Skip to content

Commit 3060e08

Browse files
authored
Merge pull request #126 from abdelaziz-mahdy/features2d_async
Features2d async
2 parents 2adff92 + 73a861b commit 3060e08

13 files changed

+2603
-109
lines changed

ffigen.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ headers:
3030
- src/extra/img_hash.h
3131
- src/extra/wechat_qrcode.h
3232
- src/features2d/features2d.h
33+
- src/features2d/features2d_async.h
3334
- src/gapi/gapi.h
3435
- src/highgui/highgui.h
3536
- src/imgcodecs/imgcodecs.h
@@ -58,6 +59,7 @@ headers:
5859
- src/extra/img_hash.h
5960
- src/extra/wechat_qrcode.h
6061
- src/features2d/features2d.h
62+
- src/features2d/features2d_async.h
6163
- src/gapi/gapi.h
6264
- src/highgui/highgui.h
6365
- src/imgcodecs/imgcodecs.h

lib/opencv_dart.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export 'src/core/vec.dart';
3030
export 'src/dnn/dnn.dart';
3131
export 'src/dnn/dnn_async.dart';
3232
export 'src/features2d/features2d.dart';
33+
export 'src/features2d/features2d_async.dart';
3334
export 'src/highgui/highgui.dart';
3435
export 'src/imgcodecs/imgcodecs.dart';
3536
export 'src/imgcodecs/imgcodecs_async.dart';

lib/src/dnn/dnn_async.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ library cv;
22

33
import 'dart:ffi' as ffi;
44
import 'dart:typed_data';
5+
56
import 'package:ffi/ffi.dart';
6-
import './dnn.dart';
77

88
import '../core/base.dart';
99
import '../core/mat.dart';
@@ -13,6 +13,7 @@ import '../core/scalar.dart';
1313
import '../core/size.dart';
1414
import '../core/vec.dart';
1515
import '../opencv.g.dart' as cvg;
16+
import './dnn.dart';
1617

1718
extension LayerAsync on Layer {
1819
Future<String> get nameAsync async {
@@ -93,8 +94,11 @@ extension NetAsync on Net {
9394
return rval;
9495
}
9596

96-
static Future<Net> fromBytesAsync(String framework, Uint8List bufferModel,
97-
{Uint8List? bufferConfig}) async {
97+
static Future<Net> fromBytesAsync(
98+
String framework,
99+
Uint8List bufferModel, {
100+
Uint8List? bufferConfig,
101+
}) async {
98102
bufferConfig ??= Uint8List(0);
99103
final cFramework = framework.toNativeUtf8().cast<ffi.Char>();
100104
final bufM = VecUChar.fromList(bufferModel);
@@ -302,7 +306,8 @@ extension NetAsync on Net {
302306
final rval = cvRunAsync2<(VecFloat, VecInt)>(
303307
(callback) => CFFI.Net_GetInputDetails_Async(ref, callback),
304308
(c, sc, zp) => c.complete(
305-
(VecFloat.fromPointer(sc.cast<cvg.VecFloat>()), VecInt.fromPointer(zp.cast<cvg.VecInt>()))),
309+
(VecFloat.fromPointer(sc.cast<cvg.VecFloat>()), VecInt.fromPointer(zp.cast<cvg.VecInt>())),
310+
),
306311
);
307312
return rval;
308313
}

lib/src/features2d/features2d.dart

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class AKAZE extends CvStruct<cvg.AKAZE> {
2222
finalizer.attach(this, ptr.cast(), detach: this);
2323
}
2424
}
25+
factory AKAZE.fromPointer(cvg.AKAZEPtr ptr, [bool attach = true]) => AKAZE._(ptr, attach);
2526

2627
/// returns a new AKAZE algorithm
2728
///
@@ -50,7 +51,9 @@ class AKAZE extends CvStruct<cvg.AKAZE> {
5051
(VecKeyPoint ret, Mat desc) detectAndCompute(Mat src, Mat mask) {
5152
final desc = Mat.empty();
5253
final ret = calloc<cvg.VecKeyPoint>();
53-
cvRun(() => CFFI.AKAZE_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret));
54+
cvRun(
55+
() => CFFI.AKAZE_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret),
56+
);
5457
return (VecKeyPoint.fromPointer(ret), desc);
5558
}
5659

@@ -75,6 +78,8 @@ class AgastFeatureDetector extends CvStruct<cvg.AgastFeatureDetector> {
7578
finalizer.attach(this, ptr.cast(), detach: this);
7679
}
7780
}
81+
factory AgastFeatureDetector.fromPointer(cvg.AgastFeatureDetectorPtr ptr, [bool attach = true]) =>
82+
AgastFeatureDetector._(ptr, attach);
7883

