Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/java/generator/src/cpp/converters.cpp
16354 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html
4
5
#define LOG_TAG "org.opencv.utils.Converters"
6
#include "common.h"
7
8
using namespace cv;
9
10
// vector_int
11
12
void Mat_to_vector_int(Mat& mat, std::vector<int>& v_int)
13
{
14
v_int.clear();
15
CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1);
16
v_int = (std::vector<int>) mat;
17
}
18
19
void vector_int_to_Mat(std::vector<int>& v_int, Mat& mat)
20
{
21
mat = Mat(v_int, true);
22
}
23
24
25
//vector_double
26
27
void Mat_to_vector_double(Mat& mat, std::vector<double>& v_double)
28
{
29
v_double.clear();
30
CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1);
31
v_double = (std::vector<double>) mat;
32
}
33
34
void vector_double_to_Mat(std::vector<double>& v_double, Mat& mat)
35
{
36
mat = Mat(v_double, true);
37
}
38
39
40
// vector_float
41
42
void Mat_to_vector_float(Mat& mat, std::vector<float>& v_float)
43
{
44
v_float.clear();
45
CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1);
46
v_float = (std::vector<float>) mat;
47
}
48
49
void vector_float_to_Mat(std::vector<float>& v_float, Mat& mat)
50
{
51
mat = Mat(v_float, true);
52
}
53
54
55
//vector_uchar
56
57
void Mat_to_vector_uchar(Mat& mat, std::vector<uchar>& v_uchar)
58
{
59
v_uchar.clear();
60
CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1);
61
v_uchar = (std::vector<uchar>) mat;
62
}
63
64
void vector_uchar_to_Mat(std::vector<uchar>& v_uchar, Mat& mat)
65
{
66
mat = Mat(v_uchar, true);
67
}
68
69
void Mat_to_vector_char(Mat& mat, std::vector<char>& v_char)
70
{
71
v_char.clear();
72
CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1);
73
v_char = (std::vector<char>) mat;
74
}
75
76
void vector_char_to_Mat(std::vector<char>& v_char, Mat& mat)
77
{
78
mat = Mat(v_char, true);
79
}
80
81
82
//vector_Rect
83
84
void Mat_to_vector_Rect(Mat& mat, std::vector<Rect>& v_rect)
85
{
86
v_rect.clear();
87
CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1);
88
v_rect = (std::vector<Rect>) mat;
89
}
90
91
void vector_Rect_to_Mat(std::vector<Rect>& v_rect, Mat& mat)
92
{
93
mat = Mat(v_rect, true);
94
}
95
96
//vector_Rect2d
97
98
void Mat_to_vector_Rect2d(Mat& mat, std::vector<Rect2d>& v_rect)
99
{
100
v_rect.clear();
101
CHECK_MAT(mat.type()==CV_64FC4 && mat.cols==1);
102
v_rect = (std::vector<Rect2d>) mat;
103
}
104
105
void vector_Rect2d_to_Mat(std::vector<Rect2d>& v_rect, Mat& mat)
106
{
107
mat = Mat(v_rect, true);
108
}
109
110
//vector_Point
111
void Mat_to_vector_Point(Mat& mat, std::vector<Point>& v_point)
112
{
113
v_point.clear();
114
CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1);
115
v_point = (std::vector<Point>) mat;
116
}
117
118
//vector_Point2f
119
void Mat_to_vector_Point2f(Mat& mat, std::vector<Point2f>& v_point)
120
{
121
v_point.clear();
122
CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1);
123
v_point = (std::vector<Point2f>) mat;
124
}
125
126
//vector_Point2d
127
void Mat_to_vector_Point2d(Mat& mat, std::vector<Point2d>& v_point)
128
{
129
v_point.clear();
130
CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1);
131
v_point = (std::vector<Point2d>) mat;
132
}
133
134
135
//vector_Point3i
136
void Mat_to_vector_Point3i(Mat& mat, std::vector<Point3i>& v_point)
137
{
138
v_point.clear();
139
CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1);
140
v_point = (std::vector<Point3i>) mat;
141
}
142
143
//vector_Point3f
144
void Mat_to_vector_Point3f(Mat& mat, std::vector<Point3f>& v_point)
145
{
146
v_point.clear();
147
CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1);
148
v_point = (std::vector<Point3f>) mat;
149
}
150
151
//vector_Point3d
152
void Mat_to_vector_Point3d(Mat& mat, std::vector<Point3d>& v_point)
153
{
154
v_point.clear();
155
CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1);
156
v_point = (std::vector<Point3d>) mat;
157
}
158
159
160
void vector_Point_to_Mat(std::vector<Point>& v_point, Mat& mat)
161
{
162
mat = Mat(v_point, true);
163
}
164
165
void vector_Point2f_to_Mat(std::vector<Point2f>& v_point, Mat& mat)
166
{
167
mat = Mat(v_point, true);
168
}
169
170
void vector_Point2d_to_Mat(std::vector<Point2d>& v_point, Mat& mat)
171
{
172
mat = Mat(v_point, true);
173
}
174
175
void vector_Point3i_to_Mat(std::vector<Point3i>& v_point, Mat& mat)
176
{
177
mat = Mat(v_point, true);
178
}
179
180
void vector_Point3f_to_Mat(std::vector<Point3f>& v_point, Mat& mat)
181
{
182
mat = Mat(v_point, true);
183
}
184
185
void vector_Point3d_to_Mat(std::vector<Point3d>& v_point, Mat& mat)
186
{
187
mat = Mat(v_point, true);
188
}
189
190
//vector_Mat
191
void Mat_to_vector_Mat(cv::Mat& mat, std::vector<cv::Mat>& v_mat)
192
{
193
v_mat.clear();
194
if(mat.type() == CV_32SC2 && mat.cols == 1)
195
{
196
v_mat.reserve(mat.rows);
197
for(int i=0; i<mat.rows; i++)
198
{
199
Vec<int, 2> a = mat.at< Vec<int, 2> >(i, 0);
200
long long addr = (((long long)a[0])<<32) | (a[1]&0xffffffff);
201
Mat& m = *( (Mat*) addr );
202
v_mat.push_back(m);
203
}
204
} else {
205
LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1");
206
}
207
}
208
209
210
void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
211
{
212
int count = (int)v_mat.size();
213
mat.create(count, 1, CV_32SC2);
214
for(int i=0; i<count; i++)
215
{
216
long long addr = (long long) new Mat(v_mat[i]);
217
mat.at< Vec<int, 2> >(i, 0) = Vec<int, 2>(addr>>32, addr&0xffffffff);
218
}
219
}
220
221
void Mat_to_vector_vector_Point(Mat& mat, std::vector< std::vector< Point > >& vv_pt)
222
{
223
std::vector<Mat> vm;
224
vm.reserve( mat.rows );
225
Mat_to_vector_Mat(mat, vm);
226
for(size_t i=0; i<vm.size(); i++)
227
{
228
std::vector<Point> vpt;
229
Mat_to_vector_Point(vm[i], vpt);
230
vv_pt.push_back(vpt);
231
}
232
}
233
234
void Mat_to_vector_vector_Point2f(Mat& mat, std::vector< std::vector< Point2f > >& vv_pt)
235
{
236
std::vector<Mat> vm;
237
vm.reserve( mat.rows );
238
Mat_to_vector_Mat(mat, vm);
239
for(size_t i=0; i<vm.size(); i++)
240
{
241
std::vector<Point2f> vpt;
242
Mat_to_vector_Point2f(vm[i], vpt);
243
vv_pt.push_back(vpt);
244
}
245
}
246
247
void Mat_to_vector_vector_Point3f(Mat& mat, std::vector< std::vector< Point3f > >& vv_pt)
248
{
249
std::vector<Mat> vm;
250
vm.reserve( mat.rows );
251
Mat_to_vector_Mat(mat, vm);
252
for(size_t i=0; i<vm.size(); i++)
253
{
254
std::vector<Point3f> vpt;
255
Mat_to_vector_Point3f(vm[i], vpt);
256
vv_pt.push_back(vpt);
257
}
258
}
259
260
void Mat_to_vector_vector_char(Mat& mat, std::vector< std::vector< char > >& vv_ch)
261
{
262
std::vector<Mat> vm;
263
vm.reserve( mat.rows );
264
Mat_to_vector_Mat(mat, vm);
265
for(size_t i=0; i<vm.size(); i++)
266
{
267
std::vector<char> vch;
268
Mat_to_vector_char(vm[i], vch);
269
vv_ch.push_back(vch);
270
}
271
}
272
273
void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, Mat& mat)
274
{
275
std::vector<Mat> vm;
276
vm.reserve( vv_ch.size() );
277
for(size_t i=0; i<vv_ch.size(); i++)
278
{
279
Mat m;
280
vector_char_to_Mat(vv_ch[i], m);
281
vm.push_back(m);
282
}
283
vector_Mat_to_Mat(vm, mat);
284
}
285
286
void vector_vector_Point_to_Mat(std::vector< std::vector< Point > >& vv_pt, Mat& mat)
287
{
288
std::vector<Mat> vm;
289
vm.reserve( vv_pt.size() );
290
for(size_t i=0; i<vv_pt.size(); i++)
291
{
292
Mat m;
293
vector_Point_to_Mat(vv_pt[i], m);
294
vm.push_back(m);
295
}
296
vector_Mat_to_Mat(vm, mat);
297
}
298
299
void vector_vector_Point2f_to_Mat(std::vector< std::vector< Point2f > >& vv_pt, Mat& mat)
300
{
301
std::vector<Mat> vm;
302
vm.reserve( vv_pt.size() );
303
for(size_t i=0; i<vv_pt.size(); i++)
304
{
305
Mat m;
306
vector_Point2f_to_Mat(vv_pt[i], m);
307
vm.push_back(m);
308
}
309
vector_Mat_to_Mat(vm, mat);
310
}
311
312
void vector_vector_Point3f_to_Mat(std::vector< std::vector< Point3f > >& vv_pt, Mat& mat)
313
{
314
std::vector<Mat> vm;
315
vm.reserve( vv_pt.size() );
316
for(size_t i=0; i<vv_pt.size(); i++)
317
{
318
Mat m;
319
vector_Point3f_to_Mat(vv_pt[i], m);
320
vm.push_back(m);
321
}
322
vector_Mat_to_Mat(vm, mat);
323
}
324
325
void vector_Vec4i_to_Mat(std::vector<Vec4i>& v_vec, Mat& mat)
326
{
327
mat = Mat(v_vec, true);
328
}
329
330
void vector_Vec4f_to_Mat(std::vector<Vec4f>& v_vec, Mat& mat)
331
{
332
mat = Mat(v_vec, true);
333
}
334
335
void vector_Vec6f_to_Mat(std::vector<Vec6f>& v_vec, Mat& mat)
336
{
337
mat = Mat(v_vec, true);
338
}
339
340