Skip to content

Commit

Permalink
add cv.floodFill, move findHomography to calib3d
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyl committed Sep 5, 2024
1 parent e40c871 commit cd6a95f
Show file tree
Hide file tree
Showing 19 changed files with 1,181 additions and 480 deletions.
30 changes: 30 additions & 0 deletions lib/src/calib3d/calib3d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,33 @@ Mat drawChessboardCorners(
);
return (Mat.fromPointer(p), inliers);
}

/// FindHomography finds an optimal homography matrix using 4 or more point pairs (as opposed to GetPerspectiveTransform, which uses exactly 4)
///
/// For further details, please see:
/// https:///docs.opencv.org/master/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780
Mat findHomography(
InputArray srcPoints,
InputArray dstPoints, {
int method = 0,
double ransacReprojThreshold = 3,
OutputArray? mask,
int maxIters = 2000,
double confidence = 0.995,
}) {
mask ??= Mat.empty();
final mat = calloc<cvg.Mat>();
cvRun(
() => ccalib3d.FindHomography(
srcPoints.ref,
dstPoints.ref,
method,
ransacReprojThreshold,
mask!.ref,
maxIters,
confidence,
mat,
),
);
return Mat.fromPointer(mat);
}
25 changes: 25 additions & 0 deletions lib/src/calib3d/calib3d_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,28 @@ Future<(Mat, Mat inliers)> estimateAffine2DAsync(
),
matCompleter2,
);

/// FindHomography finds an optimal homography matrix using 4 or more point pairs (as opposed to GetPerspectiveTransform, which uses exactly 4)
///
/// For further details, please see:
/// https:///docs.opencv.org/master/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780
Future<(Mat, Mat)> findHomographyAsync(
InputArray srcPoints,
InputArray dstPoints, {
int method = 0,
double ransacReprojThreshold = 3,
int maxIters = 2000,
double confidence = 0.995,
}) async =>
cvRunAsync2(
(callback) => ccalib3d.FindHomography_Async(
srcPoints.ref,
dstPoints.ref,
method,
ransacReprojThreshold,
maxIters,
confidence,
callback,
),
matCompleter2,
);
58 changes: 58 additions & 0 deletions lib/src/g/calib3d.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,64 @@ class CvNativeCalib3d {
ffi.Pointer<CvStatus> Function(
Mat, Size, Mat, int, Mat, ffi.Pointer<ffi.Bool>)>();

ffi.Pointer<CvStatus> FindHomography(
Mat src,
Mat dst,
int method,
double ransacReprojThreshold,
Mat mask,
int maxIters,
double confidence,
ffi.Pointer<Mat> rval,
) {
return _FindHomography(
src,
dst,
method,
ransacReprojThreshold,
mask,
maxIters,
confidence,
rval,
);
}

late final _FindHomographyPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, Mat,
ffi.Int, ffi.Double, ffi.Pointer<Mat>)>>('FindHomography');
late final _FindHomography = _FindHomographyPtr.asFunction<
ffi.Pointer<CvStatus> Function(
Mat, Mat, int, double, Mat, int, double, ffi.Pointer<Mat>)>();

ffi.Pointer<CvStatus> FindHomography_Async(
Mat src,
Mat dst,
int method,
double ransacReprojThreshold,
int maxIters,
double confidence,
imp1.CvCallback_2 callback,
) {
return _FindHomography_Async(
src,
dst,
method,
ransacReprojThreshold,
maxIters,
confidence,
callback,
);
}

late final _FindHomography_AsyncPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, ffi.Int,
ffi.Double, imp1.CvCallback_2)>>('FindHomography_Async');
late final _FindHomography_Async = _FindHomography_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(
Mat, Mat, int, double, int, double, imp1.CvCallback_2)>();

