diff --git a/ffigen.yaml b/ffigen.yaml index 0ff6656c..68aa1355 100644 --- a/ffigen.yaml +++ b/ffigen.yaml @@ -40,7 +40,9 @@ headers: - src/objdetect/objdetect.h - src/objdetect/objdetect_async.h - src/photo/photo.h + - src/photo/photo_async.h - src/stitching/stitching.h + - src/stitching/stitching_async.h - src/video/video.h - src/video/videoio.h include-directives: @@ -69,7 +71,9 @@ headers: - src/objdetect/objdetect.h - src/objdetect/objdetect_async.h - src/photo/photo.h + - src/photo/photo_async.h - src/stitching/stitching.h + - src/stitching/stitching_async.h - src/video/video.h - src/video/videoio.h functions: diff --git a/lib/opencv_dart.dart b/lib/opencv_dart.dart index 6acd2560..db33fc6f 100644 --- a/lib/opencv_dart.dart +++ b/lib/opencv_dart.dart @@ -43,7 +43,9 @@ export 'src/imgproc/subdiv2d_async.dart'; export 'src/objdetect/objdetect.dart'; export 'src/objdetect/objdetect_async.dart'; export 'src/photo/photo.dart'; +export 'src/photo/photo_async.dart'; export 'src/stitching/stitching.dart'; +export 'src/stitching/stitching_async.dart'; export 'src/svd/svd.dart'; export 'src/video/video.dart'; export 'src/video/videoio.dart'; diff --git a/lib/src/core/base.dart b/lib/src/core/base.dart index 7a5ece10..49c7894c 100644 --- a/lib/src/core/base.dart +++ b/lib/src/core/base.dart @@ -43,7 +43,9 @@ ffi.DynamicLibrary loadNativeLibrary() { "windows" => "$_libraryName.dll", "linux" || "android" || "fuchsia" => "lib$_libraryName.so", "macos" => "lib$_libraryName.dylib", - _ => throw UnsupportedError("Platform ${Platform.operatingSystem} not supported") + _ => throw UnsupportedError( + "Platform ${Platform.operatingSystem} not supported", + ) }; final libPath = Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath; return ffi.DynamicLibrary.open(libPath); @@ -152,7 +154,13 @@ Future cvRunAsync3( Future cvRunAsync4( ffi.Pointer Function(cvg.CvCallback_4 callback) func, - void Function(Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3) onComplete, + void Function( + Completer completer, + VoidPtr p, + VoidPtr p1, + VoidPtr p2, + VoidPtr p3, + ) onComplete, ) { final completer = Completer(); late final NativeCallable ccallback; @@ -168,7 +176,14 @@ Future cvRunAsync4( Future cvRunAsync5( ffi.Pointer Function(cvg.CvCallback_5 callback) func, - void Function(Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3, VoidPtr p4) onComplete, + void Function( + Completer completer, + VoidPtr p, + VoidPtr p1, + VoidPtr p2, + VoidPtr p3, + VoidPtr p4, + ) onComplete, ) { final completer = Completer(); late final NativeCallable ccallback; @@ -189,6 +204,12 @@ void intCompleter(Completer completer, VoidPtr p) { completer.complete(value); } +void boolCompleter(Completer completer, VoidPtr p) { + final value = p.cast().value; + calloc.free(p); + completer.complete(value); +} + void doubleCompleter(Completer completer, VoidPtr p) { final value = p.cast().value; calloc.free(p); @@ -227,7 +248,9 @@ R cvRunArena( typedef NativeFinalizerFunctionT = ffi.Pointer>; -ffi.NativeFinalizer OcvFinalizer(NativeFinalizerFunctionT func) => +ffi.NativeFinalizer OcvFinalizer( + NativeFinalizerFunctionT func, +) => ffi.NativeFinalizer(func.cast()); // native types diff --git a/lib/src/opencv.g.dart b/lib/src/opencv.g.dart index 31775d22..9b5f2d87 100644 --- a/lib/src/opencv.g.dart +++ b/lib/src/opencv.g.dart @@ -385,6 +385,42 @@ class CvNative { ffi.Pointer Function( int, int, bool, ffi.Pointer)>(); + ffi.Pointer AlignMTB_CreateWithParams_Async( + int max_bits, + int exclude_range, + bool cut, + CvCallback_1 callback, + ) { + return _AlignMTB_CreateWithParams_Async( + max_bits, + exclude_range, + cut, + callback, + ); + } + + late final _AlignMTB_CreateWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Int, ffi.Int, ffi.Bool, + CvCallback_1)>>('AlignMTB_CreateWithParams_Async'); + late final _AlignMTB_CreateWithParams_Async = + _AlignMTB_CreateWithParams_AsyncPtr.asFunction< + ffi.Pointer Function(int, int, bool, CvCallback_1)>(); + + ffi.Pointer AlignMTB_Create_Async( + CvCallback_1 callback, + ) { + return _AlignMTB_Create_Async( + callback, + ); + } + + late final _AlignMTB_Create_AsyncPtr = + _lookup Function(CvCallback_1)>>( + 'AlignMTB_Create_Async'); + late final _AlignMTB_Create_Async = _AlignMTB_Create_AsyncPtr.asFunction< + ffi.Pointer Function(CvCallback_1)>(); + ffi.Pointer AlignMTB_Process( AlignMTB b, VecMat src, @@ -404,6 +440,25 @@ class CvNative { late final _AlignMTB_Process = _AlignMTB_ProcessPtr.asFunction< ffi.Pointer Function(AlignMTB, VecMat, ffi.Pointer)>(); + ffi.Pointer AlignMTB_Process_Async( + AlignMTB b, + VecMat src, + CvCallback_1 callback, + ) { + return _AlignMTB_Process_Async( + b, + src, + callback, + ); + } + + late final _AlignMTB_Process_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + AlignMTB, VecMat, CvCallback_1)>>('AlignMTB_Process_Async'); + late final _AlignMTB_Process_Async = _AlignMTB_Process_AsyncPtr.asFunction< + ffi.Pointer Function(AlignMTB, VecMat, CvCallback_1)>(); + ffi.Pointer ApplyColorMap( Mat src, Mat dst, @@ -4153,6 +4208,32 @@ class CvNative { late final _ColorChange = _ColorChangePtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double, double)>(); + ffi.Pointer ColorChange_Async( + Mat src, + Mat mask, + double red_mul, + double green_mul, + double blue_mul, + CvCallback_1 callback, + ) { + return _ColorChange_Async( + src, + mask, + red_mul, + green_mul, + blue_mul, + callback, + ); + } + + late final _ColorChange_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, + ffi.Float, CvCallback_1)>>('ColorChange_Async'); + late final _ColorChange_Async = _ColorChange_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, double, double, double, CvCallback_1)>(); + ffi.Pointer CompareHist( Mat hist1, Mat hist2, @@ -4536,6 +4617,27 @@ class CvNative { late final _DetailEnhance = _DetailEnhancePtr.asFunction< ffi.Pointer Function(Mat, Mat, double, double)>(); + ffi.Pointer DetailEnhance_Async( + Mat src, + double sigma_s, + double sigma_r, + CvCallback_1 callback, + ) { + return _DetailEnhance_Async( + src, + sigma_s, + sigma_r, + callback, + ); + } + + late final _DetailEnhance_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Mat, ffi.Float, ffi.Float, CvCallback_1)>>('DetailEnhance_Async'); + late final _DetailEnhance_Async = _DetailEnhance_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, double, double, CvCallback_1)>(); + ffi.Pointer Dilate( Mat src, Mat dst, @@ -4991,6 +5093,31 @@ class CvNative { late final _EdgePreservingFilter = _EdgePreservingFilterPtr.asFunction< ffi.Pointer Function(Mat, Mat, int, double, double)>(); + ffi.Pointer EdgePreservingFilter_Async( + Mat src, + int filter, + double sigma_s, + double sigma_r, + CvCallback_1 callback, + ) { + return _EdgePreservingFilter_Async( + src, + filter, + sigma_s, + sigma_r, + callback, + ); + } + + late final _EdgePreservingFilter_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, ffi.Int, ffi.Float, ffi.Float, + CvCallback_1)>>('EdgePreservingFilter_Async'); + late final _EdgePreservingFilter_Async = + _EdgePreservingFilter_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, int, double, double, CvCallback_1)>(); + ffi.Pointer Ellipse( Mat img, Point center, @@ -6418,6 +6545,60 @@ class CvNative { ffi.Pointer Function( VecMat, Mat, int, int, double, double, int, int)>(); + ffi.Pointer FastNlMeansDenoisingColoredMultiWithParams_Async( + VecMat src, + int imgToDenoiseIndex, + int temporalWindowSize, + double h, + double hColor, + int templateWindowSize, + int searchWindowSize, + CvCallback_1 callback, + ) { + return _FastNlMeansDenoisingColoredMultiWithParams_Async( + src, + imgToDenoiseIndex, + temporalWindowSize, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingColoredMultiWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(VecMat, ffi.Int, ffi.Int, + ffi.Float, ffi.Float, ffi.Int, ffi.Int, CvCallback_1)>>( + 'FastNlMeansDenoisingColoredMultiWithParams_Async'); + late final _FastNlMeansDenoisingColoredMultiWithParams_Async = + _FastNlMeansDenoisingColoredMultiWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + VecMat, int, int, double, double, int, int, CvCallback_1)>(); + + ffi.Pointer FastNlMeansDenoisingColoredMulti_Async( + VecMat src, + int imgToDenoiseIndex, + int temporalWindowSize, + CvCallback_1 callback, + ) { + return _FastNlMeansDenoisingColoredMulti_Async( + src, + imgToDenoiseIndex, + temporalWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingColoredMulti_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(VecMat, ffi.Int, ffi.Int, + CvCallback_1)>>('FastNlMeansDenoisingColoredMulti_Async'); + late final _FastNlMeansDenoisingColoredMulti_Async = + _FastNlMeansDenoisingColoredMulti_AsyncPtr.asFunction< + ffi.Pointer Function(VecMat, int, int, CvCallback_1)>(); + ffi.Pointer FastNlMeansDenoisingColoredWithParams( Mat src, Mat dst, @@ -6444,6 +6625,56 @@ class CvNative { _FastNlMeansDenoisingColoredWithParamsPtr.asFunction< ffi.Pointer Function(Mat, Mat, double, double, int, int)>(); + ffi.Pointer FastNlMeansDenoisingColoredWithParams_Async( + Mat src, + double h, + double hColor, + int templateWindowSize, + int searchWindowSize, + CvCallback_1 callback, + ) { + return _FastNlMeansDenoisingColoredWithParams_Async( + src, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingColoredWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Mat, + ffi.Float, + ffi.Float, + ffi.Int, + ffi.Int, + CvCallback_1)>>('FastNlMeansDenoisingColoredWithParams_Async'); + late final _FastNlMeansDenoisingColoredWithParams_Async = + _FastNlMeansDenoisingColoredWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, double, double, int, int, CvCallback_1)>(); + + ffi.Pointer FastNlMeansDenoisingColored_Async( + Mat src, + CvCallback_1 callback, + ) { + return _FastNlMeansDenoisingColored_Async( + src, + callback, + ); + } + + late final _FastNlMeansDenoisingColored_AsyncPtr = _lookup< + ffi + .NativeFunction Function(Mat, CvCallback_1)>>( + 'FastNlMeansDenoisingColored_Async'); + late final _FastNlMeansDenoisingColored_Async = + _FastNlMeansDenoisingColored_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, CvCallback_1)>(); + ffi.Pointer FastNlMeansDenoisingWithParams( Mat src, Mat dst, @@ -6468,6 +6699,48 @@ class CvNative { _FastNlMeansDenoisingWithParamsPtr.asFunction< ffi.Pointer Function(Mat, Mat, double, int, int)>(); + ffi.Pointer FastNlMeansDenoisingWithParams_Async( + Mat src, + double h, + int templateWindowSize, + int searchWindowSize, + CvCallback_1 callback, + ) { + return _FastNlMeansDenoisingWithParams_Async( + src, + h, + templateWindowSize, + searchWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, ffi.Float, ffi.Int, ffi.Int, + CvCallback_1)>>('FastNlMeansDenoisingWithParams_Async'); + late final _FastNlMeansDenoisingWithParams_Async = + _FastNlMeansDenoisingWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, double, int, int, CvCallback_1)>(); + + ffi.Pointer FastNlMeansDenoising_Async( + Mat src, + CvCallback_1 callback, + ) { + return _FastNlMeansDenoising_Async( + src, + callback, + ); + } + + late final _FastNlMeansDenoising_AsyncPtr = _lookup< + ffi + .NativeFunction Function(Mat, CvCallback_1)>>( + 'FastNlMeansDenoising_Async'); + late final _FastNlMeansDenoising_Async = _FastNlMeansDenoising_AsyncPtr + .asFunction Function(Mat, CvCallback_1)>(); + ffi.Pointer FillPoly( Mat img, VecVecPoint points, @@ -9342,6 +9615,31 @@ class CvNative { late final _IlluminationChange = _IlluminationChangePtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double)>(); + ffi.Pointer IlluminationChange_Async( + Mat src, + Mat mask, + double alpha, + double beta, + CvCallback_1 callback, + ) { + return _IlluminationChange_Async( + src, + mask, + alpha, + beta, + callback, + ); + } + + late final _IlluminationChange_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, + CvCallback_1)>>('IlluminationChange_Async'); + late final _IlluminationChange_Async = + _IlluminationChange_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, double, double, CvCallback_1)>(); + ffi.Pointer Image_IMDecode( VecUChar buf, int flags, @@ -16243,6 +16541,43 @@ class CvNative { ffi.Pointer Function( double, double, double, ffi.Pointer)>(); + ffi.Pointer MergeMertens_CreateWithParams_Async( + double contrast_weight, + double saturation_weight, + double exposure_weight, + CvCallback_1 callback, + ) { + return _MergeMertens_CreateWithParams_Async( + contrast_weight, + saturation_weight, + exposure_weight, + callback, + ); + } + + late final _MergeMertens_CreateWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Float, ffi.Float, ffi.Float, + CvCallback_1)>>('MergeMertens_CreateWithParams_Async'); + late final _MergeMertens_CreateWithParams_Async = + _MergeMertens_CreateWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + double, double, double, CvCallback_1)>(); + + ffi.Pointer MergeMertens_Create_Async( + CvCallback_1 callback, + ) { + return _MergeMertens_Create_Async( + callback, + ); + } + + late final _MergeMertens_Create_AsyncPtr = + _lookup Function(CvCallback_1)>>( + 'MergeMertens_Create_Async'); + late final _MergeMertens_Create_Async = _MergeMertens_Create_AsyncPtr + .asFunction Function(CvCallback_1)>(); + ffi.Pointer MergeMertens_Process( MergeMertens b, VecMat src, @@ -16262,6 +16597,26 @@ class CvNative { late final _MergeMertens_Process = _MergeMertens_ProcessPtr.asFunction< ffi.Pointer Function(MergeMertens, VecMat, Mat)>(); + ffi.Pointer MergeMertens_Process_Async( + MergeMertens b, + VecMat src, + CvCallback_1 callback, + ) { + return _MergeMertens_Process_Async( + b, + src, + callback, + ); + } + + late final _MergeMertens_Process_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(MergeMertens, VecMat, + CvCallback_1)>>('MergeMertens_Process_Async'); + late final _MergeMertens_Process_Async = + _MergeMertens_Process_AsyncPtr.asFunction< + ffi.Pointer Function(MergeMertens, VecMat, CvCallback_1)>(); + ffi.Pointer MinAreaRect( VecPoint pts, ffi.Pointer rval, @@ -18183,15 +18538,39 @@ class CvNative { late final _PencilSketch = _PencilSketchPtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double, double)>(); - ffi.Pointer PhaseCorrelate( - Mat src1, - Mat src2, - Mat window, - ffi.Pointer response, - ffi.Pointer rval, - ) { - return _PhaseCorrelate( - src1, + ffi.Pointer PencilSketch_Async( + Mat src, + double sigma_s, + double sigma_r, + double shade_factor, + CvCallback_2 callback, + ) { + return _PencilSketch_Async( + src, + sigma_s, + sigma_r, + shade_factor, + callback, + ); + } + + late final _PencilSketch_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, ffi.Float, ffi.Float, ffi.Float, + CvCallback_2)>>('PencilSketch_Async'); + late final _PencilSketch_Async = _PencilSketch_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, double, double, double, CvCallback_2)>(); + + ffi.Pointer PhaseCorrelate( + Mat src1, + Mat src2, + Mat window, + ffi.Pointer response, + ffi.Pointer rval, + ) { + return _PhaseCorrelate( + src1, src2, window, response, @@ -18251,6 +18630,29 @@ class CvNative { late final _PhotoInpaint = _PhotoInpaintPtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, int)>(); + ffi.Pointer PhotoInpaint_Async( + Mat src, + Mat mask, + double inpaint_radius, + int algorithm_type, + CvCallback_1 callback, + ) { + return _PhotoInpaint_Async( + src, + mask, + inpaint_radius, + algorithm_type, + callback, + ); + } + + late final _PhotoInpaint_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Int, + CvCallback_1)>>('PhotoInpaint_Async'); + late final _PhotoInpaint_Async = _PhotoInpaint_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, Mat, double, int, CvCallback_1)>(); + ffi.Pointer PointPolygonTest( VecPoint pts, Point2f pt, @@ -20108,6 +20510,32 @@ class CvNative { late final _SeamlessClone = _SeamlessClonePtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, Point, Mat, int)>(); + ffi.Pointer SeamlessClone_Async( + Mat src, + Mat dst, + Mat mask, + Point p, + int flags, + CvCallback_1 callback, + ) { + return _SeamlessClone_Async( + src, + dst, + mask, + p, + flags, + callback, + ); + } + + late final _SeamlessClone_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, Point, ffi.Int, + CvCallback_1)>>('SeamlessClone_Async'); + late final _SeamlessClone_Async = _SeamlessClone_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, Point, int, CvCallback_1)>(); + ffi.Pointer SepFilter2D( Mat src, Mat dst, @@ -20518,7 +20946,7 @@ class CvNative { ffi.Pointer Function(Mat, int, Size, CvCallback_1)>(); void Stitcher_Close( - PtrStitcherPtr stitcher, + StitcherPtr stitcher, ) { return _Stitcher_Close( stitcher, @@ -20526,10 +20954,26 @@ class CvNative { } late final _Stitcher_ClosePtr = - _lookup>( + _lookup>( 'Stitcher_Close'); late final _Stitcher_Close = - _Stitcher_ClosePtr.asFunction(); + _Stitcher_ClosePtr.asFunction(); + + void Stitcher_Close_Async( + StitcherPtr stitcher, + CvCallback_0 callback, + ) { + return _Stitcher_Close_Async( + stitcher, + callback, + ); + } + + late final _Stitcher_Close_AsyncPtr = + _lookup>( + 'Stitcher_Close_Async'); + late final _Stitcher_Close_Async = _Stitcher_Close_AsyncPtr.asFunction< + void Function(StitcherPtr, CvCallback_0)>(); ffi.Pointer Stitcher_Component( Stitcher self, @@ -20548,6 +20992,23 @@ class CvNative { late final _Stitcher_Component = _Stitcher_ComponentPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_Component_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_Component_Async( + self, + callback, + ); + } + + late final _Stitcher_Component_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_1)>>('Stitcher_Component_Async'); + late final _Stitcher_Component_Async = _Stitcher_Component_AsyncPtr + .asFunction Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_ComposePanorama( Stitcher self, Mat rpano, @@ -20592,9 +21053,47 @@ class CvNative { ffi.Pointer Function( Stitcher, VecMat, Mat, ffi.Pointer)>(); + ffi.Pointer Stitcher_ComposePanorama_1_Async( + Stitcher self, + VecMat mats, + CvCallback_2 callback, + ) { + return _Stitcher_ComposePanorama_1_Async( + self, + mats, + callback, + ); + } + + late final _Stitcher_ComposePanorama_1_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, VecMat, + CvCallback_2)>>('Stitcher_ComposePanorama_1_Async'); + late final _Stitcher_ComposePanorama_1_Async = + _Stitcher_ComposePanorama_1_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, VecMat, CvCallback_2)>(); + + ffi.Pointer Stitcher_ComposePanorama_Async( + Stitcher self, + CvCallback_2 callback, + ) { + return _Stitcher_ComposePanorama_Async( + self, + callback, + ); + } + + late final _Stitcher_ComposePanorama_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_2)>>('Stitcher_ComposePanorama_Async'); + late final _Stitcher_ComposePanorama_Async = + _Stitcher_ComposePanorama_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_2)>(); + ffi.Pointer Stitcher_Create( int mode, - ffi.Pointer rval, + ffi.Pointer rval, ) { return _Stitcher_Create( mode, @@ -20605,9 +21104,26 @@ class CvNative { late final _Stitcher_CreatePtr = _lookup< ffi.NativeFunction< ffi.Pointer Function( - ffi.Int, ffi.Pointer)>>('Stitcher_Create'); + ffi.Int, ffi.Pointer)>>('Stitcher_Create'); late final _Stitcher_Create = _Stitcher_CreatePtr.asFunction< - ffi.Pointer Function(int, ffi.Pointer)>(); + ffi.Pointer Function(int, ffi.Pointer)>(); + + ffi.Pointer Stitcher_Create_Async( + int mode, + CvCallback_1 callback, + ) { + return _Stitcher_Create_Async( + mode, + callback, + ); + } + + late final _Stitcher_Create_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Int, CvCallback_1)>>('Stitcher_Create_Async'); + late final _Stitcher_Create_Async = _Stitcher_Create_AsyncPtr.asFunction< + ffi.Pointer Function(int, CvCallback_1)>(); ffi.Pointer Stitcher_EstimateTransform( Stitcher self, @@ -20632,8 +21148,31 @@ class CvNative { ffi.Pointer Function( Stitcher, VecMat, VecMat, ffi.Pointer)>(); + ffi.Pointer Stitcher_EstimateTransform_Async( + Stitcher self, + VecMat mats, + VecMat masks, + CvCallback_1 callback, + ) { + return _Stitcher_EstimateTransform_Async( + self, + mats, + masks, + callback, + ); + } + + late final _Stitcher_EstimateTransform_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, VecMat, VecMat, + CvCallback_1)>>('Stitcher_EstimateTransform_Async'); + late final _Stitcher_EstimateTransform_Async = + _Stitcher_EstimateTransform_AsyncPtr.asFunction< + ffi.Pointer Function( + Stitcher, VecMat, VecMat, CvCallback_1)>(); + ffi.Pointer Stitcher_Get( - PtrStitcher self, + Stitcher self, ffi.Pointer rval, ) { return _Stitcher_Get( @@ -20645,9 +21184,9 @@ class CvNative { late final _Stitcher_GetPtr = _lookup< ffi.NativeFunction< ffi.Pointer Function( - PtrStitcher, ffi.Pointer)>>('Stitcher_Get'); + Stitcher, ffi.Pointer)>>('Stitcher_Get'); late final _Stitcher_Get = _Stitcher_GetPtr.asFunction< - ffi.Pointer Function(PtrStitcher, ffi.Pointer)>(); + ffi.Pointer Function(Stitcher, ffi.Pointer)>(); ffi.Pointer Stitcher_GetCompositingResol( Stitcher self, @@ -20667,6 +21206,24 @@ class CvNative { _Stitcher_GetCompositingResolPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetCompositingResol_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetCompositingResol_Async( + self, + callback, + ); + } + + late final _Stitcher_GetCompositingResol_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_1)>>('Stitcher_GetCompositingResol_Async'); + late final _Stitcher_GetCompositingResol_Async = + _Stitcher_GetCompositingResol_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_GetInterpolationFlags( Stitcher self, ffi.Pointer rval, @@ -20685,6 +21242,24 @@ class CvNative { _Stitcher_GetInterpolationFlagsPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetInterpolationFlags_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetInterpolationFlags_Async( + self, + callback, + ); + } + + late final _Stitcher_GetInterpolationFlags_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_1)>>('Stitcher_GetInterpolationFlags_Async'); + late final _Stitcher_GetInterpolationFlags_Async = + _Stitcher_GetInterpolationFlags_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_GetPanoConfidenceThresh( Stitcher self, ffi.Pointer rval, @@ -20703,6 +21278,24 @@ class CvNative { _Stitcher_GetPanoConfidenceThreshPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetPanoConfidenceThresh_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetPanoConfidenceThresh_Async( + self, + callback, + ); + } + + late final _Stitcher_GetPanoConfidenceThresh_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, + CvCallback_1)>>('Stitcher_GetPanoConfidenceThresh_Async'); + late final _Stitcher_GetPanoConfidenceThresh_Async = + _Stitcher_GetPanoConfidenceThresh_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_GetRegistrationResol( Stitcher self, ffi.Pointer rval, @@ -20721,6 +21314,24 @@ class CvNative { _Stitcher_GetRegistrationResolPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetRegistrationResol_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetRegistrationResol_Async( + self, + callback, + ); + } + + late final _Stitcher_GetRegistrationResol_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_1)>>('Stitcher_GetRegistrationResol_Async'); + late final _Stitcher_GetRegistrationResol_Async = + _Stitcher_GetRegistrationResol_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_GetSeamEstimationResol( Stitcher self, ffi.Pointer rval, @@ -20739,6 +21350,24 @@ class CvNative { _Stitcher_GetSeamEstimationResolPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetSeamEstimationResol_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetSeamEstimationResol_Async( + self, + callback, + ); + } + + late final _Stitcher_GetSeamEstimationResol_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, + CvCallback_1)>>('Stitcher_GetSeamEstimationResol_Async'); + late final _Stitcher_GetSeamEstimationResol_Async = + _Stitcher_GetSeamEstimationResol_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_GetWaveCorrectKind( Stitcher self, ffi.Pointer rval, @@ -20757,6 +21386,24 @@ class CvNative { _Stitcher_GetWaveCorrectKindPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetWaveCorrectKind_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetWaveCorrectKind_Async( + self, + callback, + ); + } + + late final _Stitcher_GetWaveCorrectKind_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_1)>>('Stitcher_GetWaveCorrectKind_Async'); + late final _Stitcher_GetWaveCorrectKind_Async = + _Stitcher_GetWaveCorrectKind_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_GetWaveCorrection( Stitcher self, ffi.Pointer rval, @@ -20775,6 +21422,24 @@ class CvNative { _Stitcher_GetWaveCorrectionPtr.asFunction< ffi.Pointer Function(Stitcher, ffi.Pointer)>(); + ffi.Pointer Stitcher_GetWaveCorrection_Async( + Stitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_GetWaveCorrection_Async( + self, + callback, + ); + } + + late final _Stitcher_GetWaveCorrection_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, CvCallback_1)>>('Stitcher_GetWaveCorrection_Async'); + late final _Stitcher_GetWaveCorrection_Async = + _Stitcher_GetWaveCorrection_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_SetCompositingResol( Stitcher self, double inval, @@ -20792,6 +21457,26 @@ class CvNative { late final _Stitcher_SetCompositingResol = _Stitcher_SetCompositingResolPtr .asFunction Function(Stitcher, double)>(); + ffi.Pointer Stitcher_SetCompositingResol_Async( + Stitcher self, + double inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetCompositingResol_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetCompositingResol_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Double, + CvCallback_0)>>('Stitcher_SetCompositingResol_Async'); + late final _Stitcher_SetCompositingResol_Async = + _Stitcher_SetCompositingResol_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, double, CvCallback_0)>(); + ffi.Pointer Stitcher_SetInterpolationFlags( Stitcher self, int inval, @@ -20810,6 +21495,26 @@ class CvNative { _Stitcher_SetInterpolationFlagsPtr.asFunction< ffi.Pointer Function(Stitcher, int)>(); + ffi.Pointer Stitcher_SetInterpolationFlags_Async( + Stitcher self, + int inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetInterpolationFlags_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetInterpolationFlags_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Int, + CvCallback_0)>>('Stitcher_SetInterpolationFlags_Async'); + late final _Stitcher_SetInterpolationFlags_Async = + _Stitcher_SetInterpolationFlags_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, int, CvCallback_0)>(); + ffi.Pointer Stitcher_SetPanoConfidenceThresh( Stitcher self, double inval, @@ -20828,6 +21533,26 @@ class CvNative { _Stitcher_SetPanoConfidenceThreshPtr.asFunction< ffi.Pointer Function(Stitcher, double)>(); + ffi.Pointer Stitcher_SetPanoConfidenceThresh_Async( + Stitcher self, + double inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetPanoConfidenceThresh_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetPanoConfidenceThresh_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Double, + CvCallback_0)>>('Stitcher_SetPanoConfidenceThresh_Async'); + late final _Stitcher_SetPanoConfidenceThresh_Async = + _Stitcher_SetPanoConfidenceThresh_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, double, CvCallback_0)>(); + ffi.Pointer Stitcher_SetRegistrationResol( Stitcher self, double inval, @@ -20845,6 +21570,26 @@ class CvNative { late final _Stitcher_SetRegistrationResol = _Stitcher_SetRegistrationResolPtr .asFunction Function(Stitcher, double)>(); + ffi.Pointer Stitcher_SetRegistrationResol_Async( + Stitcher self, + double inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetRegistrationResol_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetRegistrationResol_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Double, + CvCallback_0)>>('Stitcher_SetRegistrationResol_Async'); + late final _Stitcher_SetRegistrationResol_Async = + _Stitcher_SetRegistrationResol_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, double, CvCallback_0)>(); + ffi.Pointer Stitcher_SetSeamEstimationResol( Stitcher self, double inval, @@ -20863,6 +21608,26 @@ class CvNative { _Stitcher_SetSeamEstimationResolPtr.asFunction< ffi.Pointer Function(Stitcher, double)>(); + ffi.Pointer Stitcher_SetSeamEstimationResol_Async( + Stitcher self, + double inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetSeamEstimationResol_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetSeamEstimationResol_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Double, + CvCallback_0)>>('Stitcher_SetSeamEstimationResol_Async'); + late final _Stitcher_SetSeamEstimationResol_Async = + _Stitcher_SetSeamEstimationResol_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, double, CvCallback_0)>(); + ffi.Pointer Stitcher_SetWaveCorrectKind( Stitcher self, int inval, @@ -20880,6 +21645,26 @@ class CvNative { late final _Stitcher_SetWaveCorrectKind = _Stitcher_SetWaveCorrectKindPtr .asFunction Function(Stitcher, int)>(); + ffi.Pointer Stitcher_SetWaveCorrectKind_Async( + Stitcher self, + int inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetWaveCorrectKind_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetWaveCorrectKind_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Int, + CvCallback_0)>>('Stitcher_SetWaveCorrectKind_Async'); + late final _Stitcher_SetWaveCorrectKind_Async = + _Stitcher_SetWaveCorrectKind_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, int, CvCallback_0)>(); + ffi.Pointer Stitcher_SetWaveCorrection( Stitcher self, bool inval, @@ -20897,6 +21682,26 @@ class CvNative { late final _Stitcher_SetWaveCorrection = _Stitcher_SetWaveCorrectionPtr .asFunction Function(Stitcher, bool)>(); + ffi.Pointer Stitcher_SetWaveCorrection_Async( + Stitcher self, + bool inval, + CvCallback_0 callback, + ) { + return _Stitcher_SetWaveCorrection_Async( + self, + inval, + callback, + ); + } + + late final _Stitcher_SetWaveCorrection_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, ffi.Bool, + CvCallback_0)>>('Stitcher_SetWaveCorrection_Async'); + late final _Stitcher_SetWaveCorrection_Async = + _Stitcher_SetWaveCorrection_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, bool, CvCallback_0)>(); + ffi.Pointer Stitcher_Stitch( Stitcher self, VecMat mats, @@ -20943,6 +21748,46 @@ class CvNative { ffi.Pointer Function( Stitcher, VecMat, VecMat, Mat, ffi.Pointer)>(); + ffi.Pointer Stitcher_Stitch_1_Async( + Stitcher self, + VecMat mats, + VecMat masks, + CvCallback_2 callback, + ) { + return _Stitcher_Stitch_1_Async( + self, + mats, + masks, + callback, + ); + } + + late final _Stitcher_Stitch_1_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, VecMat, VecMat, + CvCallback_2)>>('Stitcher_Stitch_1_Async'); + late final _Stitcher_Stitch_1_Async = _Stitcher_Stitch_1_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, VecMat, VecMat, CvCallback_2)>(); + + ffi.Pointer Stitcher_Stitch_Async( + Stitcher self, + VecMat mats, + CvCallback_2 callback, + ) { + return _Stitcher_Stitch_Async( + self, + mats, + callback, + ); + } + + late final _Stitcher_Stitch_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, VecMat, CvCallback_2)>>('Stitcher_Stitch_Async'); + late final _Stitcher_Stitch_Async = _Stitcher_Stitch_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, VecMat, CvCallback_2)>(); + ffi.Pointer Stylization( Mat src, Mat dst, @@ -20964,6 +21809,27 @@ class CvNative { late final _Stylization = _StylizationPtr.asFunction< ffi.Pointer Function(Mat, Mat, double, double)>(); + ffi.Pointer Stylization_Async( + Mat src, + double sigma_s, + double sigma_r, + CvCallback_1 callback, + ) { + return _Stylization_Async( + src, + sigma_s, + sigma_r, + callback, + ); + } + + late final _Stylization_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Mat, ffi.Float, ffi.Float, CvCallback_1)>>('Stylization_Async'); + late final _Stylization_Async = _Stylization_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, double, double, CvCallback_1)>(); + void Subdiv2D_Close( Subdiv2DPtr self, ) { @@ -21738,6 +22604,32 @@ class CvNative { late final _TextureFlattening = _TextureFlatteningPtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double, int)>(); + ffi.Pointer TextureFlattening_Async( + Mat src, + Mat mask, + double low_threshold, + double high_threshold, + int kernel_size, + CvCallback_1 callback, + ) { + return _TextureFlattening_Async( + src, + mask, + low_threshold, + high_threshold, + kernel_size, + callback, + ); + } + + late final _TextureFlattening_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, + ffi.Int, CvCallback_1)>>('TextureFlattening_Async'); + late final _TextureFlattening_Async = _TextureFlattening_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, double, double, int, CvCallback_1)>(); + ffi.Pointer TheRNG( ffi.Pointer rval, ) { @@ -29033,14 +29925,9 @@ class _SymbolAddresses { get SIFT_Close_Async => _library._SIFT_Close_AsyncPtr; ffi.Pointer> get SimpleBlobDetector_Close => _library._SimpleBlobDetector_ClosePtr; - ffi.Pointer< - ffi.NativeFunction< - ffi.Pointer Function( - SimpleBlobDetectorPtr, CvCallback_0)>> - get SimpleBlobDetector_Close_Async => - _library._SimpleBlobDetector_Close_AsyncPtr; - ffi.Pointer> get Stitcher_Close => _library._Stitcher_ClosePtr; + ffi.Pointer> + get Stitcher_Close_Async => _library._Stitcher_Close_AsyncPtr; ffi.Pointer> get Subdiv2D_Close => _library._Subdiv2D_ClosePtr; ffi.Pointer> @@ -29562,12 +30449,6 @@ final class Prim extends ffi.Struct { external ffi.Pointer ptr; } -final class PtrStitcher extends ffi.Struct { - external ffi.Pointer> ptr; -} - -typedef PtrStitcherPtr = ffi.Pointer; - final class QRCodeDetector extends ffi.Struct { external ffi.Pointer ptr; } @@ -29731,9 +30612,11 @@ final class Size2f extends ffi.Struct { } final class Stitcher extends ffi.Struct { - external ffi.Pointer ptr; + external ffi.Pointer> ptr; } +typedef StitcherPtr = ffi.Pointer; + final class Subdiv2D extends ffi.Struct { external ffi.Pointer ptr; } diff --git a/lib/src/photo/photo.dart b/lib/src/photo/photo.dart index aefb95bf..cd5af23f 100644 --- a/lib/src/photo/photo.dart +++ b/lib/src/photo/photo.dart @@ -22,7 +22,11 @@ class MergeMertens extends CvStruct { finalizer.attach(this, ptr.cast(), detach: this); } } - + factory MergeMertens.fromPointer( + cvg.MergeMertensPtr ptr, [ + bool attach = true, + ]) => + MergeMertens._(ptr.cast(), attach); factory MergeMertens.empty() { final p = calloc(); cvRun(() => CFFI.MergeMertens_Create(p)); @@ -36,7 +40,12 @@ class MergeMertens extends CvStruct { }) { final p = calloc(); cvRun( - () => CFFI.MergeMertens_CreateWithParams(contrastWeight, saturationWeight, exposureWeight, p), + () => CFFI.MergeMertens_CreateWithParams( + contrastWeight, + saturationWeight, + exposureWeight, + p, + ), ); return MergeMertens._(p); } @@ -79,6 +88,11 @@ class AlignMTB extends CvStruct { finalizer.attach(this, ptr.cast(), detach: this); } } + factory AlignMTB.fromPointer( + cvg.AlignMTBPtr ptr, [ + bool attach = true, + ]) => + AlignMTB._(ptr.cast(), attach); /// AlignMTB for converts images to median threshold bitmaps. /// of type AlignMTB converts images to median threshold bitmaps (1 for pixels @@ -102,7 +116,11 @@ class AlignMTB extends CvStruct { /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html /// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga2f1fafc885a5d79dbfb3542e08db0244 - factory AlignMTB.create({int maxBits = 6, int excludeRange = 4, bool cut = true}) { + factory AlignMTB.create({ + int maxBits = 6, + int excludeRange = 4, + bool cut = true, + }) { final p = calloc(); cvRun(() => CFFI.AlignMTB_CreateWithParams(maxBits, excludeRange, cut, p)); return AlignMTB._(p); @@ -140,7 +158,9 @@ Mat colorChange( double blueMul = 1.0, }) { final dst = Mat.empty(); - cvRun(() => CFFI.ColorChange(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul)); + cvRun( + () => CFFI.ColorChange(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul), + ); return dst; } @@ -148,9 +168,17 @@ Mat colorChange( // /// For further details, please see: /// https://docs.opencv.org/master/df/da0/group__photo__clone.html#ga2bf426e4c93a6b1f21705513dfeca49d -Mat seamlessClone(InputArray src, InputArray dst, InputArray mask, Point p, int flags) { +Mat seamlessClone( + InputArray src, + InputArray dst, + InputArray mask, + Point p, + int flags, +) { final blend = Mat.empty(); - cvRun(() => CFFI.SeamlessClone(src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags)); + cvRun( + () => CFFI.SeamlessClone(src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags), + ); return blend; } @@ -181,7 +209,16 @@ Mat textureFlattening( int kernelSize = 3, }) { final dst = Mat.empty(); - cvRun(() => CFFI.TextureFlattening(src.ref, mask.ref, dst.ref, lowThreshold, highThreshold, kernelSize)); + cvRun( + () => CFFI.TextureFlattening( + src.ref, + mask.ref, + dst.ref, + lowThreshold, + highThreshold, + kernelSize, + ), + ); return dst; } @@ -285,7 +322,9 @@ Mat edgePreservingFilter( double sigmaR = 0.4, }) { final dst = Mat.empty(); - cvRun(() => CFFI.EdgePreservingFilter(src.ref, dst.ref, flags, sigmaS, sigmaR)); + cvRun( + () => CFFI.EdgePreservingFilter(src.ref, dst.ref, flags, sigmaS, sigmaR), + ); return dst; } @@ -301,7 +340,16 @@ Mat edgePreservingFilter( }) { final dst1 = Mat.empty(); final dst2 = Mat.empty(); - cvRun(() => CFFI.PencilSketch(src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor)); + cvRun( + () => CFFI.PencilSketch( + src.ref, + dst1.ref, + dst2.ref, + sigmaS, + sigmaR, + shadeFactor, + ), + ); return (dst1, dst2); } @@ -328,8 +376,21 @@ Mat stylization( // /// For further details, please see: /// https://docs.opencv.org/4.x/d7/d8b/group__photo__inpaint.html#gaedd30dfa0214fec4c88138b51d678085 -Mat inpaint(InputArray src, InputArray inpaintMask, double inpaintRadius, int flags) { +Mat inpaint( + InputArray src, + InputArray inpaintMask, + double inpaintRadius, + int flags, +) { final dst = Mat.empty(); - cvRun(() => CFFI.PhotoInpaint(src.ref, inpaintMask.ref, dst.ref, inpaintRadius, flags)); + cvRun( + () => CFFI.PhotoInpaint( + src.ref, + inpaintMask.ref, + dst.ref, + inpaintRadius, + flags, + ), + ); return dst; } diff --git a/lib/src/photo/photo_async.dart b/lib/src/photo/photo_async.dart new file mode 100644 index 00000000..c343118d --- /dev/null +++ b/lib/src/photo/photo_async.dart @@ -0,0 +1,295 @@ +library cv; + +import '../core/base.dart'; +import '../core/mat.dart'; +import '../core/point.dart'; +import '../opencv.g.dart' as cvg; +import './photo.dart'; + +extension MergeMertensAsync on MergeMertens { + static Future emptyNewAsync() async => cvRunAsync( + CFFI.MergeMertens_Create_Async, + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), + ); + + static Future createAsync({ + double contrastWeight = 1.0, + double saturationWeight = 1.0, + double exposureWeight = 0.0, + }) async { + return cvRunAsync( + (callback) => CFFI.MergeMertens_CreateWithParams_Async( + contrastWeight, + saturationWeight, + exposureWeight, + callback, + ), + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), + ); + } + + Future processAsync(VecMat src) async { + return cvRunAsync( + (callback) => CFFI.MergeMertens_Process_Async(ref, src.ref, callback), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); + } +} + +extension AlignMTBAsync on AlignMTB { + static Future emptyNewAsync() async => cvRunAsync( + CFFI.AlignMTB_Create_Async, + (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), + ); + + static Future createAsync({ + int maxBits = 6, + int excludeRange = 4, + bool cut = true, + }) async { + return cvRunAsync( + (callback) => CFFI.AlignMTB_CreateWithParams_Async( + maxBits, + excludeRange, + cut, + callback, + ), + (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), + ); + } + + Future processAsync(VecMat src) async { + return cvRunAsync( + (callback) => CFFI.AlignMTB_Process_Async(ref, src.ref, callback), + (c, pdst) => c.complete(VecMat.fromPointer(pdst.cast())), + ); + } +} + +Future colorChangeAsync( + InputArray src, + InputArray mask, { + double redMul = 1.0, + double greenMul = 1.0, + double blueMul = 1.0, +}) async { + return cvRunAsync( + (callback) => CFFI.ColorChange_Async( + src.ref, + mask.ref, + redMul, + greenMul, + blueMul, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future seamlessCloneAsync( + InputArray src, + InputArray dst, + InputArray mask, + Point p, + int flags, +) async { + return cvRunAsync( + (callback) => CFFI.SeamlessClone_Async( + src.ref, + dst.ref, + mask.ref, + p.ref, + flags, + callback, + ), + matCompleter, + ); +} + +Future illuminationChangeAsync( + InputArray src, + InputArray mask, { + double alpha = 0.2, + double beta = 0.4, +}) async { + return cvRunAsync( + (callback) => CFFI.IlluminationChange_Async( + src.ref, + mask.ref, + alpha, + beta, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future textureFlatteningAsync( + InputArray src, + InputArray mask, { + double lowThreshold = 30, + double highThreshold = 45, + int kernelSize = 3, +}) async { + return cvRunAsync( + (callback) => CFFI.TextureFlattening_Async( + src.ref, + mask.ref, + lowThreshold, + highThreshold, + kernelSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future fastNlMeansDenoisingAsync( + InputArray src, { + double h = 3, + int templateWindowSize = 7, + int searchWindowSize = 21, +}) async { + return cvRunAsync( + (callback) => CFFI.FastNlMeansDenoisingWithParams_Async( + src.ref, + h, + templateWindowSize, + searchWindowSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future fastNlMeansDenoisingColoredAsync( + InputArray src, { + double h = 3, + double hColor = 3, + int templateWindowSize = 7, + int searchWindowSize = 21, +}) async { + return cvRunAsync( + (callback) => CFFI.FastNlMeansDenoisingColoredWithParams_Async( + src.ref, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future fastNlMeansDenoisingColoredMultiAsync( + VecMat srcImgs, + int imgToDenoiseIndex, + int temporalWindowSize, { + double h = 3, + double hColor = 3, + int templateWindowSize = 7, + int searchWindowSize = 21, +}) async { + return cvRunAsync( + (callback) => CFFI.FastNlMeansDenoisingColoredMultiWithParams_Async( + srcImgs.ref, + imgToDenoiseIndex, + temporalWindowSize, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future detailEnhanceAsync( + InputArray src, { + double sigmaS = 10, + double sigmaR = 0.15, +}) async { + return cvRunAsync( + (callback) => CFFI.DetailEnhance_Async( + src.ref, + sigmaS, + sigmaR, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future edgePreservingFilterAsync( + InputArray src, { + int flags = 1, + double sigmaS = 60, + double sigmaR = 0.4, +}) async { + return cvRunAsync( + (callback) => CFFI.EdgePreservingFilter_Async( + src.ref, + flags, + sigmaS, + sigmaR, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future<(Mat dst1, Mat dst2)> pencilSketchAsync( + InputArray src, { + double sigmaS = 60, + double sigmaR = 0.07, + double shadeFactor = 0.02, +}) async { + return cvRunAsync2( + (callback) => CFFI.PencilSketch_Async( + src.ref, + sigmaS, + sigmaR, + shadeFactor, + callback, + ), + (c, pdst1, pdst2) => c.complete( + (Mat.fromPointer(pdst1.cast()), Mat.fromPointer(pdst2.cast())), + ), + ); +} + +Future stylizationAsync( + InputArray src, { + double sigmaS = 60, + double sigmaR = 0.45, +}) async { + return cvRunAsync( + (callback) => CFFI.Stylization_Async( + src.ref, + sigmaS, + sigmaR, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} + +Future inpaintAsync( + InputArray src, + InputArray inpaintMask, + double inpaintRadius, + int flags, +) async { + return cvRunAsync( + (callback) => CFFI.PhotoInpaint_Async( + src.ref, + inpaintMask.ref, + inpaintRadius, + flags, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); +} diff --git a/lib/src/stitching/stitching.dart b/lib/src/stitching/stitching.dart index 8ccf16de..9ecef6ac 100644 --- a/lib/src/stitching/stitching.dart +++ b/lib/src/stitching/stitching.dart @@ -18,23 +18,18 @@ import '../opencv.g.dart' as cvg; /// stability and quality of the final images at least being familiar /// with the theory is recommended. /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#details -class Stitcher extends CvStruct { - Stitcher._(cvg.PtrStitcherPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { +class Stitcher extends CvStruct { + Stitcher._(cvg.StitcherPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { if (attach) { finalizer.attach(this, ptr.cast(), detach: this); } } - - cvg.Stitcher get stitcher { - final s = calloc(); - cvRun(() => CFFI.Stitcher_Get(ptr.ref, s)); - return s.ref; - } + factory Stitcher.fromPointer(cvg.StitcherPtr ptr, [bool attach = true]) => Stitcher._(ptr.cast(), attach); /// Creates a Stitcher configured in one of the stitching modes. /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a308a47865a1f381e4429c8ec5e99549f factory Stitcher.create({StitcherMode mode = StitcherMode.PANORAMA}) { - final ptr_ = calloc(); + final ptr_ = calloc(); cvRun(() => CFFI.Stitcher_Create(mode.index, ptr_)); return Stitcher._(ptr_); } @@ -43,98 +38,98 @@ class Stitcher extends CvStruct { double get registrationResol { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetRegistrationResol(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetRegistrationResol(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a9912fe8c095b8385267908e5ef707439 set registrationResol(double value) { - cvRun(() => CFFI.Stitcher_SetRegistrationResol(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetRegistrationResol(ref, value)); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#ac559c3eb228614f9402ff3eba23a08f5 double get seamEstimationResol { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetSeamEstimationResol(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetSeamEstimationResol(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#ad0fcef52b2fedda1dbb90ea780cd7979 set seamEstimationResol(double value) { - cvRun(() => CFFI.Stitcher_SetSeamEstimationResol(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetSeamEstimationResol(ref, value)); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#ad13d2d50b253e471fbaf041b9a044571 double get compositingResol { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetCompositingResol(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetCompositingResol(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#afe927e80fcb2ca2061630ddd98eebba8 set compositingResol(double value) { - cvRun(() => CFFI.Stitcher_SetCompositingResol(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetCompositingResol(ref, value)); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a3755bbeca7f4c80dc42af034f7621568 double get panoConfidenceThresh { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetPanoConfidenceThresh(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetPanoConfidenceThresh(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a6f5e62bc1dd5d7bdb5f9313a2c21c558 set panoConfidenceThresh(double value) { - cvRun(() => CFFI.Stitcher_SetPanoConfidenceThresh(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetPanoConfidenceThresh(ref, value)); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#af6a51e0b23dac119a3612d57345f9a7f bool get waveCorrection { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetWaveCorrection(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetWaveCorrection(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a968a2f4a1faddfdacbcfce54b44bab70 set waveCorrection(bool value) { - cvRun(() => CFFI.Stitcher_SetWaveCorrection(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetWaveCorrection(ref, value)); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#abc0c8f54a1d223a1098206654813d973 int get interpolationFlags { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetInterpolationFlags(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetInterpolationFlags(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a253d04b8dcd3c674321b29139c769873 set interpolationFlags(int value) { - cvRun(() => CFFI.Stitcher_SetInterpolationFlags(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetInterpolationFlags(ref, value)); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#ad9c9c9b8a97b686ad3b93f7918c4c6de int get waveCorrectKind { return using((arena) { final rptr = arena(); - cvRun(() => CFFI.Stitcher_GetWaveCorrectKind(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_GetWaveCorrectKind(ref, rptr)); return rptr.value; }); } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a17413f5c06e4e569bfd45e01d4e8ff4a set waveCorrectKind(int value) { - cvRun(() => CFFI.Stitcher_SetWaveCorrectKind(stitcher, value)); + cvRun(() => CFFI.Stitcher_SetWaveCorrectKind(ref, value)); } /// These functions try to match the given images and to estimate rotations of each camera. @@ -143,7 +138,7 @@ class Stitcher extends CvStruct { return using((arena) { final rptr = arena(); masks ??= VecMat.fromList([]); - cvRun(() => CFFI.Stitcher_EstimateTransform(stitcher, images.ref, masks!.ref, rptr)); + cvRun(() => CFFI.Stitcher_EstimateTransform(ref, images.ref, masks!.ref, rptr)); return StitcherStatus.fromInt(rptr.value); }); } @@ -157,8 +152,8 @@ class Stitcher extends CvStruct { final rptr = arena(); final rpano = Mat.empty(); images == null - ? cvRun(() => CFFI.Stitcher_ComposePanorama(stitcher, rpano.ref, rptr)) - : cvRun(() => CFFI.Stitcher_ComposePanorama_1(stitcher, images.ref, rpano.ref, rptr)); + ? cvRun(() => CFFI.Stitcher_ComposePanorama(ref, rpano.ref, rptr)) + : cvRun(() => CFFI.Stitcher_ComposePanorama_1(ref, images.ref, rpano.ref, rptr)); return (StitcherStatus.fromInt(rptr.value), rpano); }); } @@ -171,8 +166,8 @@ class Stitcher extends CvStruct { final rptr = arena(); final rpano = Mat.empty(); masks == null - ? cvRun(() => CFFI.Stitcher_Stitch(stitcher, images.ref, rpano.ref, rptr)) - : cvRun(() => CFFI.Stitcher_Stitch_1(stitcher, images.ref, masks.ref, rpano.ref, rptr)); + ? cvRun(() => CFFI.Stitcher_Stitch(ref, images.ref, rpano.ref, rptr)) + : cvRun(() => CFFI.Stitcher_Stitch_1(ref, images.ref, masks.ref, rpano.ref, rptr)); return (StitcherStatus.fromInt(rptr.value), rpano); }); } @@ -180,11 +175,11 @@ class Stitcher extends CvStruct { /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a7fed80561a9b46a1a924ac6cb334ac85 VecInt get component { final rptr = calloc(); - cvRun(() => CFFI.Stitcher_Component(stitcher, rptr)); + cvRun(() => CFFI.Stitcher_Component(ref, rptr)); return VecInt.fromPointer(rptr); } - static final finalizer = OcvFinalizer(CFFI.addresses.Stitcher_Close); + static final finalizer = OcvFinalizer(CFFI.addresses.Stitcher_Close); void dispose() { finalizer.detach(this); @@ -195,7 +190,7 @@ class Stitcher extends CvStruct { List get props => [ptr.address]; @override - cvg.PtrStitcher get ref => ptr.ref; + cvg.Stitcher get ref => ptr.ref; } /// https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html#a507409ce9435dd89857469d12ec06b45 diff --git a/lib/src/stitching/stitching_async.dart b/lib/src/stitching/stitching_async.dart new file mode 100644 index 00000000..42ccdf78 --- /dev/null +++ b/lib/src/stitching/stitching_async.dart @@ -0,0 +1,176 @@ +library cv; + +import 'dart:ffi' as ffi; +import 'package:ffi/ffi.dart'; + +import '../core/base.dart'; +import '../core/mat.dart'; +import '../core/vec.dart'; +import '../opencv.g.dart' as cvg; +import './stitching.dart'; + +extension StitcherAsync on Stitcher { + static Future createAsync({ + StitcherMode mode = StitcherMode.PANORAMA, + }) async => + cvRunAsync( + (callback) => CFFI.Stitcher_Create_Async(mode.index, callback), + (c, p) => c.complete(Stitcher.fromPointer(p.cast())), + ); + + Future getRegistrationResolAsync() async => cvRunAsync( + (callback) => CFFI.Stitcher_GetRegistrationResol_Async(ref, callback), + doubleCompleter, + ); + + Future setRegistrationResolAsync(double value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetRegistrationResol_Async(ref, value, callback), + (c) => c.complete(), + ); + + Future getSeamEstimationResolAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetSeamEstimationResol_Async(ref, callback), + doubleCompleter, + ); + } + + Future setSeamEstimationResolAsync(double value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetSeamEstimationResol_Async(ref, value, callback), + (c) => c.complete(), + ); + + Future getCompositingResolAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetCompositingResol_Async(ref, callback), + doubleCompleter, + ); + } + + Future setCompositingResolAsync(double value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetCompositingResol_Async(ref, value, callback), + (c) => c.complete(), + ); + + Future getPanoConfidenceThreshAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetPanoConfidenceThresh_Async(ref, callback), + doubleCompleter, + ); + } + + Future setPanoConfidenceThreshAsync(double value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetPanoConfidenceThresh_Async( + ref, + value, + callback, + ), + (c) => c.complete(), + ); + + Future getWaveCorrectionAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetWaveCorrection_Async(ref, callback), + boolCompleter, + ); + } + + Future setWaveCorrectionAsync(bool value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetWaveCorrection_Async(ref, value, callback), + (c) => c.complete(), + ); + + Future getInterpolationFlagsAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetInterpolationFlags_Async(ref, callback), + intCompleter, + ); + } + + Future setInterpolationFlagsAsync(int value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetInterpolationFlags_Async(ref, value, callback), + (c) => c.complete(), + ); + + Future getWaveCorrectKindAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetWaveCorrectKind_Async(ref, callback), + intCompleter, + ); + } + + Future setWaveCorrectKindAsync(int value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetWaveCorrectKind_Async(ref, value, callback), + (c) => c.complete(), + ); + + Future estimateTransformAsync( + VecMat images, { + VecMat? masks, + }) async { + masks ??= VecMat.fromList([]); + return cvRunAsync( + (callback) => CFFI.Stitcher_EstimateTransform_Async( + ref, + images.ref, + masks!.ref, + callback, + ), (c, p) { + final value = p.cast().value; + calloc.free(p); + return c.complete(StitcherStatus.fromInt(value)); + }); + } + + Future<(StitcherStatus, Mat)> composePanoramaAsync({VecMat? images}) async { + return cvRunAsync2( + (callback) => images == null + ? CFFI.Stitcher_ComposePanorama_Async( + ref, + callback, + ) + : CFFI.Stitcher_ComposePanorama_1_Async( + ref, + images.ref, + callback, + ), (c, status, pano) { + final value = status.cast().value; + calloc.free(status); + return c.complete( + (StitcherStatus.fromInt(value), Mat.fromPointer(pano.cast())), + ); + }); + } + + Future<(StitcherStatus, Mat)> stitchAsync( + VecMat images, { + VecMat? masks, + }) async { + return cvRunAsync2( + (callback) => masks == null + ? CFFI.Stitcher_Stitch_Async( + ref, + images.ref, + callback, + ) + : CFFI.Stitcher_Stitch_1_Async( + ref, + images.ref, + masks.ref, + callback, + ), (c, status, pano) { + final value = status.cast().value; + calloc.free(status); + return c.complete( + (StitcherStatus.fromInt(value), Mat.fromPointer(pano.cast())), + ); + }); + } + + Future getComponentAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_Component_Async(ref, callback), + (c, p) => c.complete(VecInt.fromPointer(p.cast())), + ); + } +} diff --git a/src/photo/photo_async.cpp b/src/photo/photo_async.cpp new file mode 100644 index 00000000..55a8cad5 --- /dev/null +++ b/src/photo/photo_async.cpp @@ -0,0 +1,198 @@ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ +#include "photo_async.h" +#include "core/types.h" + +// Asynchronous functions for ColorChange +CvStatus *ColorChange_Async(Mat src, Mat mask, float red_mul, float green_mul, float blue_mul, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::colorChange(*src.ptr, *mask.ptr, _dst, red_mul, green_mul, blue_mul); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for SeamlessClone +CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, int flags, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _blend; + cv::seamlessClone(*src.ptr, *dst.ptr, *mask.ptr, cv::Point(p.x, p.y), _blend, flags); + callback(new Mat{new cv::Mat(_blend)}); + END_WRAP +} + +// Asynchronous functions for IlluminationChange +CvStatus *IlluminationChange_Async(Mat src, Mat mask, float alpha, float beta, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::illuminationChange(*src.ptr, *mask.ptr, _dst, alpha, beta); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for TextureFlattening +CvStatus *TextureFlattening_Async(Mat src, Mat mask, float low_threshold, float high_threshold, int kernel_size, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::textureFlattening(*src.ptr, *mask.ptr, _dst, low_threshold, high_threshold, kernel_size); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for FastNlMeansDenoisingColoredMulti +CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::fastNlMeansDenoisingColoredMulti(*src.ptr, _dst, imgToDenoiseIndex, temporalWindowSize); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::fastNlMeansDenoisingColoredMulti(*src.ptr, _dst, imgToDenoiseIndex, temporalWindowSize, h, hColor, templateWindowSize, searchWindowSize); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for FastNlMeansDenoising +CvStatus *FastNlMeansDenoising_Async(Mat src, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::fastNlMeansDenoising(*src.ptr, _dst); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, float h, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::fastNlMeansDenoising(*src.ptr, _dst, h, templateWindowSize, searchWindowSize); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for FastNlMeansDenoisingColored +CvStatus *FastNlMeansDenoisingColored_Async(Mat src, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::fastNlMeansDenoisingColored(*src.ptr, _dst); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::fastNlMeansDenoisingColored(*src.ptr, _dst, h, hColor, templateWindowSize, searchWindowSize); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for MergeMertens +CvStatus *MergeMertens_Create_Async(CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new MergeMertens{new cv::Ptr(cv::createMergeMertens())}); + END_WRAP +} + +CvStatus *MergeMertens_CreateWithParams_Async(float contrast_weight, float saturation_weight, float exposure_weight, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new MergeMertens{new cv::Ptr(cv::createMergeMertens(contrast_weight, saturation_weight, exposure_weight))}); + END_WRAP +} + +CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + (*b.ptr)->process(*src.ptr, _dst); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for AlignMTB +CvStatus *AlignMTB_Create_Async(CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new AlignMTB{new cv::Ptr(cv::createAlignMTB())}); + END_WRAP +} + +CvStatus *AlignMTB_CreateWithParams_Async(int max_bits, int exclude_range, bool cut, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new AlignMTB{new cv::Ptr(cv::createAlignMTB(max_bits, exclude_range, cut))}); + END_WRAP +} + +CvStatus *AlignMTB_Process_Async(AlignMTB b, VecMat src, CvCallback_1 callback) +{ + BEGIN_WRAP + auto vec = std::vector(); + (*b.ptr)->process(*src.ptr, vec); + callback(new VecMat{new std::vector(vec)}); + END_WRAP +} + +// Asynchronous functions for DetailEnhance +CvStatus *DetailEnhance_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::detailEnhance(*src.ptr, _dst, sigma_s, sigma_r); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for EdgePreservingFilter +CvStatus *EdgePreservingFilter_Async(Mat src, int filter, float sigma_s, float sigma_r, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::edgePreservingFilter(*src.ptr, _dst, filter, sigma_s, sigma_r); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for PencilSketch +CvStatus *PencilSketch_Async(Mat src, float sigma_s, float sigma_r, float shade_factor, CvCallback_2 callback) +{ + BEGIN_WRAP + cv::Mat _dst1, _dst2; + cv::pencilSketch(*src.ptr, _dst1, _dst2, sigma_s, sigma_r, shade_factor); + callback(new Mat{new cv::Mat(_dst1)}, new Mat{new cv::Mat(_dst2)}); + END_WRAP +} + +// Asynchronous functions for Stylization +CvStatus *Stylization_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::stylization(*src.ptr, _dst, sigma_s, sigma_r); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} + +// Asynchronous functions for PhotoInpaint +CvStatus *PhotoInpaint_Async(Mat src, Mat mask, float inpaint_radius, int algorithm_type, CvCallback_1 callback) +{ + BEGIN_WRAP + cv::Mat _dst; + cv::inpaint(*src.ptr, *mask.ptr, _dst, inpaint_radius, algorithm_type); + callback(new Mat{new cv::Mat(_dst)}); + END_WRAP +} diff --git a/src/photo/photo_async.h b/src/photo/photo_async.h new file mode 100644 index 00000000..75d69187 --- /dev/null +++ b/src/photo/photo_async.h @@ -0,0 +1,67 @@ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ +#ifndef CVD_PHOTO_ASYNC_H_ +#define CVD_PHOTO_ASYNC_H_ + +#include "core/types.h" +#include "photo.h" + +#ifdef __cplusplus +#include +extern "C" +{ +#endif + + // Asynchronous functions for ColorChange + CvStatus *ColorChange_Async(Mat src, Mat mask, float red_mul, float green_mul, float blue_mul, CvCallback_1 callback); + + // Asynchronous functions for SeamlessClone + CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, int flags, CvCallback_1 callback); + + // Asynchronous functions for IlluminationChange + CvStatus *IlluminationChange_Async(Mat src, Mat mask, float alpha, float beta, CvCallback_1 callback); + + // Asynchronous functions for TextureFlattening + CvStatus *TextureFlattening_Async(Mat src, Mat mask, float low_threshold, float high_threshold, int kernel_size, CvCallback_1 callback); + + // Asynchronous functions for FastNlMeansDenoisingColoredMulti + CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_1 callback); + CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback); + + // Asynchronous functions for FastNlMeansDenoising + CvStatus *FastNlMeansDenoising_Async(Mat src, CvCallback_1 callback); + CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, float h, int templateWindowSize, int searchWindowSize, CvCallback_1 callback); + + // Asynchronous functions for FastNlMeansDenoisingColored + CvStatus *FastNlMeansDenoisingColored_Async(Mat src, CvCallback_1 callback); + CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback); + + // Asynchronous functions for MergeMertens + CvStatus *MergeMertens_Create_Async(CvCallback_1 callback); + CvStatus *MergeMertens_CreateWithParams_Async(float contrast_weight, float saturation_weight, float exposure_weight, CvCallback_1 callback); + CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, CvCallback_1 callback); + + // Asynchronous functions for AlignMTB + CvStatus *AlignMTB_Create_Async(CvCallback_1 callback); + CvStatus *AlignMTB_CreateWithParams_Async(int max_bits, int exclude_range, bool cut, CvCallback_1 callback); + CvStatus *AlignMTB_Process_Async(AlignMTB b, VecMat src, CvCallback_1 callback); + + // Asynchronous functions for DetailEnhance + CvStatus *DetailEnhance_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback); + + // Asynchronous functions for EdgePreservingFilter + CvStatus *EdgePreservingFilter_Async(Mat src, int filter, float sigma_s, float sigma_r, CvCallback_1 callback); + + // Asynchronous functions for PencilSketch + CvStatus *PencilSketch_Async(Mat src, float sigma_s, float sigma_r, float shade_factor, CvCallback_2 callback); + + // Asynchronous functions for Stylization + CvStatus *Stylization_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback); + + // Asynchronous functions for PhotoInpaint + CvStatus *PhotoInpaint_Async(Mat src, Mat mask, float inpaint_radius, int algorithm_type, CvCallback_1 callback); + +#ifdef __cplusplus +} +#endif + +#endif // CVD_PHOTO_ASYNC_H_ diff --git a/src/stitching/stitching.cpp b/src/stitching/stitching.cpp index 60fd047b..ad408f7b 100644 --- a/src/stitching/stitching.cpp +++ b/src/stitching/stitching.cpp @@ -5,7 +5,7 @@ #include "stitching.h" -CvStatus *Stitcher_Create(int mode, PtrStitcher *rval) +CvStatus *Stitcher_Create(int mode, Stitcher *rval) { BEGIN_WRAP const auto ptr = cv::Stitcher::create(static_cast(mode)); @@ -13,108 +13,101 @@ CvStatus *Stitcher_Create(int mode, PtrStitcher *rval) END_WRAP } -void Stitcher_Close(PtrStitcherPtr stitcher) +void Stitcher_Close(StitcherPtr stitcher) { stitcher->ptr->reset(); CVD_FREE(stitcher); } -CvStatus *Stitcher_Get(PtrStitcher self, Stitcher *rval) -{ - BEGIN_WRAP - *rval = {self.ptr->get()}; - END_WRAP -} - CvStatus *Stitcher_GetRegistrationResol(Stitcher self, double *rval) { BEGIN_WRAP - *rval = self.ptr->registrationResol(); + *rval = (*self.ptr)->registrationResol(); END_WRAP } CvStatus *Stitcher_SetRegistrationResol(Stitcher self, double inval) { BEGIN_WRAP - self.ptr->setRegistrationResol(inval); + (*self.ptr)->setRegistrationResol(inval); END_WRAP } CvStatus *Stitcher_GetSeamEstimationResol(Stitcher self, double *rval) { BEGIN_WRAP - *rval = self.ptr->seamEstimationResol(); + *rval = (*self.ptr)->seamEstimationResol(); END_WRAP } CvStatus *Stitcher_SetSeamEstimationResol(Stitcher self, double inval) { BEGIN_WRAP - self.ptr->setSeamEstimationResol(inval); + (*self.ptr)->setSeamEstimationResol(inval); END_WRAP } CvStatus *Stitcher_GetCompositingResol(Stitcher self, double *rval) { BEGIN_WRAP - *rval = self.ptr->compositingResol(); + *rval = (*self.ptr)->compositingResol(); END_WRAP } CvStatus *Stitcher_SetCompositingResol(Stitcher self, double inval) { BEGIN_WRAP - self.ptr->setCompositingResol(inval); + (*self.ptr)->setCompositingResol(inval); END_WRAP } CvStatus *Stitcher_GetPanoConfidenceThresh(Stitcher self, double *rval) { BEGIN_WRAP - *rval = self.ptr->panoConfidenceThresh(); + *rval = (*self.ptr)->panoConfidenceThresh(); END_WRAP } CvStatus *Stitcher_SetPanoConfidenceThresh(Stitcher self, double inval) { BEGIN_WRAP - self.ptr->setPanoConfidenceThresh(inval); + (*self.ptr)->setPanoConfidenceThresh(inval); END_WRAP } CvStatus *Stitcher_GetWaveCorrection(Stitcher self, bool *rval) { BEGIN_WRAP - *rval = self.ptr->waveCorrection(); + *rval = (*self.ptr)->waveCorrection(); END_WRAP } CvStatus *Stitcher_SetWaveCorrection(Stitcher self, bool inval) { BEGIN_WRAP - self.ptr->setWaveCorrection(inval); + (*self.ptr)->setWaveCorrection(inval); END_WRAP } CvStatus *Stitcher_GetInterpolationFlags(Stitcher self, int *rval) { BEGIN_WRAP - *rval = static_cast(self.ptr->interpolationFlags()); + *rval = static_cast((*self.ptr)->interpolationFlags()); END_WRAP } CvStatus *Stitcher_SetInterpolationFlags(Stitcher self, int inval) { BEGIN_WRAP - self.ptr->setInterpolationFlags(static_cast(inval)); + (*self.ptr)->setInterpolationFlags(static_cast(inval)); END_WRAP } CvStatus *Stitcher_GetWaveCorrectKind(Stitcher self, int *rval) { BEGIN_WRAP - *rval = static_cast(self.ptr->waveCorrectKind()); + *rval = static_cast((*self.ptr)->waveCorrectKind()); END_WRAP } CvStatus *Stitcher_SetWaveCorrectKind(Stitcher self, int inval) { BEGIN_WRAP - self.ptr->setWaveCorrectKind(static_cast(inval)); + (*self.ptr)->setWaveCorrectKind(static_cast(inval)); END_WRAP } @@ -122,42 +115,42 @@ CvStatus *Stitcher_EstimateTransform(Stitcher self, VecMat mats, VecMat masks, i { BEGIN_WRAP if (masks.ptr->size() > 0) { - *rval = static_cast(self.ptr->estimateTransform(*mats.ptr, *masks.ptr)); + *rval = static_cast((*self.ptr)->estimateTransform(*mats.ptr, *masks.ptr)); } else - *rval = static_cast(self.ptr->estimateTransform(*mats.ptr)); + *rval = static_cast((*self.ptr)->estimateTransform(*mats.ptr)); END_WRAP } CvStatus *Stitcher_ComposePanorama(Stitcher self, Mat rpano, int *rval) { BEGIN_WRAP - *rval = static_cast(self.ptr->composePanorama(*rpano.ptr)); + *rval = static_cast((*self.ptr)->composePanorama(*rpano.ptr)); END_WRAP } CvStatus *Stitcher_ComposePanorama_1(Stitcher self, VecMat mats, Mat rpano, int *rval) { BEGIN_WRAP - *rval = static_cast(self.ptr->composePanorama(*mats.ptr, *rpano.ptr)); + *rval = static_cast((*self.ptr)->composePanorama(*mats.ptr, *rpano.ptr)); END_WRAP } CvStatus *Stitcher_Stitch(Stitcher self, VecMat mats, Mat rpano, int *rval) { BEGIN_WRAP - *rval = static_cast(self.ptr->stitch(*mats.ptr, *rpano.ptr)); + *rval = static_cast((*self.ptr)->stitch(*mats.ptr, *rpano.ptr)); END_WRAP } CvStatus *Stitcher_Stitch_1(Stitcher self, VecMat mats, VecMat masks, Mat rpano, int *rval) { BEGIN_WRAP - *rval = static_cast(self.ptr->stitch(*mats.ptr, *masks.ptr, *rpano.ptr)); + *rval = static_cast((*self.ptr)->stitch(*mats.ptr, *masks.ptr, *rpano.ptr)); END_WRAP } CvStatus *Stitcher_Component(Stitcher self, VecInt *rval) { BEGIN_WRAP - std::vector _rval = self.ptr->component(); + std::vector _rval = (*self.ptr)->component(); *rval = {new std::vector(_rval)}; END_WRAP } diff --git a/src/stitching/stitching.h b/src/stitching/stitching.h index ab61b1e2..4701a40d 100644 --- a/src/stitching/stitching.h +++ b/src/stitching/stitching.h @@ -23,16 +23,14 @@ enum { }; #ifdef __cplusplus -CVD_TYPEDEF(cv::Ptr, PtrStitcher); -CVD_TYPEDEF(cv::Stitcher, Stitcher); +CVD_TYPEDEF(cv::Ptr, Stitcher); #else -CVD_TYPEDEF(void *, PtrStitcher); -CVD_TYPEDEF(void, Stitcher); +CVD_TYPEDEF(void *, Stitcher); #endif -CvStatus *Stitcher_Create(int mode, PtrStitcher *rval); -void Stitcher_Close(PtrStitcherPtr stitcher); -CvStatus *Stitcher_Get(PtrStitcher self, Stitcher *rval); +CvStatus *Stitcher_Create(int mode, Stitcher *rval); +void Stitcher_Close(StitcherPtr stitcher); +CvStatus *Stitcher_Get(Stitcher self, Stitcher *rval); #pragma region getter/setter diff --git a/src/stitching/stitching_async.cpp b/src/stitching/stitching_async.cpp new file mode 100644 index 00000000..56c8e6c2 --- /dev/null +++ b/src/stitching/stitching_async.cpp @@ -0,0 +1,182 @@ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ +#include "stitching_async.h" +#include "core/types.h" + +// Asynchronous functions for Stitcher_Create +CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback) +{ + BEGIN_WRAP + const auto ptr = cv::Stitcher::create(static_cast(mode)); + callback(new Stitcher{new cv::Ptr(ptr)}); + END_WRAP +} + +// Asynchronous getter/setter functions +CvStatus *Stitcher_GetRegistrationResol_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new double((*self.ptr)->registrationResol())); + END_WRAP +} + +CvStatus *Stitcher_SetRegistrationResol_Async(Stitcher self, double inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setRegistrationResol(inval); + callback(); + END_WRAP +} + +CvStatus *Stitcher_GetSeamEstimationResol_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new double((*self.ptr)->seamEstimationResol())); + END_WRAP +} + +CvStatus *Stitcher_SetSeamEstimationResol_Async(Stitcher self, double inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setSeamEstimationResol(inval); + callback(); + END_WRAP +} + +CvStatus *Stitcher_GetCompositingResol_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new double((*self.ptr)->compositingResol())); + END_WRAP +} + +CvStatus *Stitcher_SetCompositingResol_Async(Stitcher self, double inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setCompositingResol(inval); + callback(); + END_WRAP +} + +CvStatus *Stitcher_GetPanoConfidenceThresh_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new double((*self.ptr)->panoConfidenceThresh())); + END_WRAP +} + +CvStatus *Stitcher_SetPanoConfidenceThresh_Async(Stitcher self, double inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setPanoConfidenceThresh(inval); + callback(); + END_WRAP +} + +CvStatus *Stitcher_GetWaveCorrection_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new bool((*self.ptr)->waveCorrection())); + END_WRAP +} + +CvStatus *Stitcher_SetWaveCorrection_Async(Stitcher self, bool inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setWaveCorrection(inval); + callback(); + END_WRAP +} + +CvStatus *Stitcher_GetInterpolationFlags_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new int(static_cast((*self.ptr)->interpolationFlags()))); + END_WRAP +} + +CvStatus *Stitcher_SetInterpolationFlags_Async(Stitcher self, int inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setInterpolationFlags(static_cast(inval)); + callback(); + END_WRAP +} + +CvStatus *Stitcher_GetWaveCorrectKind_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + callback(new int(static_cast((*self.ptr)->waveCorrectKind()))); + END_WRAP +} + +CvStatus *Stitcher_SetWaveCorrectKind_Async(Stitcher self, int inval, CvCallback_0 callback) +{ + BEGIN_WRAP + (*self.ptr)->setWaveCorrectKind(static_cast(inval)); + callback(); + END_WRAP +} + +// Asynchronous functions +CvStatus *Stitcher_EstimateTransform_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_1 callback) +{ + BEGIN_WRAP + int rval; + if (masks.ptr->size() > 0) + { + rval = static_cast((*self.ptr)->estimateTransform(*mats.ptr, *masks.ptr)); + } + else + { + rval = static_cast((*self.ptr)->estimateTransform(*mats.ptr)); + } + callback(new int(rval)); + END_WRAP +} + +CvStatus *Stitcher_ComposePanorama_Async(Stitcher self, CvCallback_2 callback) +{ + BEGIN_WRAP + cv::Mat ـrpano; + + int rval = static_cast((*self.ptr)->composePanorama(ـrpano)); + callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); + END_WRAP +} + +CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, CvCallback_2 callback) +{ + BEGIN_WRAP + cv::Mat ـrpano; + + int rval = static_cast((*self.ptr)->composePanorama(*mats.ptr, ـrpano)); + callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); + END_WRAP +} + +CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, CvCallback_2 callback) +{ + BEGIN_WRAP + cv::Mat ـrpano; + + int rval = static_cast((*self.ptr)->stitch(*mats.ptr, ـrpano)); + callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); + END_WRAP +} + +CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_2 callback) +{ + BEGIN_WRAP + cv::Mat ـrpano; + int rval = static_cast((*self.ptr)->stitch(*mats.ptr, *masks.ptr, ـrpano)); + callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); + END_WRAP +} + +CvStatus *Stitcher_Component_Async(Stitcher self, CvCallback_1 callback) +{ + BEGIN_WRAP + std::vector _rval = (*self.ptr)->component(); + callback(new VecInt{new std::vector(_rval)}); + END_WRAP +} diff --git a/src/stitching/stitching_async.h b/src/stitching/stitching_async.h new file mode 100644 index 00000000..2312d667 --- /dev/null +++ b/src/stitching/stitching_async.h @@ -0,0 +1,47 @@ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ +#ifndef OPENCV_DART_LIBRARY_STITCHING_ASYNC_H +#define OPENCV_DART_LIBRARY_STITCHING_ASYNC_H + +#include "core/types.h" +#include "stitching.h" + +#ifdef __cplusplus +#include +extern "C" { +#endif + +// Asynchronous functions for Stitcher_Create +CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback); + +// Asynchronous functions for Stitcher_Close +void Stitcher_Close_Async(StitcherPtr stitcher, CvCallback_0 callback); + +// Asynchronous getter/setter functions +CvStatus *Stitcher_GetRegistrationResol_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetRegistrationResol_Async(Stitcher self, double inval, CvCallback_0 callback); +CvStatus *Stitcher_GetSeamEstimationResol_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetSeamEstimationResol_Async(Stitcher self, double inval, CvCallback_0 callback); +CvStatus *Stitcher_GetCompositingResol_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetCompositingResol_Async(Stitcher self, double inval, CvCallback_0 callback); +CvStatus *Stitcher_GetPanoConfidenceThresh_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetPanoConfidenceThresh_Async(Stitcher self, double inval, CvCallback_0 callback); +CvStatus *Stitcher_GetWaveCorrection_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetWaveCorrection_Async(Stitcher self, bool inval, CvCallback_0 callback); +CvStatus *Stitcher_GetInterpolationFlags_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetInterpolationFlags_Async(Stitcher self, int inval, CvCallback_0 callback); +CvStatus *Stitcher_GetWaveCorrectKind_Async(Stitcher self, CvCallback_1 callback); +CvStatus *Stitcher_SetWaveCorrectKind_Async(Stitcher self, int inval, CvCallback_0 callback); + +// Asynchronous functions +CvStatus *Stitcher_EstimateTransform_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_1 callback); +CvStatus *Stitcher_ComposePanorama_Async(Stitcher self, CvCallback_2 callback); +CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, CvCallback_2 callback); +CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, CvCallback_2 callback); +CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_2 callback); +CvStatus *Stitcher_Component_Async(Stitcher self, CvCallback_1 callback); + +#ifdef __cplusplus +} +#endif + +#endif // OPENCV_DART_LIBRARY_STITCHING_ASYNC_H diff --git a/test/photo/photo_async_test.dart b/test/photo/photo_async_test.dart new file mode 100644 index 00000000..c07b249a --- /dev/null +++ b/test/photo/photo_async_test.dart @@ -0,0 +1,155 @@ +import 'package:opencv_dart/opencv_dart.dart' as cv; +import 'package:test/test.dart'; + +void main() { + test('cv.colorChangeAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final mask = src.clone(); + final dst = await cv.colorChangeAsync(src, mask); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src.rows, src.cols)); + }); + + test('cv.seamlessCloneAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final mask = src.clone(); + final dst = src.clone(); + final p = cv.Point(dst.cols ~/ 2, dst.rows ~/ 2); + final blend = await cv.seamlessCloneAsync(src, dst, mask, p, cv.NORMAL_CLONE); + expect(blend.isEmpty, false); + expect((blend.rows, blend.cols), (dst.rows, dst.cols)); + }); + + test('cv.illuminationChangeAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final mask = src.clone(); + final dst = await cv.illuminationChangeAsync(src, mask); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src.rows, src.cols)); + }); + + test('cv.textureFlatteningAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final mask = src.clone(); + final dst = await cv.textureFlatteningAsync(src, mask); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src.rows, src.cols)); + }); + + test('cv.fastNlMeansDenoisingAsync', () async { + final img = await cv.imreadAsync( + "test/images/lenna.png", + flags: cv.IMREAD_GRAYSCALE, + ); + expect(img.isEmpty, false); + + final dst = await cv.fastNlMeansDenoisingAsync(img); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (img.rows, img.cols)); + }); + + test('cv.fastNlMeansDenoisingColoredMultiAsync', () async { + final src = [ + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + ]; + + final dst = await cv.fastNlMeansDenoisingColoredMultiAsync(src.cvd, 1, 1); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src[0].rows, src[0].cols)); + }); + + test('cv.fastNlMeansDenoisingColoredAsync', () async { + final img = await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR); + expect(img.isEmpty, false); + + final dst = await cv.fastNlMeansDenoisingColoredAsync(img); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (img.rows, img.cols)); + }); + + test('cv.detailEnhanceAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final dst = await cv.detailEnhanceAsync(src); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src.rows, src.cols)); + }); + + test('cv.edgePreservingFilterAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final dst = await cv.edgePreservingFilterAsync(src); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src.rows, src.cols)); + }); + + test('cv.pencilSketchAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final (dst1, dst2) = await cv.pencilSketchAsync(src); + expect(dst1.isEmpty, false); + expect((dst1.rows, dst1.cols), (src.rows, src.cols)); + expect(dst2.isEmpty, false); + expect((dst2.rows, dst2.cols), (src.rows, src.cols)); + }); + + test('cv.stylizationAsync', () async { + final src = cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3); + final dst = await cv.stylizationAsync(src); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src.rows, src.cols)); + }); + + test('cv.inpaintAsync', () async { + final src = await cv.imreadAsync( + "test/images/inpaint-src.jpg", + flags: cv.IMREAD_COLOR, + ); + expect(src.isEmpty, false); + final mask = await cv.imreadAsync( + "test/images/inpaint-mask.jpg", + flags: cv.IMREAD_GRAYSCALE, + ); + expect(mask.isEmpty, false); + final dst = await cv.inpaintAsync(src, mask, 10, cv.INPAINT_TELEA); + expect(dst.channels, greaterThan(1)); + final sum = dst.sum(); + expect(sum == cv.Scalar.all(0), false); + }); + + test('cv.MergeMertensAsync', () async { + final src = [ + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + ]; + final mertens = await cv.MergeMertensAsync.emptyNewAsync(); + final dst = await mertens.processAsync(src.cvd); + expect(dst.isEmpty, false); + expect((dst.rows, dst.cols), (src[0].rows, src[0].cols)); + + final mertens1 = await cv.MergeMertensAsync.createAsync(); + final dst1 = await mertens1.processAsync(src.cvd); + expect(dst1.isEmpty, false); + expect((dst1.rows, dst1.cols), (src[0].rows, src[0].cols)); + + mertens1.dispose(); + }); + + test('cv.AlignMTBAsync', () async { + final src = [ + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + cv.Mat.zeros(20, 20, cv.MatType.CV_8UC3), + ]; + + final alignmtb = await cv.AlignMTBAsync.emptyNewAsync(); + final dst = await alignmtb.processAsync(src.cvd); + expect(dst.length, greaterThan(0)); + + final alignmtb1 = await cv.AlignMTBAsync.createAsync(); + final dst1 = await alignmtb1.processAsync(src.cvd); + expect(dst1.length, greaterThan(0)); + + alignmtb1.dispose(); + }); +} diff --git a/test/photo_test.dart b/test/photo/photo_test.dart similarity index 100% rename from test/photo_test.dart rename to test/photo/photo_test.dart diff --git a/test/stitching/stitching_async_test.dart b/test/stitching/stitching_async_test.dart new file mode 100644 index 00000000..70fdb245 --- /dev/null +++ b/test/stitching/stitching_async_test.dart @@ -0,0 +1,78 @@ +import 'package:opencv_dart/opencv_dart.dart' as cv; +import 'package:test/test.dart'; + +void main() { + test('cv.StitcherAsync', () async { + final stitcher = await cv.StitcherAsync.createAsync(mode: cv.StitcherMode.PANORAMA); + final images = [ + await cv.imreadAsync("test/images/barcode1.png", flags: cv.IMREAD_COLOR), + await cv.imreadAsync("test/images/barcode2.png", flags: cv.IMREAD_COLOR), + ]; + final (status, pano) = await stitcher.stitchAsync(images.cvd); + expect(status, cv.StitcherStatus.OK); + expect(pano.isEmpty, false); + stitcher.dispose(); + }); + + test('cv.StitcherAsync with mask', () async { + final stitcher = await cv.StitcherAsync.createAsync(mode: cv.StitcherMode.PANORAMA); + final images = [ + await cv.imreadAsync("test/images/barcode1.png", flags: cv.IMREAD_COLOR), + await cv.imreadAsync("test/images/barcode2.png", flags: cv.IMREAD_COLOR), + ]; + + final masks = [ + await cv.imreadAsync("test/images/barcode_mask1.png", flags: cv.IMREAD_GRAYSCALE), + await cv.imreadAsync("test/images/barcode_mask2.png", flags: cv.IMREAD_GRAYSCALE), + ]; + final (status, pano) = await stitcher.stitchAsync(images.cvd, masks: masks.cvd); + expect(status, cv.StitcherStatus.OK); + expect(pano.isEmpty, false); + stitcher.dispose(); + }); + + test('cv.StitcherAsync getter/setter', () async { + final stitcher = await cv.StitcherAsync.createAsync(mode: cv.StitcherMode.PANORAMA); + await stitcher.setRegistrationResolAsync(3.14159); + expect(await stitcher.getRegistrationResolAsync(), 3.14159); + + await stitcher.setSeamEstimationResolAsync(3.14159); + expect(await stitcher.getSeamEstimationResolAsync(), 3.14159); + + await stitcher.setPanoConfidenceThreshAsync(3.14159); + expect(await stitcher.getPanoConfidenceThreshAsync(), 3.14159); + + await stitcher.setCompositingResolAsync(3.14159); + expect(await stitcher.getCompositingResolAsync(), 3.14159); + + await stitcher.setWaveCorrectionAsync(true); + expect(await stitcher.getWaveCorrectionAsync(), true); + + await stitcher.setWaveCorrectKindAsync(cv.WaveCorrectKind.HORIZONTAL.index); + expect(await stitcher.getWaveCorrectKindAsync(), cv.WaveCorrectKind.HORIZONTAL.index); + + await stitcher.setInterpolationFlagsAsync(cv.INTER_LINEAR); + expect(await stitcher.getInterpolationFlagsAsync(), cv.INTER_LINEAR); + + expect((await stitcher.getComponentAsync()).length, greaterThanOrEqualTo(0)); + }); + + test('Issue 48', () async { + final images = [ + await cv.imreadAsync("test/images/barcode1.png", flags: cv.IMREAD_COLOR), + await cv.imreadAsync("test/images/barcode2.png", flags: cv.IMREAD_COLOR), + ]; + + final stitcher = await cv.StitcherAsync.createAsync(); + final status = await stitcher.estimateTransformAsync(images.cvd); + expect(status, cv.StitcherStatus.OK); + + final result = await stitcher.composePanoramaAsync(); + expect(result.$1, cv.StitcherStatus.OK); + expect(result.$2.isEmpty, false); + + final result1 = await stitcher.composePanoramaAsync(images: images.cvd); + expect(result1.$1, cv.StitcherStatus.OK); + expect(result1.$2.isEmpty, false); + }); +} diff --git a/test/stitching_test.dart b/test/stitching/stitching_test.dart similarity index 100% rename from test/stitching_test.dart rename to test/stitching/stitching_test.dart