00001
00024 #ifndef __D_CV_MAT__
00025 #define __D_CV_MAT__
00026
00027 #include <opencv/cv.h>
00028 #include <vector>
00029
00030 namespace DUtilsCV
00031 {
00032
00033 class Mat
00034 {
00035 public:
00036
00042 static void removeRows(cv::Mat &m, std::vector<unsigned int> &rows);
00043
00049 static void removeRows(cv::Mat &m, const std::vector<unsigned int> &rows);
00050
00051 public:
00052
00059 static void _removeRows(cv::Mat &m, const std::vector<unsigned int> &rows);
00060
00061 protected:
00062
00069 template<class T>
00070 static void _removeRowsContinuous(cv::Mat &m,
00071 const std::vector<unsigned int> &rows);
00072
00079 static void _removeRowsNonContinuous(cv::Mat &m,
00080 const std::vector<unsigned int> &rows);
00081
00082 };
00083
00084
00085
00086 template<class T>
00087 void Mat::_removeRowsContinuous(cv::Mat &m,
00088 const std::vector<unsigned int> &rows)
00089 {
00090
00091
00092
00093 int end_row = m.rows;
00094 int i_idx = (int)rows.size() - 1;
00095 while(i_idx >= 0)
00096 {
00097 int j_idx = i_idx - 1;
00098 while(j_idx >= 0 && ((int)(rows[i_idx] - rows[j_idx]) == i_idx - j_idx))
00099 {
00100 j_idx--;
00101 }
00102
00103
00104
00105 std::copy( m.ptr<T>(rows[i_idx]+1), m.ptr<T>(end_row),
00106 m.ptr<T>(rows[j_idx + 1]) );
00107
00108 end_row -= rows[i_idx] - rows[j_idx+1] + 1;
00109
00110 i_idx = j_idx;
00111 }
00112
00113
00114 m.resize(end_row);
00115 }
00116
00117
00118
00119 }
00120
00121 #endif
00122