ffi.Pointer<CvStatus> Fisheye_EstimateNewCameraMatrixForUndistortRectify(
Mat k,
Mat d,
Expand Down
4 changes: 4 additions & 0 deletions lib/src/g/calib3d.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ files:
name: FindChessboardCornersSB
c:@F@FindChessboardCornersSBWithMeta:
name: FindChessboardCornersSBWithMeta
c:@F@FindHomography:
name: FindHomography
c:@F@FindHomography_Async:
name: FindHomography_Async
c:@F@Fisheye_EstimateNewCameraMatrixForUndistortRectify:
name: Fisheye_EstimateNewCameraMatrixForUndistortRectify
c:@F@Fisheye_UndistortImage:
Expand Down
176 changes: 94 additions & 82 deletions lib/src/g/imgproc.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2238,64 +2238,6 @@ class CvNativeImgproc {
late final _FindContours_Async = _FindContours_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, int, int, imp1.CvCallback_2)>();

ffi.Pointer<CvStatus> FindHomography(
Mat src,
Mat dst,
int method,
double ransacReprojThreshold,
Mat mask,
int maxIters,
double confidence,
ffi.Pointer<Mat> rval,
) {
return _FindHomography(
src,
dst,
method,
ransacReprojThreshold,
mask,
maxIters,
confidence,
rval,
);
}

late final _FindHomographyPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, Mat,
ffi.Int, ffi.Double, ffi.Pointer<Mat>)>>('FindHomography');
late final _FindHomography = _FindHomographyPtr.asFunction<
ffi.Pointer<CvStatus> Function(
Mat, Mat, int, double, Mat, int, double, ffi.Pointer<Mat>)>();

ffi.Pointer<CvStatus> FindHomography_Async(
Mat src,
Mat dst,
int method,
double ransacReprojThreshold,
int maxIters,
double confidence,
imp1.CvCallback_2 callback,
) {
return _FindHomography_Async(
src,
dst,
method,
ransacReprojThreshold,
maxIters,
confidence,
callback,
);
}

late final _FindHomography_AsyncPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, ffi.Double, ffi.Int,
ffi.Double, imp1.CvCallback_2)>>('FindHomography_Async');
late final _FindHomography_Async = _FindHomography_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(
Mat, Mat, int, double, int, double, imp1.CvCallback_2)>();

ffi.Pointer<CvStatus> FitEllipse(
VecPoint pts,
ffi.Pointer<RotatedRect> rval,
Expand Down Expand Up @@ -2382,6 +2324,76 @@ class CvNativeImgproc {
ffi.Pointer<CvStatus> Function(
VecPoint, int, double, double, double, imp1.CvCallback_1)>();

ffi.Pointer<CvStatus> FloodFill(
Mat src,
Mat mask,
Point seedPoint,
Scalar newVal,
ffi.Pointer<Rect> rect,
Scalar loDiff,
Scalar upDiff,
int flags,
ffi.Pointer<ffi.Int> rval,
) {
return _FloodFill(
src,
mask,
seedPoint,
newVal,
rect,
loDiff,
upDiff,
flags,
rval,
);
}

late final _FloodFillPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(
Mat,
Mat,
Point,
Scalar,
ffi.Pointer<Rect>,
Scalar,
Scalar,
ffi.Int,
ffi.Pointer<ffi.Int>)>>('FloodFill');
late final _FloodFill = _FloodFillPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, Point, Scalar, ffi.Pointer<Rect>,
Scalar, Scalar, int, ffi.Pointer<ffi.Int>)>();

ffi.Pointer<CvStatus> FloodFill_Async(
Mat src,
Mat mask,
Point seedPoint,
Scalar newVal,
Scalar loDiff,
Scalar upDiff,
int flags,
imp1.CvCallback_2 callback,
) {
return _FloodFill_Async(
src,
mask,
seedPoint,
newVal,
loDiff,
upDiff,
flags,
callback,
);
}

late final _FloodFill_AsyncPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, Point, Scalar, Scalar,
Scalar, ffi.Int, imp1.CvCallback_2)>>('FloodFill_Async');
late final _FloodFill_Async = _FloodFill_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(
Mat, Mat, Point, Scalar, Scalar, Scalar, int, imp1.CvCallback_2)>();