7984
/// returns a new AgastFeatureDetector algorithm
8085
///
@@ -96,8 +101,9 @@ class AgastFeatureDetector extends CvStruct<cvg.AgastFeatureDetector> {
96101
return VecKeyPoint.fromPointer(ret);
97102
}
98103

99-
static final finalizer =
100-
OcvFinalizer<cvg.AgastFeatureDetectorPtr>(CFFI.addresses.AgastFeatureDetector_Close);
104+
static final finalizer = OcvFinalizer<cvg.AgastFeatureDetectorPtr>(
105+
CFFI.addresses.AgastFeatureDetector_Close,
106+
);
101107

102108
void dispose() {
103109
finalizer.detach(this);
@@ -118,6 +124,7 @@ class BRISK extends CvStruct<cvg.BRISK> {
118124
finalizer.attach(this, ptr.cast(), detach: this);
119125
}
120126
}
127+
factory BRISK.fromPointer(cvg.BRISKPtr ptr, [bool attach = true]) => BRISK._(ptr, attach);
121128

122129
/// returns a new BRISK algorithm
123130
///
@@ -146,7 +153,9 @@ class BRISK extends CvStruct<cvg.BRISK> {
146153
(VecKeyPoint, Mat) detectAndCompute(Mat src, Mat mask) {
147154
final desc = Mat.empty();
148155
final ret = calloc<cvg.VecKeyPoint>();
149-
cvRun(() => CFFI.BRISK_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret));
156+
cvRun(
157+
() => CFFI.BRISK_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret),
158+
);
150159
return (VecKeyPoint.fromPointer(ret), desc);
151160
}
152161

@@ -185,6 +194,8 @@ class FastFeatureDetector extends CvStruct<cvg.FastFeatureDetector> {
185194
finalizer.attach(this, ptr.cast(), detach: this);
186195
}
187196
}
197+
factory FastFeatureDetector.fromPointer(cvg.FastFeatureDetectorPtr ptr, [bool attach = true]) =>
198+
FastFeatureDetector._(ptr, attach);
188199

189200
/// returns a new FastFeatureDetector algorithm
190201
///
@@ -227,7 +238,9 @@ class FastFeatureDetector extends CvStruct<cvg.FastFeatureDetector> {
227238
return VecKeyPoint.fromPointer(ret);
228239
}
229240

230-
static final finalizer = OcvFinalizer<cvg.FastFeatureDetectorPtr>(CFFI.addresses.FastFeatureDetector_Close);
241+
static final finalizer = OcvFinalizer<cvg.FastFeatureDetectorPtr>(
242+
CFFI.addresses.FastFeatureDetector_Close,
243+
);
231244

232245
void dispose() {
233246
finalizer.detach(this);
@@ -248,6 +261,8 @@ class GFTTDetector extends CvStruct<cvg.GFTTDetector> {
248261
finalizer.attach(this, ptr.cast(), detach: this);
249262
}
250263
}
264+
factory GFTTDetector.fromPointer(cvg.GFTTDetectorPtr ptr, [bool attach = true]) =>
265+
GFTTDetector._(ptr, attach);
251266

252267
/// returns a new GFTTDetector algorithm
253268
///
@@ -290,6 +305,7 @@ class KAZE extends CvStruct<cvg.KAZE> {
290305
finalizer.attach(this, ptr.cast(), detach: this);
291306
}
292307
}
308+
factory KAZE.fromPointer(cvg.KAZEPtr ptr, [bool attach = true]) => KAZE._(ptr, attach);
293309

294310
/// returns a new KAZE algorithm
295311
///
@@ -318,7 +334,9 @@ class KAZE extends CvStruct<cvg.KAZE> {
318334
(VecKeyPoint, Mat) detectAndCompute(Mat src, Mat mask) {
319335
final desc = Mat.empty();
320336
final ret = calloc<cvg.VecKeyPoint>();
321-
cvRun(() => CFFI.KAZE_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret));
337+
cvRun(
338+
() => CFFI.KAZE_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret),
339+
);
322340
return (VecKeyPoint.fromPointer(ret), desc);
323341
}
324342

@@ -343,6 +361,7 @@ class MSER extends CvStruct<cvg.MSER> {
343361
finalizer.attach(this, ptr.cast(), detach: this);
344362
}
345363
}
364+
factory MSER.fromPointer(cvg.MSERPtr ptr, [bool attach = true]) => MSER._(ptr, attach);
346365

