1
#define LOG_TAG "org.opencv.utils.Converters"
6
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
11
void Mat_to_vector_int(Mat& mat, std::vector<int>& v_int)
14
CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
15
v_int = (std::vector<int>) mat;
18
void vector_int_to_Mat(std::vector<int>& v_int, Mat& mat)
20
mat = Mat(v_int, true);
26
void Mat_to_vector_double(Mat& mat, std::vector<double>& v_double)
29
CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1);
30
v_double = (std::vector<double>) mat;
33
void vector_double_to_Mat(std::vector<double>& v_double, Mat& mat)
35
mat = Mat(v_double, true);
41
void Mat_to_vector_float(Mat& mat, std::vector<float>& v_float)
44
CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1);
45
v_float = (std::vector<float>) mat;
48
void vector_float_to_Mat(std::vector<float>& v_float, Mat& mat)
50
mat = Mat(v_float, true);
56
void Mat_to_vector_uchar(Mat& mat, std::vector<uchar>& v_uchar)
59
CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1);
60
v_uchar = (std::vector<uchar>) mat;
63
void vector_uchar_to_Mat(std::vector<uchar>& v_uchar, Mat& mat)
65
mat = Mat(v_uchar, true);
68
void Mat_to_vector_char(Mat& mat, std::vector<char>& v_char)
71
CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1);
72
v_char = (std::vector<char>) mat;
75
void vector_char_to_Mat(std::vector<char>& v_char, Mat& mat)
77
mat = Mat(v_char, true);
83
void Mat_to_vector_Rect(Mat& mat, std::vector<Rect>& v_rect)
86
CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1);
87
v_rect = (std::vector<Rect>) mat;
90
void vector_Rect_to_Mat(std::vector<Rect>& v_rect, Mat& mat)
92
mat = Mat(v_rect, true);
97
void Mat_to_vector_Point(Mat& mat, std::vector<Point>& v_point)
100
CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1);
101
v_point = (std::vector<Point>) mat;
105
void Mat_to_vector_Point2f(Mat& mat, std::vector<Point2f>& v_point)
108
CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1);
109
v_point = (std::vector<Point2f>) mat;
113
void Mat_to_vector_Point2d(Mat& mat, std::vector<Point2d>& v_point)
116
CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1);
117
v_point = (std::vector<Point2d>) mat;
122
void Mat_to_vector_Point3i(Mat& mat, std::vector<Point3i>& v_point)
125
CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1);
126
v_point = (std::vector<Point3i>) mat;
130
void Mat_to_vector_Point3f(Mat& mat, std::vector<Point3f>& v_point)
133
CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1);
134
v_point = (std::vector<Point3f>) mat;
138
void Mat_to_vector_Point3d(Mat& mat, std::vector<Point3d>& v_point)
141
CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1);
142
v_point = (std::vector<Point3d>) mat;
146
void vector_Point_to_Mat(std::vector<Point>& v_point, Mat& mat)
148
mat = Mat(v_point, true);
151
void vector_Point2f_to_Mat(std::vector<Point2f>& v_point, Mat& mat)
153
mat = Mat(v_point, true);
156
void vector_Point2d_to_Mat(std::vector<Point2d>& v_point, Mat& mat)
158
mat = Mat(v_point, true);
161
void vector_Point3i_to_Mat(std::vector<Point3i>& v_point, Mat& mat)
163
mat = Mat(v_point, true);
166
void vector_Point3f_to_Mat(std::vector<Point3f>& v_point, Mat& mat)
168
mat = Mat(v_point, true);
171
void vector_Point3d_to_Mat(std::vector<Point3d>& v_point, Mat& mat)
173
mat = Mat(v_point, true);
177
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)
180
if(mat.type() == CV_32SC2 && mat.cols == 1)
182
v_mat.reserve(mat.rows);
183
for(int i=0; i<mat.rows; i++)
185
Vec<int, 2> a = mat.at< Vec<int, 2> >(i, 0);
186
long long addr = (((long long)a[0])<<32) | (a[1]&0xffffffff);
187
Mat& m = *( (Mat*) addr );
191
LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1");
196
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
198
int count = (int)v_mat.size();
199
mat.create(count, 1, CV_32SC2);
200
for(int i=0; i<count; i++)
202
long long addr = (long long) new Mat(v_mat[i]);
203
mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
207
void Mat_to_vector_vector_Point(Mat& mat, std::vector< std::vector< Point > >& vv_pt)
210
vm.reserve( mat.rows );
211
Mat_to_vector_Mat(mat, vm);
212
for(size_t i=0; i<vm.size(); i++)
214
std::vector<Point> vpt;
215
Mat_to_vector_Point(vm[i], vpt);
216
vv_pt.push_back(vpt);
220
void Mat_to_vector_vector_Point2f(Mat& mat, std::vector< std::vector< Point2f > >& vv_pt)
223
vm.reserve( mat.rows );
224
Mat_to_vector_Mat(mat, vm);
225
for(size_t i=0; i<vm.size(); i++)
227
std::vector<Point2f> vpt;
228
Mat_to_vector_Point2f(vm[i], vpt);
229
vv_pt.push_back(vpt);
233
void Mat_to_vector_vector_Point3f(Mat& mat, std::vector< std::vector< Point3f > >& vv_pt)
236
vm.reserve( mat.rows );
237
Mat_to_vector_Mat(mat, vm);
238
for(size_t i=0; i<vm.size(); i++)
240
std::vector<Point3f> vpt;
241
Mat_to_vector_Point3f(vm[i], vpt);
242
vv_pt.push_back(vpt);
246
void Mat_to_vector_vector_char(Mat& mat, std::vector< std::vector< char > >& vv_ch)
249
vm.reserve( mat.rows );
250
Mat_to_vector_Mat(mat, vm);
251
for(size_t i=0; i<vm.size(); i++)
253
std::vector<char> vch;
254
Mat_to_vector_char(vm[i], vch);
255
vv_ch.push_back(vch);
259
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, Mat& mat)
262
vm.reserve( vv_ch.size() );
263
for(size_t i=0; i<vv_ch.size(); i++)
266
vector_char_to_Mat(vv_ch[i], m);
269
vector_Mat_to_Mat(vm, mat);
272
void vector_vector_Point_to_Mat(std::vector< std::vector< Point > >& vv_pt, Mat& mat)
275
vm.reserve( vv_pt.size() );
276
for(size_t i=0; i<vv_pt.size(); i++)
279
vector_Point_to_Mat(vv_pt[i], m);
282
vector_Mat_to_Mat(vm, mat);
285
void vector_vector_Point2f_to_Mat(std::vector< std::vector< Point2f > >& vv_pt, Mat& mat)
288
vm.reserve( vv_pt.size() );
289
for(size_t i=0; i<vv_pt.size(); i++)
292
vector_Point2f_to_Mat(vv_pt[i], m);
295
vector_Mat_to_Mat(vm, mat);
298
void vector_vector_Point3f_to_Mat(std::vector< std::vector< Point3f > >& vv_pt, Mat& mat)
301
vm.reserve( vv_pt.size() );
302
for(size_t i=0; i<vv_pt.size(); i++)
305
vector_Point3f_to_Mat(vv_pt[i], m);
308
vector_Mat_to_Mat(vm, mat);
311
void vector_Vec4i_to_Mat(std::vector<Vec4i>& v_vec, Mat& mat)
313
mat = Mat(v_vec, true);
316
void vector_Vec4f_to_Mat(std::vector<Vec4f>& v_vec, Mat& mat)
318
mat = Mat(v_vec, true);
321
void vector_Vec6f_to_Mat(std::vector<Vec6f>& v_vec, Mat& mat)
323
mat = Mat(v_vec, true);