Skip to content

Commit 1167883

Browse files
authored
Merge pull request #236 from rainyl/floodfill
add `cv.floodFill`, move `findHomography` to `calib3d`
2 parents e40c871 + 85ce26f commit 1167883

19 files changed

+1181
-480
lines changed

lib/src/calib3d/calib3d.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,33 @@ Mat drawChessboardCorners(
299299
);
300300
return (Mat.fromPointer(p), inliers);
301301
}
302+
303+
/// FindHomography finds an optimal homography matrix using 4 or more point pairs (as opposed to GetPerspectiveTransform, which uses exactly 4)
304+
///
305+
/// For further details, please see:
306+
/// https:///docs.opencv.org/master/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780
307+
Mat findHomography(
308+
InputArray srcPoints,
309+
InputArray dstPoints, {
310+
int method = 0,
311+
double ransacReprojThreshold = 3,
312+
OutputArray? mask,
313+
int maxIters = 2000,
314+
double confidence = 0.995,
315+
}) {
316+
mask ??= Mat.empty();
317+
final mat = calloc<cvg.Mat>();
318+
cvRun(
319+
() => ccalib3d.FindHomography(
320+
srcPoints.ref,
321+
dstPoints.ref,
322+
method,
323+
ransacReprojThreshold,
324+
mask!.ref,
325+
maxIters,
326+
confidence,
327+
mat,
328+
),
329+
);
330+
return Mat.fromPointer(mat);
331+
}

lib/src/calib3d/calib3d_async.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,3 +286,28 @@ Future<(Mat, Mat inliers)> estimateAffine2DAsync(
286286
),
287287
matCompleter2,
288288
);
289+
290+
/// FindHomography finds an optimal homography matrix using 4 or more point pairs (as opposed to GetPerspectiveTransform, which uses exactly 4)
291+
///
292+
/// For further details, please see:
293+
/// https:///docs.opencv.org/master/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780
294+
Future<(Mat, Mat)> findHomographyAsync(
295+
InputArray srcPoints,
296+
InputArray dstPoints, {
297+
int method = 0,
298+
double ransacReprojThreshold = 3,
299+
int maxIters = 2000,
300+
double confidence = 0.995,
301+
}) async =>
302+
cvRunAsync2(
303+
(callback) => ccalib3d.FindHomography_Async(
304+
srcPoints.ref,
305+
dstPoints.ref,
306+
method,
307+
ransacReprojThreshold,
308+
maxIters,
309+
confidence,
310+
callback,
311+
),
312+
matCompleter2,
313+
);