347366
/// returns a new MSER algorithm
348367
///
@@ -393,6 +412,7 @@ class ORB extends CvStruct<cvg.ORB> {
393412
finalizer.attach(this, ptr.cast(), detach: this);
394413
}
395414
}
415+
factory ORB.fromPointer(cvg.ORBPtr ptr, [bool attach = true]) => ORB._(ptr, attach);
396416

397417
/// returns a new ORB algorithm
398418
///
@@ -454,7 +474,9 @@ class ORB extends CvStruct<cvg.ORB> {
454474
(VecKeyPoint, Mat) detectAndCompute(Mat src, Mat mask) {
455475
final desc = Mat.empty();
456476
final ret = calloc<cvg.VecKeyPoint>();
457-
cvRun(() => CFFI.ORB_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret));
477+
cvRun(
478+
() => CFFI.ORB_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret),
479+
);
458480
return (VecKeyPoint.fromPointer(ret), desc);
459481
}
460482

@@ -473,8 +495,10 @@ class ORB extends CvStruct<cvg.ORB> {
473495
}
474496

475497
class SimpleBlobDetectorParams extends CvStruct<cvg.SimpleBlobDetectorParams> {
476-
SimpleBlobDetectorParams._(ffi.Pointer<cvg.SimpleBlobDetectorParams> ptr, [bool attach = true])
477-
: super.fromPointer(ptr) {
498+
SimpleBlobDetectorParams._(
499+
ffi.Pointer<cvg.SimpleBlobDetectorParams> ptr, [
500+
bool attach = true,
501+
]) : super.fromPointer(ptr) {
478502
if (attach) {
479503
finalizer.attach(this, ptr.cast(), detach: this);
480504
}
@@ -510,7 +534,9 @@ class SimpleBlobDetectorParams extends CvStruct<cvg.SimpleBlobDetectorParams> {
510534
final p = calloc<cvg.SimpleBlobDetectorParams>();
511535
if (blobColor != null) p.ref.blobColor = blobColor;
512536
if (filterByArea != null) p.ref.filterByArea = filterByArea;
513-
if (filterByCircularity != null) p.ref.filterByCircularity = filterByCircularity;
537+
if (filterByCircularity != null) {
538+
p.ref.filterByCircularity = filterByCircularity;
539+
}
514540
if (filterByColor != null) p.ref.filterByColor = filterByColor;
515541
if (filterByConvexity != null) p.ref.filterByConvexity = filterByConvexity;
516542
if (filterByInertia != null) p.ref.filterByInertia = filterByInertia;
@@ -522,7 +548,9 @@ class SimpleBlobDetectorParams extends CvStruct<cvg.SimpleBlobDetectorParams> {
522548
if (minArea != null) p.ref.minArea = minArea;
523549
if (minCircularity != null) p.ref.minCircularity = minCircularity;
524550
if (minConvexity != null) p.ref.minConvexity = minConvexity;
525-
if (minDistBetweenBlobs != null) p.ref.minDistBetweenBlobs = minDistBetweenBlobs;
551+
if (minDistBetweenBlobs != null) {
552+
p.ref.minDistBetweenBlobs = minDistBetweenBlobs;
553+
}
526554
if (minInertiaRatio != null) p.ref.minInertiaRatio = minInertiaRatio;
527555
if (minRepeatability != null) p.ref.minRepeatability = minRepeatability;
528556
if (minThreshold != null) p.ref.minThreshold = minThreshold;
@@ -691,6 +719,9 @@ class SimpleBlobDetector extends CvStruct<cvg.SimpleBlobDetector> {
691719
}
692720
}
693721

722+
factory SimpleBlobDetector.fromPointer(cvg.SimpleBlobDetectorPtr ptr, [bool attach = true]) =>
723+
SimpleBlobDetector._(ptr, attach);
724+
694725
/// returns a new SimpleBlobDetector algorithm
695726
///
696727
/// For further details, please see:
@@ -717,7 +748,9 @@ class SimpleBlobDetector extends CvStruct<cvg.SimpleBlobDetector> {
717748
return VecKeyPoint.fromPointer(ret);
718749
}
719750

720-
static final finalizer = OcvFinalizer<cvg.SimpleBlobDetectorPtr>(CFFI.addresses.SimpleBlobDetector_Close);
751+
static final finalizer = OcvFinalizer<cvg.SimpleBlobDetectorPtr>(
752+
CFFI.addresses.SimpleBlobDetector_Close,
753+
);
721754

722755
void dispose() {
723756
finalizer.detach(this);
@@ -738,6 +771,7 @@ class BFMatcher extends CvStruct<cvg.BFMatcher> {
738771
finalizer.attach(this, ptr.cast(), detach: this);
739772
}
740773
}
774+
factory BFMatcher.fromPointer(cvg.BFMatcherPtr ptr, [bool attach = true]) => BFMatcher._(ptr, attach);
741775

742776
/// returns a new BFMatcher algorithm
743777
///
@@ -796,6 +830,8 @@ class FlannBasedMatcher extends CvStruct<cvg.FlannBasedMatcher> {
796830
finalizer.attach(this, ptr.cast(), detach: this);
797831
}
798832
}
833+
factory FlannBasedMatcher.fromPointer(cvg.FlannBasedMatcherPtr ptr, [bool attach = true]) =>
834+
FlannBasedMatcher._(ptr, attach);
799835

800836
/// returns a new FlannBasedMatcher algorithm
801837
///
@@ -813,11 +849,15 @@ class FlannBasedMatcher extends CvStruct<cvg.FlannBasedMatcher> {
813849
/// https://docs.opencv.org/master/db/d39/classcv_1_1DescriptorMatcher.html#aa880f9353cdf185ccf3013e08210483a
814850
VecVecDMatch knnMatch(Mat query, Mat train, int k) {
815851
final ret = calloc<cvg.VecVecDMatch>();
816-
cvRun(() => CFFI.FlannBasedMatcher_KnnMatch(ptr.ref, query.ref, train.ref, k, ret));
852+
cvRun(
853+
() => CFFI.FlannBasedMatcher_KnnMatch(ptr.ref, query.ref, train.ref, k, ret),
854+
);
817855
return VecVecDMatch.fromPointer(ret);
818856
}
819857

820-
static final finalizer = OcvFinalizer<cvg.FlannBasedMatcherPtr>(CFFI.addresses.FlannBasedMatcher_Close);
858+
static final finalizer = OcvFinalizer<cvg.FlannBasedMatcherPtr>(
859+
CFFI.addresses.FlannBasedMatcher_Close,
860+
);
821861

822862
void dispose() {
823863
finalizer.detach(this);
@@ -848,8 +888,22 @@ enum DrawMatchesFlag {
848888
final int value;
849889
}
850890

851-
void drawKeyPoints(Mat src, VecKeyPoint keypoints, Mat dst, Scalar color, DrawMatchesFlag flag) {
852-
cvRun(() => CFFI.DrawKeyPoints(src.ref, keypoints.ref, dst.ref, color.ref, flag.value));
891+
void drawKeyPoints(
892+
Mat src,
893+
VecKeyPoint keypoints,
894+
Mat dst,
895+
Scalar color,
896+
DrawMatchesFlag flag,
897+
) {
898+
cvRun(
899+
() => CFFI.DrawKeyPoints(
900+
src.ref,
901+
keypoints.ref,
902+
dst.ref,
903+
color.ref,
904+
flag.value,
905+
),
906+
);
853907
}
854908

855909
/// SIFT is a wrapper around the cv::SIFT.
@@ -859,6 +913,7 @@ class SIFT extends CvStruct<cvg.SIFT> {
859913
finalizer.attach(this, ptr.cast(), detach: this);
860914
}
861915
}
916+
factory SIFT.fromPointer(cvg.SIFTPtr ptr, [bool attach = true]) => SIFT._(ptr, attach);
862917

863918
/// returns a new SIFT algorithm
864919
///
@@ -887,7 +942,9 @@ class SIFT extends CvStruct<cvg.SIFT> {
887942
(VecKeyPoint, Mat) detectAndCompute(Mat src, Mat mask) {
888943
final desc = Mat.empty();
889944
final ret = calloc<cvg.VecKeyPoint>();
890-
cvRun(() => CFFI.SIFT_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret));
945+
cvRun(
946+
() => CFFI.SIFT_DetectAndCompute(ptr.ref, src.ref, mask.ref, desc.ref, ret),
947+
);
891948
return (VecKeyPoint.fromPointer(ret), desc);
892949
}
893950

@@ -905,10 +962,10 @@ class SIFT extends CvStruct<cvg.SIFT> {
905962
cvg.SIFT get ref => ptr.ref;
906963
}
907964

908-
// DrawMatches draws matches on combined train and querry images.
909-
//
910-
// For further details, please see:
911-
// https://docs.opencv.org/master/d4/d5d/group__features2d__draw.html#gad8f463ccaf0dc6f61083abd8717c261a
965+
/// DrawMatches draws matches on combined train and querry images.
966+
///
967+
/// For further details, please see:
968+
/// https://docs.opencv.org/master/d4/d5d/group__features2d__draw.html#gad8f463ccaf0dc6f61083abd8717c261a
912969
void drawMatches(
913970
InputArray img1,
914971
VecKeyPoint keypoints1,

0 commit comments

Comments
 (0)