ffi.Pointer<CvStatus> GaussianBlur(
Mat src,
Mat dst,
Expand Down Expand Up @@ -5278,53 +5290,53 @@ class CvNativeImgproc {
late final _SpatialGradient_Async = _SpatialGradient_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, int, int, imp1.CvCallback_2)>();

ffi.Pointer<CvStatus> SqBoxFilter(
ffi.Pointer<CvStatus> SqBoxFilter_Async(
Mat src,
Mat dst,
int ddepth,
Size ps,
Point anchor,
bool normalize,
int borderType,
imp1.CvCallback_1 callback,
) {
return _SqBoxFilter(
return _SqBoxFilter_Async(
src,
dst,
ddepth,
ps,
anchor,
normalize,
borderType,
callback,
);
}

late final _SqBoxFilterPtr = _lookup<
late final _SqBoxFilter_AsyncPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, Size, Point,
ffi.Bool, ffi.Int)>>('SqBoxFilter');
late final _SqBoxFilter = _SqBoxFilterPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, int, Size, Point, bool, int)>();
ffi.Pointer<CvStatus> Function(
Mat, ffi.Int, Size, imp1.CvCallback_1)>>('SqBoxFilter_Async');
late final _SqBoxFilter_Async = _SqBoxFilter_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, int, Size, imp1.CvCallback_1)>();

ffi.Pointer<CvStatus> SqBoxFilter_Async(
ffi.Pointer<CvStatus> SqrBoxFilter(
Mat src,
Mat dst,
int ddepth,
Size ps,
imp1.CvCallback_1 callback,
Point anchor,
bool normalize,
int borderType,
) {
return _SqBoxFilter_Async(
return _SqrBoxFilter(
src,
dst,
ddepth,
ps,
callback,
anchor,
normalize,
borderType,
);
}

late final _SqBoxFilter_AsyncPtr = _lookup<
late final _SqrBoxFilterPtr = _lookup<
ffi.NativeFunction<
ffi.Pointer<CvStatus> Function(
Mat, ffi.Int, Size, imp1.CvCallback_1)>>('SqBoxFilter_Async');
late final _SqBoxFilter_Async = _SqBoxFilter_AsyncPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, int, Size, imp1.CvCallback_1)>();
ffi.Pointer<CvStatus> Function(Mat, Mat, ffi.Int, Size, Point,
ffi.Bool, ffi.Int)>>('SqrBoxFilter');
late final _SqrBoxFilter = _SqrBoxFilterPtr.asFunction<
ffi.Pointer<CvStatus> Function(Mat, Mat, int, Size, Point, bool, int)>();

void Subdiv2D_Close(
Subdiv2DPtr self,
Expand Down
12 changes: 6 additions & 6 deletions lib/src/g/imgproc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,6 @@ files:
name: FindContours
c:@F@FindContours_Async:
name: FindContours_Async
c:@F@FindHomography:
name: FindHomography
c:@F@FindHomography_Async:
name: FindHomography_Async
c:@F@FitEllipse:
name: FitEllipse
c:@F@FitEllipse_Async:
Expand All @@ -208,6 +204,10 @@ files:
name: FitLine
c:@F@FitLine_Async:
name: FitLine_Async
c:@F@FloodFill:
name: FloodFill
c:@F@FloodFill_Async:
name: FloodFill_Async
c:@F@GaussianBlur:
name: GaussianBlur
c:@F@GaussianBlur_Async:
Expand Down Expand Up @@ -436,10 +436,10 @@ files:
name: SpatialGradient
c:@F@SpatialGradient_Async:
name: SpatialGradient_Async
c:@F@SqBoxFilter:
name: SqBoxFilter
c:@F@SqBoxFilter_Async:
name: SqBoxFilter_Async
c:@F@SqrBoxFilter:
name: SqrBoxFilter
c:@F@Subdiv2D_Close:
name: Subdiv2D_Close
c:@F@Subdiv2D_Close_Async:
Expand Down
Loading

0 comments on commit cd6a95f

Please sign in to comment.