lib/src/g/calib3d.g.dart

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,64 @@ class CvNativeCalib3d {
291291
ffi.Pointer<CvStatus> Function(
292292
Mat, Size, Mat, int, Mat, ffi.Pointer<ffi.Bool>)>();
293293

294+
ffi.Pointer<CvStatus> FindHomography(
295+
Mat src,
296+
Mat dst,
297+
int method,
298+
double ransacReprojThreshold,
299+
Mat mask,
300+
int maxIters,
301+
double confidence,
302+
ffi.Pointer<Mat> rval,
303+
) {
304+
return _FindHomography(
305+
src,
306+
dst,
307+
method,
308+
ransacReprojThreshold,
309+
mask,
310+
maxIters,
311+
confidence,
312+
rval,
313+
);
314+
}
315+
316+
late final _FindHomographyPtr = _lookup<
317+
ffi.NativeFunction<
318+
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, Mat,
319+
ffi.Int, ffi.Double, ffi.Pointer<Mat>)>>('FindHomography');
320+
late final _FindHomography = _FindHomographyPtr.asFunction<
321+
ffi.Pointer<CvStatus> Function(
322+
Mat, Mat, int, double, Mat, int, double, ffi.Pointer<Mat>)>();
323+
324+
ffi.Pointer<CvStatus> FindHomography_Async(
325+
Mat src,
326+
Mat dst,
327+
int method,
328+
double ransacReprojThreshold,
329+
int maxIters,
330+
double confidence,
331+
imp1.CvCallback_2 callback,
332+
) {
333+
return _FindHomography_Async(
334+
src,
335+
dst,
336+
method,
337+
ransacReprojThreshold,
338+
maxIters,
339+
confidence,
340+
callback,
341+
);
342+
}
343+
344+
late final _FindHomography_AsyncPtr = _lookup<
345+
ffi.NativeFunction<
346+
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, ffi.Int,
347+
ffi.Double, imp1.CvCallback_2)>>('FindHomography_Async');
348+
late final _FindHomography_Async = _FindHomography_AsyncPtr.asFunction<
349+
ffi.Pointer<CvStatus> Function(
350+
Mat, Mat, int, double, int, double, imp1.CvCallback_2)>();
351+
294352
ffi.Pointer<CvStatus> Fisheye_EstimateNewCameraMatrixForUndistortRectify(
295353
Mat k,
296354
Mat d,

lib/src/g/calib3d.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ files:
2222
name: FindChessboardCornersSB
2323
c:@F@FindChessboardCornersSBWithMeta:
2424
name: FindChessboardCornersSBWithMeta
25+
c:@F@FindHomography:
26+
name: FindHomography
27+
c:@F@FindHomography_Async:
28+
name: FindHomography_Async
2529
c:@F@Fisheye_EstimateNewCameraMatrixForUndistortRectify:
2630
name: Fisheye_EstimateNewCameraMatrixForUndistortRectify
2731
c:@F@Fisheye_UndistortImage:

lib/src/g/imgproc.g.dart

Lines changed: 94 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,64 +2238,6 @@ class CvNativeImgproc {
22382238
late final _FindContours_Async = _FindContours_AsyncPtr.asFunction<
22392239
ffi.Pointer<CvStatus> Function(Mat, int, int, imp1.CvCallback_2)>();
22402240

2241-
ffi.Pointer<CvStatus> FindHomography(
2242-
Mat src,
2243-
Mat dst,
2244-
int method,
2245-
double ransacReprojThreshold,
2246-
Mat mask,
2247-
int maxIters,
2248-
double confidence,
2249-
ffi.Pointer<Mat> rval,
2250-
) {
2251-
return _FindHomography(
2252-
src,
2253-
dst,
2254-
method,
2255-
ransacReprojThreshold,
2256-
mask,
2257-
maxIters,
2258-
confidence,
2259-
rval,
2260-
);
2261-
}
2262-
2263-
late final _FindHomographyPtr = _lookup<
2264-
ffi.NativeFunction<
2265-
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, Mat,
2266-
ffi.Int, ffi.Double, ffi.Pointer<Mat>)>>('FindHomography');
2267-
late final _FindHomography = _FindHomographyPtr.asFunction<
2268-
ffi.Pointer<CvStatus> Function(
2269-
Mat, Mat, int, double, Mat, int, double, ffi.Pointer<Mat>)>();
2270-
2271-
ffi.Pointer<CvStatus> FindHomography_Async(
2272-
Mat src,
2273-
Mat dst,
2274-
int method,
2275-
double ransacReprojThreshold,
2276-
int maxIters,
2277-
double confidence,
2278-
imp1.CvCallback_2 callback,
2279-
) {
2280-
return _FindHomography_Async(
2281-
src,
2282-
dst,
2283-
method,
2284-
ransacReprojThreshold,
2285-
maxIters,
2286-
confidence,
2287-
callback,
2288-
);
2289-
}
2290-
2291-
late final _FindHomography_AsyncPtr = _lookup<
2292-
ffi.NativeFunction<
2293-
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, ffi.Int,
2294-
ffi.Double, imp1.CvCallback_2)>>('FindHomography_Async');
2295-
late final _FindHomography_Async = _FindHomography_AsyncPtr.asFunction<
2296-
ffi.Pointer<CvStatus> Function(
2297-
Mat, Mat, int, double, int, double, imp1.CvCallback_2)>();
2298-
22992241
ffi.Pointer<CvStatus> FitEllipse(
23002242
VecPoint pts,
23012243
ffi.Pointer<RotatedRect> rval,
@@ -2382,6 +2324,76 @@ class CvNativeImgproc {
23822324
ffi.Pointer<CvStatus> Function(
23832325
VecPoint, int, double, double, double, imp1.CvCallback_1)>();
23842326

2327+
ffi.Pointer<CvStatus> FloodFill(
2328+
Mat src,
2329+
Mat mask,
2330+
Point seedPoint,
2331+
Scalar newVal,
2332+
ffi.Pointer<Rect> rect,
2333+
Scalar loDiff,
2334+
Scalar upDiff,
2335+
int flags,
2336+
ffi.Pointer<ffi.Int> rval,
2337+
) {
2338+
return _FloodFill(
2339+
src,
2340+
mask,
2341+
seedPoint,
2342+
newVal,
2343+
rect,
2344+
loDiff,
2345+
upDiff,
2346+
flags,
2347+
rval,
2348+
);
2349+
}
2350+
2351+
late final _FloodFillPtr = _lookup<
2352+
ffi.NativeFunction<
2353+
ffi.Pointer<CvStatus> Function(
2354+
Mat,
2355+
Mat,
2356+
Point,
2357+
Scalar,
2358+
ffi.Pointer<Rect>,
2359+
Scalar,
2360+
Scalar,
2361+
ffi.Int,
2362+
ffi.Pointer<ffi.Int>)>>('FloodFill');
2363+
late final _FloodFill = _FloodFillPtr.asFunction<
2364+
ffi.Pointer<CvStatus> Function(Mat, Mat, Point, Scalar, ffi.Pointer<Rect>,
2365+
Scalar, Scalar, int, ffi.Pointer<ffi.Int>)>();
2366+
2367+
ffi.Pointer<CvStatus> FloodFill_Async(
2368+
Mat src,
2369+
Mat mask,
2370+
Point seedPoint,
2371+
Scalar newVal,
2372+
Scalar loDiff,
2373+
Scalar upDiff,
2374+
int flags,
2375+
imp1.CvCallback_2 callback,
2376+
) {
2377+
return _FloodFill_Async(
2378+
src,
2379+
mask,
2380+
seedPoint,
2381+
newVal,
2382+
loDiff,
2383+
upDiff,
2384+
flags,
2385+
callback,
2386+
);
2387+
}
2388+
2389+
late final _FloodFill_AsyncPtr = _lookup<
2390+
ffi.NativeFunction<
2391+
ffi.Pointer<CvStatus> Function(Mat, Mat, Point, Scalar, Scalar,
2392+
Scalar, ffi.Int, imp1.CvCallback_2)>>('FloodFill_Async');
2393+
late final _FloodFill_Async = _FloodFill_AsyncPtr.asFunction<
2394+
ffi.Pointer<CvStatus> Function(
2395+
Mat, Mat, Point, Scalar, Scalar, Scalar, int, imp1.CvCallback_2)>();
2396+
23852397
ffi.Pointer<CvStatus> GaussianBlur(
23862398
Mat src,
23872399
Mat dst,
@@ -5278,53 +5290,53 @@ class CvNativeImgproc {
52785290
late final _SpatialGradient_Async = _SpatialGradient_AsyncPtr.asFunction<
52795291
ffi.Pointer<CvStatus> Function(Mat, int, int, imp1.CvCallback_2)>();
52805292

5281-
ffi.Pointer<CvStatus> SqBoxFilter(
5293+
ffi.Pointer<CvStatus> SqBoxFilter_Async(
52825294
Mat src,
5283-
Mat dst,
52845295
int ddepth,
52855296
Size ps,
5286-
Point anchor,
5287-
bool normalize,
5288-
int borderType,
5297+
imp1.CvCallback_1 callback,
52895298
) {
5290-
return _SqBoxFilter(
5299+
return _SqBoxFilter_Async(
52915300
src,
5292-
dst,
52935301
ddepth,
52945302
ps,
5295-
anchor,
5296-
normalize,
5297-
borderType,
5303+
callback,
52985304
);
52995305
}
53005306

5301-
late final _SqBoxFilterPtr = _lookup<
5307+
late final _SqBoxFilter_AsyncPtr = _lookup<
53025308
ffi.NativeFunction<
5303-
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, Size, Point,
5304-
ffi.Bool, ffi.Int)>>('SqBoxFilter');
5305-
late final _SqBoxFilter = _SqBoxFilterPtr.asFunction<
5306-
ffi.Pointer<CvStatus> Function(Mat, Mat, int, Size, Point, bool, int)>();
5309+
ffi.Pointer<CvStatus> Function(
5310+
Mat, ffi.Int, Size, imp1.CvCallback_1)>>('SqBoxFilter_Async');
5311+
late final _SqBoxFilter_Async = _SqBoxFilter_AsyncPtr.asFunction<
5312+
ffi.Pointer<CvStatus> Function(Mat, int, Size, imp1.CvCallback_1)>();
53075313

5308-
ffi.Pointer<CvStatus> SqBoxFilter_Async(
5314+
ffi.Pointer<CvStatus> SqrBoxFilter(
53095315
Mat src,
5316+
Mat dst,
53105317
int ddepth,
53115318
Size ps,
5312-
imp1.CvCallback_1 callback,
5319+
Point anchor,
5320+
bool normalize,
5321+
int borderType,
53135322
) {
5314-
return _SqBoxFilter_Async(
5323+
return _SqrBoxFilter(
53155324
src,
5325+
dst,
53165326
ddepth,
53175327
ps,
5318-
callback,
5328+
anchor,
5329+
normalize,
5330+
borderType,
53195331
);
53205332
}
53215333

5322-
late final _SqBoxFilter_AsyncPtr = _lookup<
5334+
late final _SqrBoxFilterPtr = _lookup<
53235335
ffi.NativeFunction<
5324-
ffi.Pointer<CvStatus> Function(
5325-
Mat, ffi.Int, Size, imp1.CvCallback_1)>>('SqBoxFilter_Async');
5326-
late final _SqBoxFilter_Async = _SqBoxFilter_AsyncPtr.asFunction<
5327-
ffi.Pointer<CvStatus> Function(Mat, int, Size, imp1.CvCallback_1)>();
5336+
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, Size, Point,
5337+
ffi.Bool, ffi.Int)>>('SqrBoxFilter');
5338+
late final _SqrBoxFilter = _SqrBoxFilterPtr.asFunction<
5339+
ffi.Pointer<CvStatus> Function(Mat, Mat, int, Size, Point, bool, int)>();
53285340

53295341
void Subdiv2D_Close(
53305342
Subdiv2DPtr self,

lib/src/g/imgproc.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ files:
196196
name: FindContours
197197
c:@F@FindContours_Async:
198198
name: FindContours_Async
199-
c:@F@FindHomography:
200-
name: FindHomography
201-
c:@F@FindHomography_Async:
202-
name: FindHomography_Async
203199
c:@F@FitEllipse:
204200
name: FitEllipse
205201
c:@F@FitEllipse_Async:
@@ -208,6 +204,10 @@ files:
208204
name: FitLine
209205
c:@F@FitLine_Async:
210206
name: FitLine_Async
207+
c:@F@FloodFill:
208+
name: FloodFill
209+
c:@F@FloodFill_Async:
210+
name: FloodFill_Async
211211
c:@F@GaussianBlur:
212212
name: GaussianBlur
213213
c:@F@GaussianBlur_Async:
@@ -436,10 +436,10 @@ files:
436436
name: SpatialGradient
437437
c:@F@SpatialGradient_Async:
438438
name: SpatialGradient_Async
439-
c:@F@SqBoxFilter:
440-
name: SqBoxFilter
441439
c:@F@SqBoxFilter_Async:
442440
name: SqBoxFilter_Async
441+
c:@F@SqrBoxFilter:
442+
name: SqrBoxFilter
443443
c:@F@Subdiv2D_Close:
444444
name: Subdiv2D_Close
445445
c:@F@Subdiv2D_Close_Async:

0 commit comments

Comments
 (0)