Skip to content

Commit a1ce3b5

Browse files
authored
Merge pull request #229 from rainyl/1.x-vec-fix
1.x vec fix
2 parents ea281c2 + 72b1033 commit a1ce3b5

File tree

5 files changed

+62
-77
lines changed

5 files changed

+62
-77
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.2.3
2+
3+
* fix: android build.gradle task by @einsitang in https://github.com/rainyl/opencv_dart/pull/226
4+
* fix: vector conversion by @rainyl in https://github.com/rainyl/opencv_dart/pull/229
5+
* remove the dependency of flutter
6+
17
## 1.2.2
28

39
* remove arm64 and x64 setup options for ios by @rainyl in https://github.com/rainyl/opencv_dart/pull/202

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ OpenCV Bindings for Dart Language. Support both asynchronous and synchronous!
5656
- [2. clone this repo](#2-clone-this-repo)
5757
- [3. compile](#3-compile)
5858
- [4. test](#4-test)
59-
- [5. Cross-compile for linux aarch64](#5-cross-compile-for-linux-aarch64)
6059
- [Contributors](#contributors)
6160
- [Acknowledgement](#acknowledgement)
6261
- [Star History](#star-history)
@@ -264,11 +263,6 @@ or `$ENV:OPENCV_DART_LIB_PATH=$PWD\windows\opencv_dart.dll`
264263
- or append the lib path to the library search path of your system
265264
- If you want to test using vscode, add above variable to `"dart.env"` in `settings.json`
266265

267-
#### 5. Cross-compile for linux aarch64
268-
269-
Compiling for linux aarch64 requires GCC 13 and newer,
270-
conan toolchain for linux arm is located in [opencv.full](https://github.com/rainyl/opencv.full/tree/linux-aarch64/profiles), explore more there.
271-
272266
## Contributors
273267

274268
<!-- readme: contributors,TotemaT -start -->

binary.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.2
1+
1.2.3

pubspec.yaml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
name: opencv_dart
22
description: "OpenCV4 bindings for Dart language and Flutter, using dart:ffi. The most complete OpenCV bindings for Dart! With asynchronous support now!"
3-
version: 1.2.2
3+
version: 1.2.3
44
homepage: https://github.com/rainyl/opencv_dart
55

66
environment:
77
sdk: ">=3.3.0 <4.0.0"
8-
flutter: ">=3.0.0"
98

109
dependencies:
11-
flutter:
12-
sdk: flutter
13-
plugin_platform_interface: ^2.1.8
1410
ffi: ^2.1.3
1511
path: ^1.9.0
1612
args: ^2.5.0

src/core/vec.hpp

+54-65
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include <vector>
66

77
inline std::vector<cv::Point> vecpoint_c2cpp(VecPoint v) {
8-
std::vector<cv::Point> rv;
8+
std::vector<cv::Point> rv(v.length);
99
for (int i = 0; i < v.length; i++) {
1010
Point p = v.ptr[i];
11-
rv.push_back(cv::Point(p.x, p.y));
11+
rv[i] = cv::Point(p.x, p.y);
1212
}
1313
return rv;
1414
}
@@ -26,10 +26,10 @@ inline VecPoint *vecpoint_cpp2c_p(std::vector<cv::Point> v) {
2626
}
2727

2828
inline std::vector<cv::Point2f> vecpoint2f_c2cpp(VecPoint2f v) {
29-
std::vector<cv::Point2f> rv;
29+
std::vector<cv::Point2f> rv(v.length);
3030
for (int i = 0; i < v.length; i++) {
3131
Point2f p = v.ptr[i];
32-
rv.push_back(cv::Point2f(p.x, p.y));
32+
rv[i] = cv::Point2f(p.x, p.y);
3333
}
3434
return rv;
3535
}
@@ -55,10 +55,10 @@ inline VecPoint2f *vecpoint2f_cpp2c_p(std::vector<cv::Point2f> v) {
5555
}
5656

5757
inline std::vector<cv::Point3f> vecpoint3f_c2cpp(VecPoint3f v) {
58-
std::vector<cv::Point3f> rv;
58+
std::vector<cv::Point3f> rv(v.length);
5959
for (int i = 0; i < v.length; i++) {
6060
Point3f p = v.ptr[i];
61-
rv.push_back(cv::Point3f(p.x, p.y, p.z));
61+
rv[i] = cv::Point3f(p.x, p.y, p.z);
6262
}
6363
return rv;
6464
}
@@ -76,10 +76,10 @@ inline VecPoint3f *vecpoint3f_cpp2c_p(std::vector<cv::Point3f> v) {
7676
}
7777

7878
inline std::vector<cv::Point3i> vecpoint3i_c2cpp(VecPoint3i v) {
79-
std::vector<cv::Point3i> rv;
79+
std::vector<cv::Point3i> rv(v.length);
8080
for (int i = 0; i < v.length; i++) {
8181
Point3i p = v.ptr[i];
82-
rv.push_back(cv::Point3i(p.x, p.y, p.z));
82+
rv[i] = cv::Point3i(p.x, p.y, p.z);
8383
}
8484
return rv;
8585
}
@@ -97,11 +97,11 @@ inline VecPoint3i *vecpoint3i_cpp2c_p(std::vector<cv::Point3i> v) {
9797
}
9898

9999
inline std::vector<std::vector<cv::Point>> vecvecpoint_c2cpp(VecVecPoint v) {
100-
std::vector<std::vector<cv::Point>> rv;
100+
std::vector<std::vector<cv::Point>> rv(v.length);
101101
for (int i = 0; i < v.length; i++) {
102102
VecPoint vp = v.ptr[i];
103103
std::vector<cv::Point> pts = vecpoint_c2cpp(vp);
104-
rv.push_back(pts);
104+
rv[i] = pts;
105105
}
106106
return rv;
107107
}
@@ -125,11 +125,11 @@ inline VecVecPoint *vecvecpoint_cpp2c_p(std::vector<std::vector<cv::Point>> v) {
125125
}
126126

127127
inline std::vector<std::vector<cv::Point2f>> vecvecpoint2f_c2cpp(VecVecPoint2f v) {
128-
std::vector<std::vector<cv::Point2f>> rv;
128+
std::vector<std::vector<cv::Point2f>> rv(v.length);
129129
for (int i = 0; i < v.length; i++) {
130130
VecPoint2f vp = v.ptr[i];
131131
std::vector<cv::Point2f> pts = vecpoint2f_c2cpp(vp);
132-
rv.push_back(pts);
132+
rv[i] = pts;
133133
}
134134
return rv;
135135
}
@@ -153,11 +153,11 @@ inline VecVecPoint2f *vecvecpoint2f_cpp2c_p(std::vector<std::vector<cv::Point2f>
153153
}
154154

155155
inline std::vector<std::vector<cv::Point3f>> vecvecpoint3f_c2cpp(VecVecPoint3f v) {
156-
std::vector<std::vector<cv::Point3f>> rv;
156+
std::vector<std::vector<cv::Point3f>> rv(v.length);
157157
for (int i = 0; i < v.length; i++) {
158158
VecPoint3f vp = v.ptr[i];
159159
std::vector<cv::Point3f> pts = vecpoint3f_c2cpp(vp);
160-
rv.push_back(pts);
160+
rv[i] = pts;
161161
}
162162
return rv;
163163
}
@@ -181,11 +181,11 @@ inline VecVecPoint3f *vecvecpoint3f_cpp2c_p(std::vector<std::vector<cv::Point3f>
181181
}
182182

183183
inline std::vector<std::vector<cv::Point3i>> vecvecpoint3i_c2cpp(VecVecPoint3i v) {
184-
std::vector<std::vector<cv::Point3i>> rv;
184+
std::vector<std::vector<cv::Point3i>> rv(v.length);
185185
for (int i = 0; i < v.length; i++) {
186186
VecPoint3i vp = v.ptr[i];
187187
std::vector<cv::Point3i> pts = vecpoint3i_c2cpp(vp);
188-
rv.push_back(pts);
188+
rv[i] = pts;
189189
}
190190
return rv;
191191
}
@@ -209,10 +209,10 @@ inline VecVecPoint3i *vecvecpoint3i_cpp2c_p(std::vector<std::vector<cv::Point3i>
209209
}
210210

211211
inline std::vector<cv::Mat> vecmat_c2cpp(VecMat v) {
212-
std::vector<cv::Mat> rv;
212+
std::vector<cv::Mat> rv(v.length);
213213
for (int i = 0; i < v.length; i++) {
214214
Mat m = v.ptr[i];
215-
rv.push_back(*m.ptr);
215+
rv[i] = *m.ptr;
216216
}
217217
return rv;
218218
}
@@ -230,46 +230,44 @@ inline VecMat *vecmat_cpp2c_p(std::vector<cv::Mat> v) {
230230
}
231231

232232
inline std::vector<char> vecchar_c2cpp(VecChar v) {
233-
std::vector<char> rv;
234-
for (int i = 0; i < v.length; i++) {
235-
char p = v.ptr[i];
236-
rv.push_back(p);
237-
}
233+
std::vector<char> rv(v.length);
234+
for (int i = 0; i < v.length; i++) { rv[i] = v.ptr[i]; }
238235
return rv;
239236
}
240237

241238
inline std::string vecchar_c2cpp_s(VecChar v) { return std::string(v.ptr, v.length); }
242239

243240
inline VecChar vecchar_cpp2c(std::vector<char> v) {
244241
char *ptr = new char[v.size()];
245-
for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
242+
std::copy(v.begin(), v.end(), ptr);
243+
// for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
246244
return VecChar{.ptr = ptr, .length = v.size()};
247245
}
248246

249247
inline VecChar *vecchar_cpp2c_p(std::vector<char> v) {
250248
char *ptr = new char[v.size()];
251-
for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
249+
std::copy(v.begin(), v.end(), ptr);
250+
// for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
252251
return new VecChar{.ptr = ptr, .length = v.size()};
253252
}
254253

255254
inline VecChar vecchar_cpp2c_s(std::string v) {
256255
char *ptr = new char[v.size()];
257-
for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
256+
std::copy(v.begin(), v.end(), ptr);
257+
// for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
258258
return VecChar{.ptr = ptr, .length = v.size()};
259259
}
260260

261261
inline VecChar *vecchar_cpp2c_s_p(std::string v) {
262262
char *ptr = new char[v.size()];
263-
for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
263+
std::copy(v.begin(), v.end(), ptr);
264+
// for (int i = 0; i < v.size(); i++) { ptr[i] = v[i]; }
264265
return new VecChar{.ptr = ptr, .length = v.size()};
265266
}
266267

267268
inline std::vector<uchar> vecuchar_c2cpp(VecUChar v) {
268-
std::vector<uchar> rv;
269-
for (int i = 0; i < v.length; i++) {
270-
char p = v.ptr[i];
271-
rv.push_back(p);
272-
}
269+
std::vector<uchar> rv(v.length);
270+
for (int i = 0; i < v.length; i++) { rv[i] = v.ptr[i]; }
273271
return rv;
274272
}
275273
inline VecUChar vecuchar_cpp2c(std::vector<uchar> v) {
@@ -285,18 +283,18 @@ inline VecUChar *vecuchar_cpp2c_p(std::vector<uchar> v) {
285283
}
286284

287285
inline std::vector<std::vector<char>> vecvecchar_c2cpp(VecVecChar v) {
288-
std::vector<std::vector<char>> rv;
286+
std::vector<std::vector<char>> rv(v.length);
289287
for (int i = 0; i < v.length; i++) {
290288
VecChar vc = v.ptr[i];
291289
std::vector<char> pts = vecchar_c2cpp(vc);
292-
rv.push_back(pts);
290+
rv[i] = pts;
293291
}
294292
return rv;
295293
}
296294

297295
inline std::vector<std::string> vecvecchar_c2cpp_s(VecVecChar v) {
298-
std::vector<std::string> rv;
299-
for (int i = 0; i < v.length; i++) { rv.push_back(vecchar_c2cpp_s(v.ptr[i])); }
296+
std::vector<std::string> rv(v.length);
297+
for (int i = 0; i < v.length; i++) { rv[i] = vecchar_c2cpp_s(v.ptr[i]); }
300298
return rv;
301299
}
302300

@@ -325,11 +323,8 @@ inline VecVecChar *vecvecchar_cpp2c_s_p(std::vector<std::string> v) {
325323
}
326324

327325
inline std::vector<int> vecint_c2cpp(VecI32 v) {
328-
std::vector<int> rv;
329-
for (int i = 0; i < v.length; i++) {
330-
int p = v.ptr[i];
331-
rv.push_back(p);
332-
}
326+
std::vector<int> rv(v.length);
327+
for (int i = 0; i < v.length; i++) { rv[i] = v.ptr[i]; }
333328
return rv;
334329
}
335330
inline VecI32 vecint_cpp2c(std::vector<int> v) {
@@ -345,11 +340,8 @@ inline VecI32 *vecint_cpp2c_p(std::vector<int> v) {
345340
}
346341

347342
inline std::vector<float> vecfloat_c2cpp(VecF32 v) {
348-
std::vector<float> rv;
349-
for (int i = 0; i < v.length; i++) {
350-
float p = v.ptr[i];
351-
rv.push_back(p);
352-
}
343+
std::vector<float> rv(v.length);
344+
for (int i = 0; i < v.length; i++) { rv[i] = v.ptr[i]; }
353345
return rv;
354346
}
355347

@@ -366,11 +358,8 @@ inline VecF32 *vecfloat_cpp2c_p(std::vector<float> v) {
366358
}
367359

368360
inline std::vector<double> vecdouble_c2cpp(VecF64 v) {
369-
std::vector<double> rv;
370-
for (int i = 0; i < v.length; i++) {
371-
int p = v.ptr[i];
372-
rv.push_back(p);
373-
}
361+
std::vector<double> rv(v.length);
362+
for (int i = 0; i < v.length; i++) { rv[i] = v.ptr[i]; }
374363
return rv;
375364
}
376365

@@ -395,10 +384,10 @@ inline VecF64 *vecdouble_cpp2c_p(std::vector<double> v) {
395384
}
396385

397386
inline std::vector<cv::Rect> vecrect_c2cpp(VecRect v) {
398-
std::vector<cv::Rect> rv;
387+
std::vector<cv::Rect> rv(v.length);
399388
for (int i = 0; i < v.length; i++) {
400389
Rect p = v.ptr[i];
401-
rv.push_back(cv::Rect(p.x, p.y, p.width, p.height));
390+
rv[i] = cv::Rect(p.x, p.y, p.width, p.height);
402391
}
403392
return rv;
404393
}
@@ -423,10 +412,10 @@ inline VecRect *vecrect_cpp2c_p(std::vector<cv::Rect> v) {
423412
}
424413

425414
inline std::vector<cv::KeyPoint> veckeypoint_c2cpp(VecKeyPoint v) {
426-
std::vector<cv::KeyPoint> rv;
415+
std::vector<cv::KeyPoint> rv(v.length);
427416
for (int i = 0; i < v.length; i++) {
428417
KeyPoint p = v.ptr[i];
429-
rv.push_back(cv::KeyPoint(p.x, p.y, p.size, p.angle, p.response, p.octave, p.classID));
418+
rv[i] = cv::KeyPoint(p.x, p.y, p.size, p.angle, p.response, p.octave, p.classID);
430419
}
431420
return rv;
432421
}
@@ -451,10 +440,10 @@ inline VecKeyPoint *veckeypoint_cpp2c_p(std::vector<cv::KeyPoint> v) {
451440
}
452441

453442
inline std::vector<cv::DMatch> vecdmatch_c2cpp(VecDMatch v) {
454-
std::vector<cv::DMatch> rv;
443+
std::vector<cv::DMatch> rv(v.length);
455444
for (int i = 0; i < v.length; i++) {
456445
DMatch p = v.ptr[i];
457-
rv.push_back(cv::DMatch(p.queryIdx, p.trainIdx, p.imgIdx, p.distance));
446+
rv[i] = cv::DMatch(p.queryIdx, p.trainIdx, p.imgIdx, p.distance);
458447
}
459448
return rv;
460449
}
@@ -476,10 +465,10 @@ inline VecDMatch *vecdmatch_cpp2c_p(std::vector<cv::DMatch> v) {
476465
}
477466

478467
inline std::vector<std::vector<cv::DMatch>> vecvecdmatch_c2cpp(VecVecDMatch v) {
479-
std::vector<std::vector<cv::DMatch>> rv;
468+
std::vector<std::vector<cv::DMatch>> rv(v.length);
480469
for (int i = 0; i < v.length; i++) {
481470
VecDMatch p = v.ptr[i];
482-
rv.push_back(vecdmatch_c2cpp(p));
471+
rv[i] = vecdmatch_c2cpp(p);
483472
}
484473
return rv;
485474
}
@@ -497,16 +486,16 @@ inline VecVecDMatch *vecvecdmatch_cpp2c_p(std::vector<std::vector<cv::DMatch>> v
497486
}
498487

499488
inline std::vector<cv::Point2f> vecPointToVecPoint2f(VecPoint src) {
500-
std::vector<cv::Point2f> v;
501-
for (int i = 0; i < src.length; i++) { v.push_back(cv::Point2f(src.ptr[i].x, src.ptr[i].y)); }
489+
std::vector<cv::Point2f> v(src.length);
490+
for (int i = 0; i < src.length; i++) { v[i] = cv::Point2f(src.ptr[i].x, src.ptr[i].y); }
502491
return v;
503492
}
504493

505494
inline std::vector<cv::Vec4f> vec_vec4f_c2cpp(VecVec4f v) {
506-
std::vector<cv::Vec4f> rv;
495+
std::vector<cv::Vec4f> rv(v.length);
507496
for (int i = 0; i < v.length; i++) {
508497
Vec4f p = v.ptr[i];
509-
rv.push_back(cv::Vec4f(p.val1, p.val2, p.val3, p.val4));
498+
rv[i] = cv::Vec4f(p.val1, p.val2, p.val3, p.val4);
510499
}
511500
return rv;
512501
}
@@ -528,10 +517,10 @@ inline VecVec4f *vec_vec4f_cpp2c_p(std::vector<cv::Vec4f> v) {
528517
}
529518

530519
inline std::vector<cv::Vec6f> vec_vec6f_c2cpp(VecVec6f v) {
531-
std::vector<cv::Vec6f> rv;
520+
std::vector<cv::Vec6f> rv(v.length);
532521
for (int i = 0; i < v.length; i++) {
533522
Vec6f p = v.ptr[i];
534-
rv.push_back(cv::Vec6f(p.val1, p.val2, p.val3, p.val4, p.val5, p.val6));
523+
rv[i] = cv::Vec6f(p.val1, p.val2, p.val3, p.val4, p.val5, p.val6);
535524
}
536525
return rv;
537526
}

0 commit comments

Comments
 (0)