Skip to content

Commit

Permalink
finish stitching, video, ready for test
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyl committed Oct 21, 2024
1 parent fd018de commit c5b8dcb
Show file tree
Hide file tree
Showing 67 changed files with 1,685 additions and 1,794 deletions.
38 changes: 19 additions & 19 deletions packages/dartcv/lib/src/calib3d/calib3d.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import '../native_lib.dart' show ccalib3d;
newImgSize.cvd.ref,
validPixROI,
centerPrincipalPoint,
rval.ref,
rval.ptr,
ffi.nullptr,
),
);
Expand Down Expand Up @@ -209,46 +209,46 @@ Mat undistortPoints(

// Finds the positions of internal corners of the chessboard using a sector based approach.
// https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#gadc5bcb05cb21cf1e50963df26986d7c9
(bool, Mat corners) findChessboardCornersSB(
(bool, VecPoint2f corners) findChessboardCornersSB(
InputArray image,
(int, int) patternSize,
int flags, {
OutputArray? corners,
(int, int) patternSize, {
int flags = 0,
VecPoint2f? corners,
}) {
corners ??= Mat.empty();
final b = calloc<ffi.Bool>();
corners ??= VecPoint2f();
final p = calloc<ffi.Bool>();
cvRun(
() => ccalib3d.cv_findChessboardCornersSB(
image.ref,
patternSize.cvd.ref,
corners!.ref,
patternSize.toSize().ref,
corners!.ptr,
flags,
b,
p,
ffi.nullptr,
),
);
final rval = b.value;
calloc.free(b);
final rval = p.value;
calloc.free(p);
return (rval, corners);
}

// Finds the positions of internal corners of the chessboard using a sector based approach.
// https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#gadc5bcb05cb21cf1e50963df26986d7c9
(bool, Mat corners, Mat meta) findChessboardCornersSBWithMeta(
(bool, VecPoint2f corners, Mat meta) findChessboardCornersSBWithMeta(
InputArray image,
(int, int) patternSize,
int flags, {
OutputArray? corners,
VecPoint2f? corners,
OutputArray? meta,
}) {
corners ??= Mat.empty();
corners ??= VecPoint2f();
meta ??= Mat.empty();
final b = calloc<ffi.Bool>();
cvRun(
() => ccalib3d.cv_FindChessboardCornersSB_1(
image.ref,
patternSize.cvd.ref,
corners!.ref,
corners!.ptr,
flags,
meta!.ref,
b,
Expand Down Expand Up @@ -309,7 +309,7 @@ Mat drawChessboardCorners(
maxIters,
confidence,
refineIters,
rval.ref,
rval.ptr,
ffi.nullptr,
),
);
Expand Down Expand Up @@ -342,7 +342,7 @@ Mat drawChessboardCorners(
maxIters,
confidence,
refineIters,
rval.ref,
rval.ptr,
ffi.nullptr,
),
);
Expand Down Expand Up @@ -373,7 +373,7 @@ Mat findHomography(
mask!.ref,
maxIters,
confidence,
mat.ref,
mat.ptr,
ffi.nullptr,
),
);
Expand Down
24 changes: 12 additions & 12 deletions packages/dartcv/lib/src/calib3d/calib3d_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Future<(Mat rval, Rect validPixROI)> getOptimalNewCameraMatrixAsync(
newImgSize.cvd.ref,
validPixROI,
centerPrincipalPoint,
rval.ref,
rval.ptr,
callback,
),
(c) => c.complete((rval, Rect.fromPointer(validPixROI))),
Expand Down Expand Up @@ -208,19 +208,19 @@ Future<(bool success, Mat corners)> findChessboardCornersAsync(

// Finds the positions of internal corners of the chessboard using a sector based approach.
// https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#gadc5bcb05cb21cf1e50963df26986d7c9
Future<(bool, Mat corners)> findChessboardCornersSBAsync(
Future<(bool, VecPoint2f corners)> findChessboardCornersSBAsync(
InputArray image,
(int, int) patternSize,
int flags, {
OutputArray? corners,
VecPoint2f? corners,
}) async {
corners ??= Mat.empty();
corners ??= VecPoint2f();
final b = calloc<ffi.Bool>();
return cvRunAsync0(
(callback) => ccalib3d.cv_findChessboardCornersSB(
image.ref,
patternSize.cvd.ref,
corners!.ref,
corners!.ptr,
flags,
b,
callback,
Expand All @@ -233,21 +233,21 @@ Future<(bool, Mat corners)> findChessboardCornersSBAsync(

// Finds the positions of internal corners of the chessboard using a sector based approach.
// https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#gadc5bcb05cb21cf1e50963df26986d7c9
Future<(bool, Mat corners, Mat meta)> findChessboardCornersSBWithMetaAsync(
Future<(bool, VecPoint2f corners, Mat meta)> findChessboardCornersSBWithMetaAsync(
InputArray image,
(int, int) patternSize,
int flags, {
OutputArray? corners,
VecPoint2f? corners,
OutputArray? meta,
}) async {
corners ??= Mat.empty();
corners ??= VecPoint2f();
meta ??= Mat.empty();
final b = calloc<ffi.Bool>();
return cvRunAsync0(
(callback) => ccalib3d.cv_FindChessboardCornersSB_1(
image.ref,
patternSize.cvd.ref,
corners!.ref,
corners!.ptr,
flags,
meta!.ref,
b,
Expand Down Expand Up @@ -308,7 +308,7 @@ Future<(Mat, Mat inliers)> estimateAffinePartial2DAsync(
maxIters,
confidence,
refineIters,
rval.ref,
rval.ptr,
callback,
),
(c) => c.complete((rval, inliers!)),
Expand Down Expand Up @@ -341,7 +341,7 @@ Future<(Mat, Mat inliers)> estimateAffine2DAsync(
maxIters,
confidence,
refineIters,
rval.ref,
rval.ptr,
callback,
),
(c) => c.complete((rval, inliers!)),
Expand Down Expand Up @@ -372,7 +372,7 @@ Future<(Mat, Mat)> findHomographyAsync(
mask!.ref,
maxIters,
confidence,
mat.ref,
mat.ptr,
callback,
),
(c) => c.complete((mat, mask!)),
Expand Down
7 changes: 2 additions & 5 deletions packages/dartcv/lib/src/contrib/aruco.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ class ArucoDetector extends CvStruct<cvg.ArucoDetector> {
return ArucoDetector._(p);
}

factory ArucoDetector.create(
ArucoDictionary dictionary,
ArucoDetectorParameters parameters,
) {
factory ArucoDetector.create(ArucoDictionary dictionary, ArucoDetectorParameters parameters) {
final p = calloc<cvg.ArucoDetector>();
cvRun(
() => ccontrib.cv_aruco_arucoDetector_create_1(
Expand All @@ -47,7 +44,7 @@ class ArucoDetector extends CvStruct<cvg.ArucoDetector> {
p,
),
);
return ArucoDetector._(p);
return ArucoDetector.fromPointer(p);
}

@override
Expand Down
53 changes: 50 additions & 3 deletions packages/dartcv/lib/src/contrib/aruco_dict.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'dart:ffi' as ffi;
import 'package:ffi/ffi.dart';

import '../core/base.dart';
import '../core/mat.dart';
import '../g/contrib.g.dart' as cvg;
import '../native_lib.dart' show ccontrib;

Expand Down Expand Up @@ -92,19 +93,65 @@ class ArucoDictionary extends CvStruct<cvg.ArucoDictionary> {
}
}

factory ArucoDictionary.empty() {
final p = calloc<cvg.ArucoDictionary>();
cvRun(() => ccontrib.cv_aruco_Dictionary_create(p));
return ArucoDictionary._(p);
}

factory ArucoDictionary.fromBytesList(Mat bytesList, int markerSize, {int maxCorr = 0}) {
final p = calloc<cvg.ArucoDictionary>();
cvRun(() => ccontrib.cv_aruco_Dictionary_create_1(bytesList.ref, markerSize, maxCorr, p));
return ArucoDictionary._(p);
}

factory ArucoDictionary.predefined(PredefinedDictionaryType type) {
final p = calloc<cvg.ArucoDictionary>();
cvRun(() => ccontrib.cv_aruco_getPredefinedDictionary(type.value, p));
return ArucoDictionary._(p);
}

Mat generateImageMarker(int id, int sidePixels, {OutputArray? dst, int borderBits = 1}) {
dst ??= Mat.empty();
cvRun(() => ccontrib.cv_aruco_Dictionary_generateImageMarker(ref, id, sidePixels, dst!.ref, borderBits));
return dst;
}

int getDistanceToId(InputArray bits, int id, {bool allRotations = true}) =>
ccontrib.cv_aruco_Dictionary_getDistanceToId(ref, bits.ref, id, allRotations);

(bool rval, int idx, int rotation) identify(InputArray onlyBits, double maxCorrectionRate) {
final pIdx = calloc<ffi.Int>();
final pRotation = calloc<ffi.Int>();
final rval = ccontrib.cv_aruco_Dictionary_identify(ref, onlyBits.ref, pIdx, pRotation, maxCorrectionRate);
final ret = (rval, pIdx.value, pRotation.value);
calloc.free(pIdx);
calloc.free(pRotation);
return ret;
}

Mat get bytesList {
final dst = Mat.empty();
cvRun(() => ccontrib.cv_aruco_Dictionary_get_bytesList(ref, dst.ptr));
return dst;
}

set bytesList(Mat value) => ccontrib.cv_aruco_Dictionary_set_bytesList(ref, value.ref);

int get markerSize => ccontrib.cv_aruco_Dictionary_get_markerSize(ref);

set markerSize(int value) => ccontrib.cv_aruco_Dictionary_set_markerSize(ref, value);

int get maxCorrectionBits => ccontrib.cv_aruco_Dictionary_get_maxCorrectionBits(ref);

set maxCorrectionBits(int value) => ccontrib.cv_aruco_Dictionary_set_maxCorrectionBits(ref, value);

@override
cvg.ArucoDictionary get ref => ptr.ref;
static final finalizer =
OcvFinalizer<cvg.ArucoDictionaryPtr>(ccontrib.addresses.cv_aruco_arucoDictionary_close);
static final finalizer = OcvFinalizer<cvg.ArucoDictionaryPtr>(ccontrib.addresses.cv_aruco_Dictionary_close);

void dispose() {
finalizer.detach(this);
ccontrib.cv_aruco_arucoDictionary_close(ptr);
ccontrib.cv_aruco_Dictionary_close(ptr);
}
}
2 changes: 1 addition & 1 deletion packages/dartcv/lib/src/contrib/quality.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class QualityBRISQUE extends CvStruct<cvg.QualityBRISQUE> {
}

/// async version of [computeFeatures]
static Future<Mat> computeFeaturesAsync(Mat img, {Mat? features}) => cvRunAsync0<Mat>(
static Future<Mat> computeFeaturesAsync(Mat img, {Mat? features}) async => cvRunAsync0<Mat>(
(callback) {
features ??= Mat.empty();
return ccontrib.cv_quality_QualityBRISQUE_computeFeatures_static(img.ref, features!.ref, callback);
Expand Down
21 changes: 13 additions & 8 deletions packages/dartcv/lib/src/contrib/ximgproc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,19 @@ class ximgproc {
/// DOI: 10.5220/0006509000850094.
///
/// https://docs.opencv.org/4.x/df/d2d/group__ximgproc.html#ga86fcda65ced0aafa2741088d82e9161c
static Future<Mat> edgePreservingFilterAsync(InputArray src, int d, double threshold,
{OutputArray? dst}) async {
static Future<Mat> edgePreservingFilterAsync(
InputArray src,
int d,
double threshold, {
OutputArray? dst,
}) async {
dst ??= Mat.empty();
return cvRunAsync0(
(callback) => ccontrib.cv_ximgproc_edgePreservingFilter(src.ref, dst!.ref, d, threshold, callback),
(c) {
return c.complete(dst);
});
(callback) => ccontrib.cv_ximgproc_edgePreservingFilter(src.ref, dst!.ref, d, threshold, callback),
(c) {
return c.complete(dst);
},
);
}

/// Finds ellipses fastly in an image using projective invariant pruning.
Expand Down Expand Up @@ -839,7 +844,7 @@ class ximgproc_rl {
/// https://docs.opencv.org/4.x/df/def/group__ximgproc__run__length__morphology.html#ga8a7c10c524fb2572e2eefe0caf0375fc
static Mat getStructuringElement(int shape, (int, int) ksize) {
final dst = Mat.empty();
cvRun(() => ccontrib.cv_ximgproc_rl_getStructuringElement(shape, ksize.cvd.ref, dst.ref, ffi.nullptr));
cvRun(() => ccontrib.cv_ximgproc_rl_getStructuringElement(shape, ksize.cvd.ref, dst.ptr, ffi.nullptr));
return dst;
}

Expand All @@ -849,7 +854,7 @@ class ximgproc_rl {
static Future<Mat> getStructuringElementAsync(int shape, (int, int) ksize) async {
final dst = Mat.empty();
return cvRunAsync0(
(callback) => ccontrib.cv_ximgproc_rl_getStructuringElement(shape, ksize.cvd.ref, dst.ref, callback),
(callback) => ccontrib.cv_ximgproc_rl_getStructuringElement(shape, ksize.cvd.ref, dst.ptr, callback),
(c) {
return c.complete(dst);
});
Expand Down
8 changes: 4 additions & 4 deletions packages/dartcv/lib/src/core/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ typedef VoidPtr = ffi.Pointer<ffi.Void>;
Future<T> cvRunAsync0<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_0 callback) func,
void Function(Completer<T> completer) onComplete,
) {
) async {
final completer = Completer<T>();
late final ffi.NativeCallable<cvg.CvCallback_0Function> ccallback;
void onResponse() {
Expand All @@ -100,7 +100,9 @@ Future<T> cvRunAsync0<T>(
return completer.future;
}

Future<T> cvRunAsync<T>(
const cvRunAsync = cvRunAsync0;

Future<T> cvRunAsync1<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_1 callback) func,
void Function(Completer<T> completer, VoidPtr p) onComplete,
) {
Expand All @@ -116,8 +118,6 @@ Future<T> cvRunAsync<T>(
return completer.future;
}

const cvRunAsync1 = cvRunAsync;

Future<T> cvRunAsync2<T>(
ffi.Pointer<cvg.CvStatus> Function(cvg.CvCallback_2 callback) func,
void Function(Completer<T> completer, VoidPtr p, VoidPtr p1) onComplete,
Expand Down
5 changes: 3 additions & 2 deletions packages/dartcv/lib/src/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,9 @@ Mat scaleAdd(InputArray src1, double alpha, InputArray src2, {OutputArray? dst})
/// For further details, please see:
///
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga388d7575224a4a277ceb98ccaa327c99
Mat setIdentity(InputOutputArray mtx, {double s = 1}) {
cvRun(() => ccore.cv_setIdentity(mtx.ref, s, ffi.nullptr));
Mat setIdentity(InputOutputArray mtx, {Scalar? s}) {
s ??= Scalar.all(1.0);
cvRun(() => ccore.cv_setIdentity(mtx.ref, s!.ref, ffi.nullptr));
return mtx;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/dartcv/lib/src/core/core_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1330,9 +1330,10 @@ Future<Mat> scaleAddAsync(InputArray src1, double alpha, InputArray src2, {Outpu
/// For further details, please see:
///
/// https://docs.opencv.org/master/d2/de8/group__core__array.html#ga388d7575224a4a277ceb98ccaa327c99
Future<Mat> setIdentityAsync(InputOutputArray mtx, {double s = 1}) async {
Future<Mat> setIdentityAsync(InputOutputArray mtx, {Scalar? s}) async {
s ??= Scalar.all(1.0);
return cvRunAsync0(
(callback) => ccore.cv_setIdentity(mtx.ref, s, callback),
(callback) => ccore.cv_setIdentity(mtx.ref, s!.ref, callback),
(c) {
return c.complete(mtx);
},
Expand Down
Loading

0 comments on commit c5b8dcb

Please sign in to comment.