From 8d4b0ab7b96b93e174005c8917cae50c9b301af0 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Fri, 28 Jun 2024 15:18:33 +0300 Subject: [PATCH 01/15] c wrapper --- ffigen.yaml | 4 + lib/src/opencv.g.dart | 988 +++++++++++++++++++++++++++++- src/photo/photo_async.cpp | 161 +++++ src/photo/photo_async.h | 66 ++ src/stitching/stitching_async.cpp | 158 +++++ src/stitching/stitching_async.h | 50 ++ 6 files changed, 1413 insertions(+), 14 deletions(-) create mode 100644 src/photo/photo_async.cpp create mode 100644 src/photo/photo_async.h create mode 100644 src/stitching/stitching_async.cpp create mode 100644 src/stitching/stitching_async.h diff --git a/ffigen.yaml b/ffigen.yaml index 2fef60f4..7a73d77e 100644 --- a/ffigen.yaml +++ b/ffigen.yaml @@ -39,7 +39,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: @@ -67,7 +69,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/src/opencv.g.dart b/lib/src/opencv.g.dart index fa6640b9..c3e33124 100644 --- a/lib/src/opencv.g.dart +++ b/lib/src/opencv.g.dart @@ -258,6 +258,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, @@ -277,6 +313,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, @@ -3857,6 +3912,34 @@ class CvNative { late final _ColorChange = _ColorChangePtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double, double)>(); + ffi.Pointer ColorChange_Async( + Mat src, + Mat mask, + Mat dst, + double red_mul, + double green_mul, + double blue_mul, + CvCallback_0 callback, + ) { + return _ColorChange_Async( + src, + mask, + dst, + red_mul, + green_mul, + blue_mul, + callback, + ); + } + + late final _ColorChange_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, + ffi.Float, CvCallback_0)>>('ColorChange_Async'); + late final _ColorChange_Async = _ColorChange_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, double, double, double, CvCallback_0)>(); + ffi.Pointer CompareHist( Mat hist1, Mat hist2, @@ -4240,6 +4323,29 @@ class CvNative { late final _DetailEnhance = _DetailEnhancePtr.asFunction< ffi.Pointer Function(Mat, Mat, double, double)>(); + ffi.Pointer DetailEnhance_Async( + Mat src, + Mat dst, + double sigma_s, + double sigma_r, + CvCallback_0 callback, + ) { + return _DetailEnhance_Async( + src, + dst, + sigma_s, + sigma_r, + callback, + ); + } + + late final _DetailEnhance_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, + CvCallback_0)>>('DetailEnhance_Async'); + late final _DetailEnhance_Async = _DetailEnhance_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, Mat, double, double, CvCallback_0)>(); + ffi.Pointer Dilate( Mat src, Mat dst, @@ -4623,6 +4729,33 @@ class CvNative { late final _EdgePreservingFilter = _EdgePreservingFilterPtr.asFunction< ffi.Pointer Function(Mat, Mat, int, double, double)>(); + ffi.Pointer EdgePreservingFilter_Async( + Mat src, + Mat dst, + int filter, + double sigma_s, + double sigma_r, + CvCallback_0 callback, + ) { + return _EdgePreservingFilter_Async( + src, + dst, + filter, + sigma_s, + sigma_r, + callback, + ); + } + + late final _EdgePreservingFilter_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Int, ffi.Float, + ffi.Float, CvCallback_0)>>('EdgePreservingFilter_Async'); + late final _EdgePreservingFilter_Async = + _EdgePreservingFilter_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, int, double, double, CvCallback_0)>(); + ffi.Pointer Ellipse( Mat img, Point center, @@ -5973,6 +6106,65 @@ class CvNative { ffi.Pointer Function( VecMat, Mat, int, int, double, double, int, int)>(); + ffi.Pointer FastNlMeansDenoisingColoredMultiWithParams_Async( + VecMat src, + Mat dst, + int imgToDenoiseIndex, + int temporalWindowSize, + double h, + double hColor, + int templateWindowSize, + int searchWindowSize, + CvCallback_0 callback, + ) { + return _FastNlMeansDenoisingColoredMultiWithParams_Async( + src, + dst, + imgToDenoiseIndex, + temporalWindowSize, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingColoredMultiWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(VecMat, Mat, ffi.Int, ffi.Int, + ffi.Float, ffi.Float, ffi.Int, ffi.Int, CvCallback_0)>>( + 'FastNlMeansDenoisingColoredMultiWithParams_Async'); + late final _FastNlMeansDenoisingColoredMultiWithParams_Async = + _FastNlMeansDenoisingColoredMultiWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + VecMat, Mat, int, int, double, double, int, int, CvCallback_0)>(); + + ffi.Pointer FastNlMeansDenoisingColoredMulti_Async( + VecMat src, + Mat dst, + int imgToDenoiseIndex, + int temporalWindowSize, + CvCallback_0 callback, + ) { + return _FastNlMeansDenoisingColoredMulti_Async( + src, + dst, + imgToDenoiseIndex, + temporalWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingColoredMulti_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(VecMat, Mat, ffi.Int, ffi.Int, + CvCallback_0)>>('FastNlMeansDenoisingColoredMulti_Async'); + late final _FastNlMeansDenoisingColoredMulti_Async = + _FastNlMeansDenoisingColoredMulti_AsyncPtr.asFunction< + ffi.Pointer Function( + VecMat, Mat, int, int, CvCallback_0)>(); + ffi.Pointer FastNlMeansDenoisingColoredWithParams( Mat src, Mat dst, @@ -5999,6 +6191,61 @@ class CvNative { _FastNlMeansDenoisingColoredWithParamsPtr.asFunction< ffi.Pointer Function(Mat, Mat, double, double, int, int)>(); + ffi.Pointer FastNlMeansDenoisingColoredWithParams_Async( + Mat src, + Mat dst, + double h, + double hColor, + int templateWindowSize, + int searchWindowSize, + CvCallback_0 callback, + ) { + return _FastNlMeansDenoisingColoredWithParams_Async( + src, + dst, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingColoredWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Mat, + Mat, + ffi.Float, + ffi.Float, + ffi.Int, + ffi.Int, + CvCallback_0)>>('FastNlMeansDenoisingColoredWithParams_Async'); + late final _FastNlMeansDenoisingColoredWithParams_Async = + _FastNlMeansDenoisingColoredWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, double, double, int, int, CvCallback_0)>(); + + ffi.Pointer FastNlMeansDenoisingColored_Async( + Mat src, + Mat dst, + CvCallback_0 callback, + ) { + return _FastNlMeansDenoisingColored_Async( + src, + dst, + callback, + ); + } + + late final _FastNlMeansDenoisingColored_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Mat, Mat, CvCallback_0)>>('FastNlMeansDenoisingColored_Async'); + late final _FastNlMeansDenoisingColored_Async = + _FastNlMeansDenoisingColored_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, Mat, CvCallback_0)>(); + ffi.Pointer FastNlMeansDenoisingWithParams( Mat src, Mat dst, @@ -6023,6 +6270,52 @@ class CvNative { _FastNlMeansDenoisingWithParamsPtr.asFunction< ffi.Pointer Function(Mat, Mat, double, int, int)>(); + ffi.Pointer FastNlMeansDenoisingWithParams_Async( + Mat src, + Mat dst, + double h, + int templateWindowSize, + int searchWindowSize, + CvCallback_0 callback, + ) { + return _FastNlMeansDenoisingWithParams_Async( + src, + dst, + h, + templateWindowSize, + searchWindowSize, + callback, + ); + } + + late final _FastNlMeansDenoisingWithParams_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Int, ffi.Int, + CvCallback_0)>>('FastNlMeansDenoisingWithParams_Async'); + late final _FastNlMeansDenoisingWithParams_Async = + _FastNlMeansDenoisingWithParams_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, double, int, int, CvCallback_0)>(); + + ffi.Pointer FastNlMeansDenoising_Async( + Mat src, + Mat dst, + CvCallback_0 callback, + ) { + return _FastNlMeansDenoising_Async( + src, + dst, + callback, + ); + } + + late final _FastNlMeansDenoising_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Mat, Mat, CvCallback_0)>>('FastNlMeansDenoising_Async'); + late final _FastNlMeansDenoising_Async = _FastNlMeansDenoising_AsyncPtr + .asFunction Function(Mat, Mat, CvCallback_0)>(); + ffi.Pointer FillPoly( Mat img, VecVecPoint points, @@ -8787,6 +9080,33 @@ class CvNative { late final _IlluminationChange = _IlluminationChangePtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double)>(); + ffi.Pointer IlluminationChange_Async( + Mat src, + Mat mask, + Mat dst, + double alpha, + double beta, + CvCallback_0 callback, + ) { + return _IlluminationChange_Async( + src, + mask, + dst, + alpha, + beta, + callback, + ); + } + + late final _IlluminationChange_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, + CvCallback_0)>>('IlluminationChange_Async'); + late final _IlluminationChange_Async = + _IlluminationChange_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, double, double, CvCallback_0)>(); + ffi.Pointer Image_IMDecode( VecUChar buf, int flags, @@ -15566,27 +15886,87 @@ class CvNative { ffi.Pointer Function( double, double, double, ffi.Pointer)>(); - ffi.Pointer MergeMertens_Process( - MergeMertens b, - VecMat src, - Mat dst, + ffi.Pointer MergeMertens_CreateWithParams_Async( + double contrast_weight, + double saturation_weight, + double exposure_weight, + CvCallback_1 callback, ) { - return _MergeMertens_Process( - b, - src, - dst, + return _MergeMertens_CreateWithParams_Async( + contrast_weight, + saturation_weight, + exposure_weight, + callback, ); } - late final _MergeMertens_ProcessPtr = _lookup< + 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( - MergeMertens, VecMat, Mat)>>('MergeMertens_Process'); - late final _MergeMertens_Process = _MergeMertens_ProcessPtr.asFunction< - ffi.Pointer Function(MergeMertens, VecMat, Mat)>(); + double, double, double, CvCallback_1)>(); - ffi.Pointer MinAreaRect( - VecPoint pts, + 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, + Mat dst, + ) { + return _MergeMertens_Process( + b, + src, + dst, + ); + } + + late final _MergeMertens_ProcessPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + MergeMertens, VecMat, Mat)>>('MergeMertens_Process'); + late final _MergeMertens_Process = _MergeMertens_ProcessPtr.asFunction< + ffi.Pointer Function(MergeMertens, VecMat, Mat)>(); + + ffi.Pointer MergeMertens_Process_Async( + MergeMertens b, + VecMat src, + Mat dst, + CvCallback_0 callback, + ) { + return _MergeMertens_Process_Async( + b, + src, + dst, + callback, + ); + } + + late final _MergeMertens_Process_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(MergeMertens, VecMat, Mat, + CvCallback_0)>>('MergeMertens_Process_Async'); + late final _MergeMertens_Process_Async = + _MergeMertens_Process_AsyncPtr.asFunction< + ffi.Pointer Function( + MergeMertens, VecMat, Mat, CvCallback_0)>(); + + ffi.Pointer MinAreaRect( + VecPoint pts, ffi.Pointer rval, ) { return _MinAreaRect( @@ -17390,6 +17770,34 @@ class CvNative { late final _PencilSketch = _PencilSketchPtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double, double)>(); + ffi.Pointer PencilSketch_Async( + Mat src, + Mat dst1, + Mat dst2, + double sigma_s, + double sigma_r, + double shade_factor, + CvCallback_0 callback, + ) { + return _PencilSketch_Async( + src, + dst1, + dst2, + sigma_s, + sigma_r, + shade_factor, + callback, + ); + } + + late final _PencilSketch_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, + ffi.Float, CvCallback_0)>>('PencilSketch_Async'); + late final _PencilSketch_Async = _PencilSketch_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, double, double, double, CvCallback_0)>(); + ffi.Pointer PhaseCorrelate( Mat src1, Mat src2, @@ -17458,6 +17866,32 @@ class CvNative { late final _PhotoInpaint = _PhotoInpaintPtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, int)>(); + ffi.Pointer PhotoInpaint_Async( + Mat src, + Mat mask, + Mat dst, + double inpaint_radius, + int algorithm_type, + CvCallback_0 callback, + ) { + return _PhotoInpaint_Async( + src, + mask, + dst, + inpaint_radius, + algorithm_type, + callback, + ); + } + + late final _PhotoInpaint_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Int, + CvCallback_0)>>('PhotoInpaint_Async'); + late final _PhotoInpaint_Async = _PhotoInpaint_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, double, int, CvCallback_0)>(); + ffi.Pointer PointPolygonTest( VecPoint pts, Point2f pt, @@ -19243,6 +19677,34 @@ 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, + Mat blend, + int flags, + CvCallback_0 callback, + ) { + return _SeamlessClone_Async( + src, + dst, + mask, + p, + blend, + flags, + callback, + ); + } + + late final _SeamlessClone_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, Point, Mat, ffi.Int, + CvCallback_0)>>('SeamlessClone_Async'); + late final _SeamlessClone_Async = _SeamlessClone_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, Point, Mat, int, CvCallback_0)>(); + ffi.Pointer SepFilter2D( Mat src, Mat dst, @@ -19592,6 +20054,22 @@ class CvNative { late final _Stitcher_Close = _Stitcher_ClosePtr.asFunction(); + void Stitcher_Close_Async( + PtrStitcherPtr stitcher, + CvCallback_0 callback, + ) { + return _Stitcher_Close_Async( + stitcher, + callback, + ); + } + + late final _Stitcher_Close_AsyncPtr = _lookup< + ffi.NativeFunction>( + 'Stitcher_Close_Async'); + late final _Stitcher_Close_Async = _Stitcher_Close_AsyncPtr.asFunction< + void Function(PtrStitcherPtr, CvCallback_0)>(); + ffi.Pointer Stitcher_Component( Stitcher self, ffi.Pointer rval, @@ -19609,6 +20087,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, @@ -19653,6 +20148,49 @@ class CvNative { ffi.Pointer Function( Stitcher, VecMat, Mat, ffi.Pointer)>(); + ffi.Pointer Stitcher_ComposePanorama_1_Async( + Stitcher self, + VecMat mats, + Mat rpano, + CvCallback_1 callback, + ) { + return _Stitcher_ComposePanorama_1_Async( + self, + mats, + rpano, + callback, + ); + } + + late final _Stitcher_ComposePanorama_1_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, VecMat, Mat, + CvCallback_1)>>('Stitcher_ComposePanorama_1_Async'); + late final _Stitcher_ComposePanorama_1_Async = + _Stitcher_ComposePanorama_1_AsyncPtr.asFunction< + ffi.Pointer Function( + Stitcher, VecMat, Mat, CvCallback_1)>(); + + ffi.Pointer Stitcher_ComposePanorama_Async( + Stitcher self, + Mat rpano, + CvCallback_1 callback, + ) { + return _Stitcher_ComposePanorama_Async( + self, + rpano, + callback, + ); + } + + late final _Stitcher_ComposePanorama_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, Mat, CvCallback_1)>>('Stitcher_ComposePanorama_Async'); + late final _Stitcher_ComposePanorama_Async = + _Stitcher_ComposePanorama_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, Mat, CvCallback_1)>(); + ffi.Pointer Stitcher_Create( int mode, ffi.Pointer rval, @@ -19670,6 +20208,23 @@ class CvNative { late final _Stitcher_Create = _Stitcher_CreatePtr.asFunction< 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, VecMat mats, @@ -19693,6 +20248,29 @@ 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, ffi.Pointer rval, @@ -19728,6 +20306,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, @@ -19746,6 +20342,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, @@ -19764,6 +20378,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, @@ -19782,6 +20414,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, @@ -19800,6 +20450,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, @@ -19818,6 +20486,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, @@ -19836,6 +20522,41 @@ 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_Get_Async( + PtrStitcher self, + CvCallback_1 callback, + ) { + return _Stitcher_Get_Async( + self, + callback, + ); + } + + late final _Stitcher_Get_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + PtrStitcher, CvCallback_1)>>('Stitcher_Get_Async'); + late final _Stitcher_Get_Async = _Stitcher_Get_AsyncPtr.asFunction< + ffi.Pointer Function(PtrStitcher, CvCallback_1)>(); + ffi.Pointer Stitcher_SetCompositingResol( Stitcher self, double inval, @@ -19853,6 +20574,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, @@ -19871,6 +20612,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, @@ -19889,6 +20650,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, @@ -19906,6 +20687,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, @@ -19924,6 +20725,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, @@ -19941,6 +20762,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, @@ -19958,6 +20799,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, @@ -20004,6 +20865,51 @@ class CvNative { ffi.Pointer Function( Stitcher, VecMat, VecMat, Mat, ffi.Pointer)>(); + ffi.Pointer Stitcher_Stitch_1_Async( + Stitcher self, + VecMat mats, + VecMat masks, + Mat rpano, + CvCallback_1 callback, + ) { + return _Stitcher_Stitch_1_Async( + self, + mats, + masks, + rpano, + callback, + ); + } + + late final _Stitcher_Stitch_1_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Stitcher, VecMat, VecMat, Mat, + CvCallback_1)>>('Stitcher_Stitch_1_Async'); + late final _Stitcher_Stitch_1_Async = _Stitcher_Stitch_1_AsyncPtr.asFunction< + ffi.Pointer Function( + Stitcher, VecMat, VecMat, Mat, CvCallback_1)>(); + + ffi.Pointer Stitcher_Stitch_Async( + Stitcher self, + VecMat mats, + Mat rpano, + CvCallback_1 callback, + ) { + return _Stitcher_Stitch_Async( + self, + mats, + rpano, + callback, + ); + } + + late final _Stitcher_Stitch_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + Stitcher, VecMat, Mat, CvCallback_1)>>('Stitcher_Stitch_Async'); + late final _Stitcher_Stitch_Async = _Stitcher_Stitch_AsyncPtr.asFunction< + ffi.Pointer Function(Stitcher, VecMat, Mat, CvCallback_1)>(); + ffi.Pointer Stylization( Mat src, Mat dst, @@ -20025,6 +20931,29 @@ class CvNative { late final _Stylization = _StylizationPtr.asFunction< ffi.Pointer Function(Mat, Mat, double, double)>(); + ffi.Pointer Stylization_Async( + Mat src, + Mat dst, + double sigma_s, + double sigma_r, + CvCallback_0 callback, + ) { + return _Stylization_Async( + src, + dst, + sigma_s, + sigma_r, + callback, + ); + } + + late final _Stylization_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, + CvCallback_0)>>('Stylization_Async'); + late final _Stylization_Async = _Stylization_AsyncPtr.asFunction< + ffi.Pointer Function(Mat, Mat, double, double, CvCallback_0)>(); + void Subdiv2D_Close( Subdiv2DPtr self, ) { @@ -20799,6 +21728,34 @@ class CvNative { late final _TextureFlattening = _TextureFlatteningPtr.asFunction< ffi.Pointer Function(Mat, Mat, Mat, double, double, int)>(); + ffi.Pointer TextureFlattening_Async( + Mat src, + Mat mask, + Mat dst, + double low_threshold, + double high_threshold, + int kernel_size, + CvCallback_0 callback, + ) { + return _TextureFlattening_Async( + src, + mask, + dst, + low_threshold, + high_threshold, + kernel_size, + callback, + ); + } + + late final _TextureFlattening_AsyncPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, + ffi.Int, CvCallback_0)>>('TextureFlattening_Async'); + late final _TextureFlattening_Async = _TextureFlattening_AsyncPtr.asFunction< + ffi.Pointer Function( + Mat, Mat, Mat, double, double, int, CvCallback_0)>(); + ffi.Pointer TheRNG( ffi.Pointer rval, ) { @@ -28046,6 +29003,9 @@ class _SymbolAddresses { get SimpleBlobDetector_Close => _library._SimpleBlobDetector_ClosePtr; ffi.Pointer> get Stitcher_Close => _library._Stitcher_ClosePtr; + ffi.Pointer< + ffi.NativeFunction> + get Stitcher_Close_Async => _library._Stitcher_Close_AsyncPtr; ffi.Pointer> get Subdiv2D_Close => _library._Subdiv2D_ClosePtr; ffi.Pointer> diff --git a/src/photo/photo_async.cpp b/src/photo/photo_async.cpp new file mode 100644 index 00000000..2c8eabe7 --- /dev/null +++ b/src/photo/photo_async.cpp @@ -0,0 +1,161 @@ +/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +#include "photo_async.h" +#include "core/types.h" + +// Asynchronous functions for ColorChange +CvStatus *ColorChange_Async(Mat src, Mat mask, Mat dst, float red_mul, float green_mul, float blue_mul, CvCallback_0 callback) { + BEGIN_WRAP + cv::colorChange(*src.ptr, *mask.ptr, *dst.ptr, red_mul, green_mul, blue_mul); + callback(); + END_WRAP +} + +// Asynchronous functions for SeamlessClone +CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags, CvCallback_0 callback) { + BEGIN_WRAP + cv::seamlessClone(*src.ptr, *dst.ptr, *mask.ptr, cv::Point(p.x, p.y), *blend.ptr, flags); + callback(); + END_WRAP +} + +// Asynchronous functions for IlluminationChange +CvStatus *IlluminationChange_Async(Mat src, Mat mask, Mat dst, float alpha, float beta, CvCallback_0 callback) { + BEGIN_WRAP + cv::illuminationChange(*src.ptr, *mask.ptr, *dst.ptr, alpha, beta); + callback(); + END_WRAP +} + +// Asynchronous functions for TextureFlattening +CvStatus *TextureFlattening_Async(Mat src, Mat mask, Mat dst, float low_threshold, float high_threshold, int kernel_size, CvCallback_0 callback) { + BEGIN_WRAP + cv::textureFlattening(*src.ptr, *mask.ptr, *dst.ptr, low_threshold, high_threshold, kernel_size); + callback(); + END_WRAP +} + +// Asynchronous functions for FastNlMeansDenoisingColoredMulti +CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_0 callback) { + BEGIN_WRAP + cv::fastNlMeansDenoisingColoredMulti(*src.ptr, *dst.ptr, imgToDenoiseIndex, temporalWindowSize); + callback(); + END_WRAP +} + +CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback) { + BEGIN_WRAP + cv::fastNlMeansDenoisingColoredMulti(*src.ptr, *dst.ptr, imgToDenoiseIndex, temporalWindowSize, h, hColor, templateWindowSize, searchWindowSize); + callback(); + END_WRAP +} + +// Asynchronous functions for FastNlMeansDenoising +CvStatus *FastNlMeansDenoising_Async(Mat src, Mat dst, CvCallback_0 callback) { + BEGIN_WRAP + cv::fastNlMeansDenoising(*src.ptr, *dst.ptr); + callback(); + END_WRAP +} + +CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize, CvCallback_0 callback) { + BEGIN_WRAP + cv::fastNlMeansDenoising(*src.ptr, *dst.ptr, h, templateWindowSize, searchWindowSize); + callback(); + END_WRAP +} + +// Asynchronous functions for FastNlMeansDenoisingColored +CvStatus *FastNlMeansDenoisingColored_Async(Mat src, Mat dst, CvCallback_0 callback) { + BEGIN_WRAP + cv::fastNlMeansDenoisingColored(*src.ptr, *dst.ptr); + callback(); + END_WRAP +} + +CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, Mat dst, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback) { + BEGIN_WRAP + cv::fastNlMeansDenoisingColored(*src.ptr, *dst.ptr, h, hColor, templateWindowSize, searchWindowSize); + callback(); + 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, Mat dst, CvCallback_0 callback) { + BEGIN_WRAP + (*b.ptr)->process(*src.ptr, *dst.ptr); + callback(); + 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, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback) { + BEGIN_WRAP + cv::detailEnhance(*src.ptr, *dst.ptr, sigma_s, sigma_r); + callback(); + END_WRAP +} + +// Asynchronous functions for EdgePreservingFilter +CvStatus *EdgePreservingFilter_Async(Mat src, Mat dst, int filter, float sigma_s, float sigma_r, CvCallback_0 callback) { + BEGIN_WRAP + cv::edgePreservingFilter(*src.ptr, *dst.ptr, filter, sigma_s, sigma_r); + callback(); + END_WRAP +} + +// Asynchronous functions for PencilSketch +CvStatus *PencilSketch_Async(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_0 callback) { + BEGIN_WRAP + cv::pencilSketch(*src.ptr, *dst1.ptr, *dst2.ptr, sigma_s, sigma_r, shade_factor); + callback(); + END_WRAP +} + +// Asynchronous functions for Stylization +CvStatus *Stylization_Async(Mat src, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback) { + BEGIN_WRAP + cv::stylization(*src.ptr, *dst.ptr, sigma_s, sigma_r); + callback(); + END_WRAP +} + +// Asynchronous functions for PhotoInpaint +CvStatus *PhotoInpaint_Async(Mat src, Mat mask, Mat dst, float inpaint_radius, int algorithm_type, CvCallback_0 callback) { + BEGIN_WRAP + cv::inpaint(*src.ptr, *mask.ptr, *dst.ptr, inpaint_radius, algorithm_type); + callback(); + END_WRAP +} diff --git a/src/photo/photo_async.h b/src/photo/photo_async.h new file mode 100644 index 00000000..f5d56759 --- /dev/null +++ b/src/photo/photo_async.h @@ -0,0 +1,66 @@ +/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +#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, Mat dst, float red_mul, float green_mul, float blue_mul, CvCallback_0 callback); + +// Asynchronous functions for SeamlessClone +CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags, CvCallback_0 callback); + +// Asynchronous functions for IlluminationChange +CvStatus *IlluminationChange_Async(Mat src, Mat mask, Mat dst, float alpha, float beta, CvCallback_0 callback); + +// Asynchronous functions for TextureFlattening +CvStatus *TextureFlattening_Async(Mat src, Mat mask, Mat dst, float low_threshold, float high_threshold, int kernel_size, CvCallback_0 callback); + +// Asynchronous functions for FastNlMeansDenoisingColoredMulti +CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_0 callback); +CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback); + +// Asynchronous functions for FastNlMeansDenoising +CvStatus *FastNlMeansDenoising_Async(Mat src, Mat dst, CvCallback_0 callback); +CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize, CvCallback_0 callback); + +// Asynchronous functions for FastNlMeansDenoisingColored +CvStatus *FastNlMeansDenoisingColored_Async(Mat src, Mat dst, CvCallback_0 callback); +CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, Mat dst, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 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, Mat dst, CvCallback_0 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, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback); + +// Asynchronous functions for EdgePreservingFilter +CvStatus *EdgePreservingFilter_Async(Mat src, Mat dst, int filter, float sigma_s, float sigma_r, CvCallback_0 callback); + +// Asynchronous functions for PencilSketch +CvStatus *PencilSketch_Async(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_0 callback); + +// Asynchronous functions for Stylization +CvStatus *Stylization_Async(Mat src, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback); + +// Asynchronous functions for PhotoInpaint +CvStatus *PhotoInpaint_Async(Mat src, Mat mask, Mat dst, float inpaint_radius, int algorithm_type, CvCallback_0 callback); + +#ifdef __cplusplus +} +#endif + +#endif // CVD_PHOTO_ASYNC_H_ diff --git a/src/stitching/stitching_async.cpp b/src/stitching/stitching_async.cpp new file mode 100644 index 00000000..fab18c02 --- /dev/null +++ b/src/stitching/stitching_async.cpp @@ -0,0 +1,158 @@ +/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +#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 PtrStitcher{new cv::Ptr(ptr)}); + END_WRAP +} + +// Asynchronous functions for Stitcher_Get +CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 callback) { + BEGIN_WRAP + callback(new Stitcher{self.ptr->get()}); + 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, Mat rpano, CvCallback_1 callback) { + BEGIN_WRAP + int rval = static_cast(self.ptr->composePanorama(*rpano.ptr)); + callback(new int(rval)); + END_WRAP +} + +CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, Mat rpano, CvCallback_1 callback) { + BEGIN_WRAP + int rval = static_cast(self.ptr->composePanorama(*mats.ptr, *rpano.ptr)); + callback(new int(rval)); + END_WRAP +} + +CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, Mat rpano, CvCallback_1 callback) { + BEGIN_WRAP + int rval = static_cast(self.ptr->stitch(*mats.ptr, *rpano.ptr)); + callback(new int(rval)); + END_WRAP +} + +CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, Mat rpano, CvCallback_1 callback) { + BEGIN_WRAP + int rval = static_cast(self.ptr->stitch(*mats.ptr, *masks.ptr, *rpano.ptr)); + callback(new int(rval)); + 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..84e10c9e --- /dev/null +++ b/src/stitching/stitching_async.h @@ -0,0 +1,50 @@ +/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +#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(PtrStitcherPtr stitcher, CvCallback_0 callback); + +// Asynchronous functions for Stitcher_Get +CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 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, Mat rpano, CvCallback_1 callback); +CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, Mat rpano, CvCallback_1 callback); +CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, Mat rpano, CvCallback_1 callback); +CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, Mat rpano, CvCallback_1 callback); +CvStatus *Stitcher_Component_Async(Stitcher self, CvCallback_1 callback); + +#ifdef __cplusplus +} +#endif + +#endif // OPENCV_DART_LIBRARY_STITCHING_ASYNC_H From 0ef9ff958f085e75a967d57d57e8ffe9b0babe40 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Fri, 28 Jun 2024 15:19:45 +0300 Subject: [PATCH 02/15] updating name --- src/photo/photo_async.cpp | 2 +- src/photo/photo_async.h | 2 +- src/stitching/stitching_async.cpp | 2 +- src/stitching/stitching_async.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/photo/photo_async.cpp b/src/photo/photo_async.cpp index 2c8eabe7..b2b4e001 100644 --- a/src/photo/photo_async.cpp +++ b/src/photo/photo_async.cpp @@ -1,4 +1,4 @@ -/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ #include "photo_async.h" #include "core/types.h" diff --git a/src/photo/photo_async.h b/src/photo/photo_async.h index f5d56759..5ac2c448 100644 --- a/src/photo/photo_async.h +++ b/src/photo/photo_async.h @@ -1,4 +1,4 @@ -/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ #ifndef CVD_PHOTO_ASYNC_H_ #define CVD_PHOTO_ASYNC_H_ diff --git a/src/stitching/stitching_async.cpp b/src/stitching/stitching_async.cpp index fab18c02..d97254c9 100644 --- a/src/stitching/stitching_async.cpp +++ b/src/stitching/stitching_async.cpp @@ -1,4 +1,4 @@ -/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +/* Created by Abdelaziz Mahdy. Licensed: Apache 2.0 license. Copyright (c) 2024 Abdelaziz Mahdy. */ #include "stitching_async.h" #include "core/types.h" diff --git a/src/stitching/stitching_async.h b/src/stitching/stitching_async.h index 84e10c9e..52f6d0cd 100644 --- a/src/stitching/stitching_async.h +++ b/src/stitching/stitching_async.h @@ -1,4 +1,4 @@ -/* Created by Rainyl. Licensed: Apache 2.0 license. Copyright (c) 2024 Rainyl. */ +/* 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 From 01d2c39e45b9ab9a238af5fb6d5b559162775eb9 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Fri, 28 Jun 2024 15:39:24 +0300 Subject: [PATCH 03/15] photo_async dart --- lib/src/photo/photo.dart | 50 +++++-- lib/src/photo/photo_async.dart | 266 +++++++++++++++++++++++++++++++++ 2 files changed, 300 insertions(+), 16 deletions(-) create mode 100644 lib/src/photo/photo_async.dart diff --git a/lib/src/photo/photo.dart b/lib/src/photo/photo.dart index aefb95bf..bd839f95 100644 --- a/lib/src/photo/photo.dart +++ b/lib/src/photo/photo.dart @@ -17,12 +17,15 @@ import '../opencv.g.dart' as cvg; /// https://docs.opencv.org/master/d7/dd6/classcv_1_1MergeMertens.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga79d59aa3cb3a7c664e59a4b5acc1ccb6 class MergeMertens extends CvStruct { - MergeMertens._(cvg.MergeMertensPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { + MergeMertens._(cvg.MergeMertensPtr ptr, [bool attach = true]) + : super.fromPointer(ptr) { if (attach) { 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,12 +39,14 @@ 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); } - static final finalizer = OcvFinalizer(CFFI.addresses.MergeMertens_Close); + static final finalizer = + OcvFinalizer(CFFI.addresses.MergeMertens_Close); void dispose() { finalizer.detach(this); @@ -74,12 +79,15 @@ class MergeMertens extends CvStruct { /// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga2f1fafc885a5d79dbfb3542e08db0244 class AlignMTB extends CvStruct { - AlignMTB._(cvg.AlignMTBPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { + AlignMTB._(cvg.AlignMTBPtr ptr, [bool attach = true]) + : super.fromPointer(ptr) { if (attach) { 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 /// brighter than median luminance and 0 otherwise) and than aligns the resulting @@ -102,13 +110,15 @@ 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); } - static final finalizer = OcvFinalizer(CFFI.addresses.AlignMTB_Close); + static final finalizer = + OcvFinalizer(CFFI.addresses.AlignMTB_Close); void dispose() { finalizer.detach(this); @@ -140,7 +150,8 @@ 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 +159,11 @@ 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 +194,8 @@ 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 +299,8 @@ 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 +316,8 @@ 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 +344,10 @@ 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..dc538c4a --- /dev/null +++ b/lib/src/photo/photo_async.dart @@ -0,0 +1,266 @@ +library cv; + +import 'dart:ffi' as ffi; +import 'dart:typed_data'; +import 'package:ffi/ffi.dart'; +import '../core/base.dart'; +import '../core/mat.dart'; +import '../core/mat_type.dart'; +import '../core/point.dart'; +import '../opencv.g.dart' as cvg; +import './photo.dart'; + +extension MergeMertensAsync on MergeMertens { + static Future emptyNewAsync() async => cvRunAsync( + (callback) => CFFI.MergeMertens_Create_Async(callback), + (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 { + Mat dst = Mat.empty(); + return cvRunAsync0( + (callback) => + CFFI.MergeMertens_Process_Async(ref, src.ref, dst.ref, callback), + (c) => c.complete( + dst.convertTo(MatType.CV_8UC3, alpha: 255.0), + )); + } +} + +extension AlignMTBAsync on AlignMTB { + static Future emptyNewAsync() async => cvRunAsync( + (callback) => CFFI.AlignMTB_Create_Async(callback), + (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, dst) => c.complete(VecMat.fromPointer(dst.cast())), + ); + } +} + +Future colorChangeAsync( + InputArray src, + InputArray mask, { + double redMul = 1.0, + double greenMul = 1.0, + double blueMul = 1.0, +}) async { + Mat dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.ColorChange_Async( + src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul, callback), + (c) => c.complete(dst), + ); +} + +Future seamlessCloneAsync( + InputArray src, + InputArray dst, + InputArray mask, + Point p, + int flags, +) async { + final blend = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.SeamlessClone_Async( + src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags, callback), + (c) => c.complete(blend), + ); +} + +Future illuminationChangeAsync( + InputArray src, + InputArray mask, { + double alpha = 0.2, + double beta = 0.4, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.IlluminationChange_Async( + src.ref, mask.ref, dst.ref, alpha, beta, callback), + (c) => c.complete(dst), + ); +} + +Future textureFlatteningAsync( + InputArray src, + InputArray mask, { + double lowThreshold = 30, + double highThreshold = 45, + int kernelSize = 3, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.TextureFlattening_Async(src.ref, mask.ref, dst.ref, + lowThreshold, highThreshold, kernelSize, callback), + (c) => c.complete(dst), + ); +} + +Future fastNlMeansDenoisingAsync( + InputArray src, { + double h = 3, + int templateWindowSize = 7, + int searchWindowSize = 21, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.FastNlMeansDenoisingWithParams_Async( + src.ref, dst.ref, h, templateWindowSize, searchWindowSize, callback), + (c) => c.complete(dst), + ); +} + +Future fastNlMeansDenoisingColoredAsync( + InputArray src, { + double h = 3, + double hColor = 3, + int templateWindowSize = 7, + int searchWindowSize = 21, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.FastNlMeansDenoisingColoredWithParams_Async(src.ref, + dst.ref, h, hColor, templateWindowSize, searchWindowSize, callback), + (c) => c.complete(dst), + ); +} + +Future fastNlMeansDenoisingColoredMultiAsync( + VecMat srcImgs, + int imgToDenoiseIndex, + int temporalWindowSize, { + double h = 3, + double hColor = 3, + int templateWindowSize = 7, + int searchWindowSize = 21, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.FastNlMeansDenoisingColoredMultiWithParams_Async( + srcImgs.ref, + dst.ref, + imgToDenoiseIndex, + temporalWindowSize, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ), + (c) => c.complete(dst), + ); +} + +Future detailEnhanceAsync( + InputArray src, { + double sigmaS = 10, + double sigmaR = 0.15, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => + CFFI.DetailEnhance_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), + (c) => c.complete(dst), + ); +} + +Future edgePreservingFilterAsync( + InputArray src, { + int flags = 1, + double sigmaS = 60, + double sigmaR = 0.4, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.EdgePreservingFilter_Async( + src.ref, dst.ref, flags, sigmaS, sigmaR, callback), + (c) => c.complete(dst), + ); +} + +Future<(Mat dst1, Mat dst2)> pencilSketchAsync( + InputArray src, { + double sigmaS = 60, + double sigmaR = 0.07, + double shadeFactor = 0.02, +}) async { + final dst1 = Mat.empty(); + final dst2 = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.PencilSketch_Async( + src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor, callback), + (c) => c.complete( + (dst1, dst2), + ), + ); +} + +Future stylizationAsync( + InputArray src, { + double sigmaS = 60, + double sigmaR = 0.45, +}) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => + CFFI.Stylization_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), + (c) => c.complete(dst), + ); +} + +Future inpaintAsync( + InputArray src, + InputArray inpaintMask, + double inpaintRadius, + int flags, +) async { + final dst = Mat.empty(); + + return cvRunAsync0( + (callback) => CFFI.PhotoInpaint_Async( + src.ref, inpaintMask.ref, dst.ref, inpaintRadius, flags, callback), + (c) => c.complete(dst), + ); +} From aec9bd8f55ed4ac0e7a2e2e5e49ba869680ebb81 Mon Sep 17 00:00:00 2001 From: abdelaziz-mahdy Date: Fri, 28 Jun 2024 12:40:22 +0000 Subject: [PATCH 04/15] =?UTF-8?q?dart=20format=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/photo/photo.dart | 50 ++++++++++++---------------------- lib/src/photo/photo_async.dart | 47 ++++++++++++-------------------- 2 files changed, 34 insertions(+), 63 deletions(-) diff --git a/lib/src/photo/photo.dart b/lib/src/photo/photo.dart index bd839f95..c36aae96 100644 --- a/lib/src/photo/photo.dart +++ b/lib/src/photo/photo.dart @@ -17,14 +17,12 @@ import '../opencv.g.dart' as cvg; /// https://docs.opencv.org/master/d7/dd6/classcv_1_1MergeMertens.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga79d59aa3cb3a7c664e59a4b5acc1ccb6 class MergeMertens extends CvStruct { - MergeMertens._(cvg.MergeMertensPtr ptr, [bool attach = true]) - : super.fromPointer(ptr) { + MergeMertens._(cvg.MergeMertensPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { if (attach) { finalizer.attach(this, ptr.cast(), detach: this); } } - factory MergeMertens.fromPointer(cvg.MergeMertensPtr ptr, - [bool attach = true]) => + factory MergeMertens.fromPointer(cvg.MergeMertensPtr ptr, [bool attach = true]) => MergeMertens._(ptr.cast(), attach); factory MergeMertens.empty() { final p = calloc(); @@ -39,14 +37,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); } - static final finalizer = - OcvFinalizer(CFFI.addresses.MergeMertens_Close); + static final finalizer = OcvFinalizer(CFFI.addresses.MergeMertens_Close); void dispose() { finalizer.detach(this); @@ -79,15 +75,13 @@ class MergeMertens extends CvStruct { /// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga2f1fafc885a5d79dbfb3542e08db0244 class AlignMTB extends CvStruct { - AlignMTB._(cvg.AlignMTBPtr ptr, [bool attach = true]) - : super.fromPointer(ptr) { + AlignMTB._(cvg.AlignMTBPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { if (attach) { finalizer.attach(this, ptr.cast(), detach: this); } } - factory AlignMTB.fromPointer(cvg.AlignMTBPtr ptr, - [bool attach = true]) => - AlignMTB._(ptr.cast(), attach); + 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 /// brighter than median luminance and 0 otherwise) and than aligns the resulting @@ -110,15 +104,13 @@ 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); } - static final finalizer = - OcvFinalizer(CFFI.addresses.AlignMTB_Close); + static final finalizer = OcvFinalizer(CFFI.addresses.AlignMTB_Close); void dispose() { finalizer.detach(this); @@ -150,8 +142,7 @@ 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; } @@ -159,11 +150,9 @@ 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; } @@ -194,8 +183,7 @@ 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; } @@ -299,8 +287,7 @@ 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; } @@ -316,8 +303,7 @@ 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); } @@ -344,10 +330,8 @@ 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 index dc538c4a..7b60e345 100644 --- a/lib/src/photo/photo_async.dart +++ b/lib/src/photo/photo_async.dart @@ -13,8 +13,7 @@ import './photo.dart'; extension MergeMertensAsync on MergeMertens { static Future emptyNewAsync() async => cvRunAsync( (callback) => CFFI.MergeMertens_Create_Async(callback), - (c, p) => - c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), ); static Future createAsync({ @@ -29,16 +28,14 @@ extension MergeMertensAsync on MergeMertens { exposureWeight, callback, ), - (c, p) => - c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), ); } Future processAsync(VecMat src) async { Mat dst = Mat.empty(); return cvRunAsync0( - (callback) => - CFFI.MergeMertens_Process_Async(ref, src.ref, dst.ref, callback), + (callback) => CFFI.MergeMertens_Process_Async(ref, src.ref, dst.ref, callback), (c) => c.complete( dst.convertTo(MatType.CV_8UC3, alpha: 255.0), )); @@ -51,11 +48,9 @@ extension AlignMTBAsync on AlignMTB { (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), ); - static Future createAsync( - {int maxBits = 6, int excludeRange = 4, bool cut = true}) async { + static Future createAsync({int maxBits = 6, int excludeRange = 4, bool cut = true}) async { return cvRunAsync( - (callback) => CFFI.AlignMTB_CreateWithParams_Async( - maxBits, excludeRange, cut, callback), + (callback) => CFFI.AlignMTB_CreateWithParams_Async(maxBits, excludeRange, cut, callback), (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), ); } @@ -78,8 +73,7 @@ Future colorChangeAsync( Mat dst = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.ColorChange_Async( - src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul, callback), + (callback) => CFFI.ColorChange_Async(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul, callback), (c) => c.complete(dst), ); } @@ -94,8 +88,7 @@ Future seamlessCloneAsync( final blend = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.SeamlessClone_Async( - src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags, callback), + (callback) => CFFI.SeamlessClone_Async(src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags, callback), (c) => c.complete(blend), ); } @@ -109,8 +102,7 @@ Future illuminationChangeAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.IlluminationChange_Async( - src.ref, mask.ref, dst.ref, alpha, beta, callback), + (callback) => CFFI.IlluminationChange_Async(src.ref, mask.ref, dst.ref, alpha, beta, callback), (c) => c.complete(dst), ); } @@ -125,8 +117,8 @@ Future textureFlatteningAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.TextureFlattening_Async(src.ref, mask.ref, dst.ref, - lowThreshold, highThreshold, kernelSize, callback), + (callback) => CFFI.TextureFlattening_Async( + src.ref, mask.ref, dst.ref, lowThreshold, highThreshold, kernelSize, callback), (c) => c.complete(dst), ); } @@ -156,8 +148,8 @@ Future fastNlMeansDenoisingColoredAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.FastNlMeansDenoisingColoredWithParams_Async(src.ref, - dst.ref, h, hColor, templateWindowSize, searchWindowSize, callback), + (callback) => CFFI.FastNlMeansDenoisingColoredWithParams_Async( + src.ref, dst.ref, h, hColor, templateWindowSize, searchWindowSize, callback), (c) => c.complete(dst), ); } @@ -197,8 +189,7 @@ Future detailEnhanceAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => - CFFI.DetailEnhance_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), + (callback) => CFFI.DetailEnhance_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), (c) => c.complete(dst), ); } @@ -212,8 +203,7 @@ Future edgePreservingFilterAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.EdgePreservingFilter_Async( - src.ref, dst.ref, flags, sigmaS, sigmaR, callback), + (callback) => CFFI.EdgePreservingFilter_Async(src.ref, dst.ref, flags, sigmaS, sigmaR, callback), (c) => c.complete(dst), ); } @@ -228,8 +218,7 @@ Future<(Mat dst1, Mat dst2)> pencilSketchAsync( final dst2 = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.PencilSketch_Async( - src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor, callback), + (callback) => CFFI.PencilSketch_Async(src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor, callback), (c) => c.complete( (dst1, dst2), ), @@ -244,8 +233,7 @@ Future stylizationAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => - CFFI.Stylization_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), + (callback) => CFFI.Stylization_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), (c) => c.complete(dst), ); } @@ -259,8 +247,7 @@ Future inpaintAsync( final dst = Mat.empty(); return cvRunAsync0( - (callback) => CFFI.PhotoInpaint_Async( - src.ref, inpaintMask.ref, dst.ref, inpaintRadius, flags, callback), + (callback) => CFFI.PhotoInpaint_Async(src.ref, inpaintMask.ref, dst.ref, inpaintRadius, flags, callback), (c) => c.complete(dst), ); } From 2faf766882afc9d5a2a1bd95d170e694acd33f77 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:03:55 +0300 Subject: [PATCH 05/15] migrate to mat inside cpp --- lib/src/photo/photo_async.dart | 194 +++++++++++++++++++-------------- src/photo/photo_async.cpp | 109 ++++++++++-------- src/photo/photo_async.h | 32 +++--- 3 files changed, 191 insertions(+), 144 deletions(-) diff --git a/lib/src/photo/photo_async.dart b/lib/src/photo/photo_async.dart index dc538c4a..9f6dfa54 100644 --- a/lib/src/photo/photo_async.dart +++ b/lib/src/photo/photo_async.dart @@ -13,8 +13,7 @@ import './photo.dart'; extension MergeMertensAsync on MergeMertens { static Future emptyNewAsync() async => cvRunAsync( (callback) => CFFI.MergeMertens_Create_Async(callback), - (c, p) => - c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), ); static Future createAsync({ @@ -29,19 +28,15 @@ extension MergeMertensAsync on MergeMertens { exposureWeight, callback, ), - (c, p) => - c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), ); } Future processAsync(VecMat src) async { - Mat dst = Mat.empty(); - return cvRunAsync0( - (callback) => - CFFI.MergeMertens_Process_Async(ref, src.ref, dst.ref, callback), - (c) => c.complete( - dst.convertTo(MatType.CV_8UC3, alpha: 255.0), - )); + return cvRunAsync( + (callback) => CFFI.MergeMertens_Process_Async(ref, src.ref, callback), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + ); } } @@ -51,11 +46,14 @@ extension AlignMTBAsync on AlignMTB { (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), ); - static Future createAsync( - {int maxBits = 6, int excludeRange = 4, bool cut = true}) async { + static Future createAsync({int maxBits = 6, int excludeRange = 4, bool cut = true}) async { return cvRunAsync( (callback) => CFFI.AlignMTB_CreateWithParams_Async( - maxBits, excludeRange, cut, callback), + maxBits, + excludeRange, + cut, + callback, + ), (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), ); } @@ -63,7 +61,7 @@ extension AlignMTBAsync on AlignMTB { Future processAsync(VecMat src) async { return cvRunAsync( (callback) => CFFI.AlignMTB_Process_Async(ref, src.ref, callback), - (c, dst) => c.complete(VecMat.fromPointer(dst.cast())), + (c, pdst) => c.complete(VecMat.fromPointer(pdst.cast())), ); } } @@ -75,12 +73,16 @@ Future colorChangeAsync( double greenMul = 1.0, double blueMul = 1.0, }) async { - Mat dst = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.ColorChange_Async( - src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul, callback), - (c) => c.complete(dst), + src.ref, + mask.ref, + redMul, + greenMul, + blueMul, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -91,12 +93,16 @@ Future seamlessCloneAsync( Point p, int flags, ) async { - final blend = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.SeamlessClone_Async( - src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags, callback), - (c) => c.complete(blend), + src.ref, + dst.ref, + mask.ref, + p.ref, + flags, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -106,12 +112,15 @@ Future illuminationChangeAsync( double alpha = 0.2, double beta = 0.4, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.IlluminationChange_Async( - src.ref, mask.ref, dst.ref, alpha, beta, callback), - (c) => c.complete(dst), + src.ref, + mask.ref, + alpha, + beta, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -122,12 +131,16 @@ Future textureFlatteningAsync( double highThreshold = 45, int kernelSize = 3, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( - (callback) => CFFI.TextureFlattening_Async(src.ref, mask.ref, dst.ref, - lowThreshold, highThreshold, kernelSize, callback), - (c) => c.complete(dst), + return cvRunAsync( + (callback) => CFFI.TextureFlattening_Async( + src.ref, + mask.ref, + lowThreshold, + highThreshold, + kernelSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -137,12 +150,15 @@ Future fastNlMeansDenoisingAsync( int templateWindowSize = 7, int searchWindowSize = 21, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.FastNlMeansDenoisingWithParams_Async( - src.ref, dst.ref, h, templateWindowSize, searchWindowSize, callback), - (c) => c.complete(dst), + src.ref, + h, + templateWindowSize, + searchWindowSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -153,12 +169,16 @@ Future fastNlMeansDenoisingColoredAsync( int templateWindowSize = 7, int searchWindowSize = 21, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( - (callback) => CFFI.FastNlMeansDenoisingColoredWithParams_Async(src.ref, - dst.ref, h, hColor, templateWindowSize, searchWindowSize, callback), - (c) => c.complete(dst), + return cvRunAsync( + (callback) => CFFI.FastNlMeansDenoisingColoredWithParams_Async( + src.ref, + h, + hColor, + templateWindowSize, + searchWindowSize, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -171,12 +191,9 @@ Future fastNlMeansDenoisingColoredMultiAsync( int templateWindowSize = 7, int searchWindowSize = 21, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.FastNlMeansDenoisingColoredMultiWithParams_Async( srcImgs.ref, - dst.ref, imgToDenoiseIndex, temporalWindowSize, h, @@ -185,7 +202,7 @@ Future fastNlMeansDenoisingColoredMultiAsync( searchWindowSize, callback, ), - (c) => c.complete(dst), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -194,12 +211,14 @@ Future detailEnhanceAsync( double sigmaS = 10, double sigmaR = 0.15, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( - (callback) => - CFFI.DetailEnhance_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), - (c) => c.complete(dst), + return cvRunAsync( + (callback) => CFFI.DetailEnhance_Async( + src.ref, + sigmaS, + sigmaR, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -209,12 +228,15 @@ Future edgePreservingFilterAsync( double sigmaS = 60, double sigmaR = 0.4, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.EdgePreservingFilter_Async( - src.ref, dst.ref, flags, sigmaS, sigmaR, callback), - (c) => c.complete(dst), + src.ref, + flags, + sigmaS, + sigmaR, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -224,14 +246,19 @@ Future<(Mat dst1, Mat dst2)> pencilSketchAsync( double sigmaR = 0.07, double shadeFactor = 0.02, }) async { - final dst1 = Mat.empty(); - final dst2 = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.PencilSketch_Async( - src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor, callback), - (c) => c.complete( - (dst1, dst2), + src.ref, + sigmaS, + sigmaR, + shadeFactor, + callback, + ), + (c, pdst1, pdst2) => c.complete( + ( + Mat.fromPointer(pdst1.cast()), + Mat.fromPointer(pdst2.cast()) + ), ), ); } @@ -241,12 +268,14 @@ Future stylizationAsync( double sigmaS = 60, double sigmaR = 0.45, }) async { - final dst = Mat.empty(); - - return cvRunAsync0( - (callback) => - CFFI.Stylization_Async(src.ref, dst.ref, sigmaS, sigmaR, callback), - (c) => c.complete(dst), + return cvRunAsync( + (callback) => CFFI.Stylization_Async( + src.ref, + sigmaS, + sigmaR, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } @@ -256,11 +285,14 @@ Future inpaintAsync( double inpaintRadius, int flags, ) async { - final dst = Mat.empty(); - - return cvRunAsync0( + return cvRunAsync( (callback) => CFFI.PhotoInpaint_Async( - src.ref, inpaintMask.ref, dst.ref, inpaintRadius, flags, callback), - (c) => c.complete(dst), + src.ref, + inpaintMask.ref, + inpaintRadius, + flags, + callback, + ), + (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), ); } diff --git a/src/photo/photo_async.cpp b/src/photo/photo_async.cpp index b2b4e001..9be308b2 100644 --- a/src/photo/photo_async.cpp +++ b/src/photo/photo_async.cpp @@ -3,79 +3,89 @@ #include "core/types.h" // Asynchronous functions for ColorChange -CvStatus *ColorChange_Async(Mat src, Mat mask, Mat dst, float red_mul, float green_mul, float blue_mul, CvCallback_0 callback) { +CvStatus *ColorChange_Async(Mat src, Mat mask, float red_mul, float green_mul, float blue_mul, CvCallback_1 callback) { BEGIN_WRAP - cv::colorChange(*src.ptr, *mask.ptr, *dst.ptr, red_mul, green_mul, blue_mul); - callback(); + 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, Mat blend, int flags, CvCallback_0 callback) { +CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, int flags, CvCallback_1 callback) { BEGIN_WRAP - cv::seamlessClone(*src.ptr, *dst.ptr, *mask.ptr, cv::Point(p.x, p.y), *blend.ptr, flags); - callback(); + 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, Mat dst, float alpha, float beta, CvCallback_0 callback) { +CvStatus *IlluminationChange_Async(Mat src, Mat mask, float alpha, float beta, CvCallback_1 callback) { BEGIN_WRAP - cv::illuminationChange(*src.ptr, *mask.ptr, *dst.ptr, alpha, beta); - callback(); + 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, Mat dst, float low_threshold, float high_threshold, int kernel_size, CvCallback_0 callback) { +CvStatus *TextureFlattening_Async(Mat src, Mat mask, float low_threshold, float high_threshold, int kernel_size, CvCallback_1 callback) { BEGIN_WRAP - cv::textureFlattening(*src.ptr, *mask.ptr, *dst.ptr, low_threshold, high_threshold, kernel_size); - callback(); + 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, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_0 callback) { +CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_1 callback) { BEGIN_WRAP - cv::fastNlMeansDenoisingColoredMulti(*src.ptr, *dst.ptr, imgToDenoiseIndex, temporalWindowSize); - callback(); + cv::Mat _dst; + cv::fastNlMeansDenoisingColoredMulti(*src.ptr, _dst, imgToDenoiseIndex, temporalWindowSize); + callback(new Mat{new cv::Mat(_dst)}); END_WRAP } -CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback) { +CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) { BEGIN_WRAP - cv::fastNlMeansDenoisingColoredMulti(*src.ptr, *dst.ptr, imgToDenoiseIndex, temporalWindowSize, h, hColor, templateWindowSize, searchWindowSize); - callback(); + 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, Mat dst, CvCallback_0 callback) { +CvStatus *FastNlMeansDenoising_Async(Mat src, CvCallback_1 callback) { BEGIN_WRAP - cv::fastNlMeansDenoising(*src.ptr, *dst.ptr); - callback(); + cv::Mat _dst; + cv::fastNlMeansDenoising(*src.ptr, _dst); + callback(new Mat{new cv::Mat(_dst)}); END_WRAP } -CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize, CvCallback_0 callback) { +CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, float h, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) { BEGIN_WRAP - cv::fastNlMeansDenoising(*src.ptr, *dst.ptr, h, templateWindowSize, searchWindowSize); - callback(); + 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, Mat dst, CvCallback_0 callback) { +CvStatus *FastNlMeansDenoisingColored_Async(Mat src, CvCallback_1 callback) { BEGIN_WRAP - cv::fastNlMeansDenoisingColored(*src.ptr, *dst.ptr); - callback(); + cv::Mat _dst; + cv::fastNlMeansDenoisingColored(*src.ptr, _dst); + callback(new Mat{new cv::Mat(_dst)}); END_WRAP } -CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, Mat dst, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback) { +CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) { BEGIN_WRAP - cv::fastNlMeansDenoisingColored(*src.ptr, *dst.ptr, h, hColor, templateWindowSize, searchWindowSize); - callback(); + cv::Mat _dst; + cv::fastNlMeansDenoisingColored(*src.ptr, _dst, h, hColor, templateWindowSize, searchWindowSize); + callback(new Mat{new cv::Mat(_dst)}); END_WRAP } @@ -92,10 +102,11 @@ CvStatus *MergeMertens_CreateWithParams_Async(float contrast_weight, float satur END_WRAP } -CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, Mat dst, CvCallback_0 callback) { +CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, CvCallback_1 callback) { BEGIN_WRAP - (*b.ptr)->process(*src.ptr, *dst.ptr); - callback(); + cv::Mat _dst; + (*b.ptr)->process(*src.ptr, _dst); + callback(new Mat{new cv::Mat(_dst)}); END_WRAP } @@ -121,41 +132,45 @@ CvStatus *AlignMTB_Process_Async(AlignMTB b, VecMat src, CvCallback_1 callback) } // Asynchronous functions for DetailEnhance -CvStatus *DetailEnhance_Async(Mat src, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback) { +CvStatus *DetailEnhance_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback) { BEGIN_WRAP - cv::detailEnhance(*src.ptr, *dst.ptr, sigma_s, sigma_r); - callback(); + 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, Mat dst, int filter, float sigma_s, float sigma_r, CvCallback_0 callback) { +CvStatus *EdgePreservingFilter_Async(Mat src, int filter, float sigma_s, float sigma_r, CvCallback_1 callback) { BEGIN_WRAP - cv::edgePreservingFilter(*src.ptr, *dst.ptr, filter, sigma_s, sigma_r); - callback(); + 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, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_0 callback) { +CvStatus *PencilSketch_Async(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_1 callback) { BEGIN_WRAP cv::pencilSketch(*src.ptr, *dst1.ptr, *dst2.ptr, sigma_s, sigma_r, shade_factor); - callback(); + callback(new Mat{new cv::Mat(*dst1.ptr)}, new Mat{new cv::Mat(*dst2.ptr)}); END_WRAP } // Asynchronous functions for Stylization -CvStatus *Stylization_Async(Mat src, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback) { +CvStatus *Stylization_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback) { BEGIN_WRAP - cv::stylization(*src.ptr, *dst.ptr, sigma_s, sigma_r); - callback(); + 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, Mat dst, float inpaint_radius, int algorithm_type, CvCallback_0 callback) { +CvStatus *PhotoInpaint_Async(Mat src, Mat mask, float inpaint_radius, int algorithm_type, CvCallback_1 callback) { BEGIN_WRAP - cv::inpaint(*src.ptr, *mask.ptr, *dst.ptr, inpaint_radius, algorithm_type); - callback(); + 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 index 5ac2c448..29585805 100644 --- a/src/photo/photo_async.h +++ b/src/photo/photo_async.h @@ -11,33 +11,33 @@ extern "C" { #endif // Asynchronous functions for ColorChange -CvStatus *ColorChange_Async(Mat src, Mat mask, Mat dst, float red_mul, float green_mul, float blue_mul, CvCallback_0 callback); +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, Mat blend, int flags, CvCallback_0 callback); +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, Mat dst, float alpha, float beta, CvCallback_0 callback); +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, Mat dst, float low_threshold, float high_threshold, int kernel_size, CvCallback_0 callback); +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, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_0 callback); -CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, Mat dst, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback); +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, Mat dst, CvCallback_0 callback); -CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, Mat dst, float h, int templateWindowSize, int searchWindowSize, CvCallback_0 callback); +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, Mat dst, CvCallback_0 callback); -CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, Mat dst, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_0 callback); +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, Mat dst, CvCallback_0 callback); +CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, CvCallback_1 callback); // Asynchronous functions for AlignMTB CvStatus *AlignMTB_Create_Async(CvCallback_1 callback); @@ -45,19 +45,19 @@ CvStatus *AlignMTB_CreateWithParams_Async(int max_bits, int exclude_range, bool CvStatus *AlignMTB_Process_Async(AlignMTB b, VecMat src, CvCallback_1 callback); // Asynchronous functions for DetailEnhance -CvStatus *DetailEnhance_Async(Mat src, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback); +CvStatus *DetailEnhance_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 callback); // Asynchronous functions for EdgePreservingFilter -CvStatus *EdgePreservingFilter_Async(Mat src, Mat dst, int filter, float sigma_s, float sigma_r, CvCallback_0 callback); +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, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_0 callback); +CvStatus *PencilSketch_Async(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_1 callback); // Asynchronous functions for Stylization -CvStatus *Stylization_Async(Mat src, Mat dst, float sigma_s, float sigma_r, CvCallback_0 callback); +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, Mat dst, float inpaint_radius, int algorithm_type, CvCallback_0 callback); +CvStatus *PhotoInpaint_Async(Mat src, Mat mask, float inpaint_radius, int algorithm_type, CvCallback_1 callback); #ifdef __cplusplus } From 4c21932f50a665371147537fe60e78ef05519319 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:07:44 +0300 Subject: [PATCH 06/15] fix cpp mat --- lib/src/opencv.g.dart | 171 +++++++++++++-------------------- lib/src/photo/photo_async.dart | 13 +-- src/photo/photo_async.cpp | 73 +++++++++----- src/photo/photo_async.h | 73 +++++++------- 4 files changed, 157 insertions(+), 173 deletions(-) diff --git a/lib/src/opencv.g.dart b/lib/src/opencv.g.dart index c3e33124..2ae1b92b 100644 --- a/lib/src/opencv.g.dart +++ b/lib/src/opencv.g.dart @@ -3915,16 +3915,14 @@ class CvNative { ffi.Pointer ColorChange_Async( Mat src, Mat mask, - Mat dst, double red_mul, double green_mul, double blue_mul, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _ColorChange_Async( src, mask, - dst, red_mul, green_mul, blue_mul, @@ -3934,11 +3932,11 @@ class CvNative { late final _ColorChange_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, - ffi.Float, CvCallback_0)>>('ColorChange_Async'); + 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, Mat, double, double, double, CvCallback_0)>(); + Mat, Mat, double, double, double, CvCallback_1)>(); ffi.Pointer CompareHist( Mat hist1, @@ -4325,14 +4323,12 @@ class CvNative { ffi.Pointer DetailEnhance_Async( Mat src, - Mat dst, double sigma_s, double sigma_r, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _DetailEnhance_Async( src, - dst, sigma_s, sigma_r, callback, @@ -4341,10 +4337,10 @@ class CvNative { late final _DetailEnhance_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, - CvCallback_0)>>('DetailEnhance_Async'); + ffi.Pointer Function( + Mat, ffi.Float, ffi.Float, CvCallback_1)>>('DetailEnhance_Async'); late final _DetailEnhance_Async = _DetailEnhance_AsyncPtr.asFunction< - ffi.Pointer Function(Mat, Mat, double, double, CvCallback_0)>(); + ffi.Pointer Function(Mat, double, double, CvCallback_1)>(); ffi.Pointer Dilate( Mat src, @@ -4731,15 +4727,13 @@ class CvNative { ffi.Pointer EdgePreservingFilter_Async( Mat src, - Mat dst, int filter, double sigma_s, double sigma_r, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _EdgePreservingFilter_Async( src, - dst, filter, sigma_s, sigma_r, @@ -4749,12 +4743,12 @@ class CvNative { late final _EdgePreservingFilter_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, ffi.Int, ffi.Float, - ffi.Float, CvCallback_0)>>('EdgePreservingFilter_Async'); + 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, Mat, int, double, double, CvCallback_0)>(); + Mat, int, double, double, CvCallback_1)>(); ffi.Pointer Ellipse( Mat img, @@ -6108,18 +6102,16 @@ class CvNative { ffi.Pointer FastNlMeansDenoisingColoredMultiWithParams_Async( VecMat src, - Mat dst, int imgToDenoiseIndex, int temporalWindowSize, double h, double hColor, int templateWindowSize, int searchWindowSize, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _FastNlMeansDenoisingColoredMultiWithParams_Async( src, - dst, imgToDenoiseIndex, temporalWindowSize, h, @@ -6132,24 +6124,22 @@ class CvNative { late final _FastNlMeansDenoisingColoredMultiWithParams_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(VecMat, Mat, ffi.Int, ffi.Int, - ffi.Float, ffi.Float, ffi.Int, ffi.Int, CvCallback_0)>>( + 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, Mat, int, int, double, double, int, int, CvCallback_0)>(); + VecMat, int, int, double, double, int, int, CvCallback_1)>(); ffi.Pointer FastNlMeansDenoisingColoredMulti_Async( VecMat src, - Mat dst, int imgToDenoiseIndex, int temporalWindowSize, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _FastNlMeansDenoisingColoredMulti_Async( src, - dst, imgToDenoiseIndex, temporalWindowSize, callback, @@ -6158,12 +6148,11 @@ class CvNative { late final _FastNlMeansDenoisingColoredMulti_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(VecMat, Mat, ffi.Int, ffi.Int, - CvCallback_0)>>('FastNlMeansDenoisingColoredMulti_Async'); + ffi.Pointer Function(VecMat, ffi.Int, ffi.Int, + CvCallback_1)>>('FastNlMeansDenoisingColoredMulti_Async'); late final _FastNlMeansDenoisingColoredMulti_Async = _FastNlMeansDenoisingColoredMulti_AsyncPtr.asFunction< - ffi.Pointer Function( - VecMat, Mat, int, int, CvCallback_0)>(); + ffi.Pointer Function(VecMat, int, int, CvCallback_1)>(); ffi.Pointer FastNlMeansDenoisingColoredWithParams( Mat src, @@ -6193,16 +6182,14 @@ class CvNative { ffi.Pointer FastNlMeansDenoisingColoredWithParams_Async( Mat src, - Mat dst, double h, double hColor, int templateWindowSize, int searchWindowSize, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _FastNlMeansDenoisingColoredWithParams_Async( src, - dst, h, hColor, templateWindowSize, @@ -6214,37 +6201,34 @@ class CvNative { late final _FastNlMeansDenoisingColoredWithParams_AsyncPtr = _lookup< ffi.NativeFunction< ffi.Pointer Function( - Mat, Mat, ffi.Float, ffi.Float, ffi.Int, ffi.Int, - CvCallback_0)>>('FastNlMeansDenoisingColoredWithParams_Async'); + CvCallback_1)>>('FastNlMeansDenoisingColoredWithParams_Async'); late final _FastNlMeansDenoisingColoredWithParams_Async = _FastNlMeansDenoisingColoredWithParams_AsyncPtr.asFunction< ffi.Pointer Function( - Mat, Mat, double, double, int, int, CvCallback_0)>(); + Mat, double, double, int, int, CvCallback_1)>(); ffi.Pointer FastNlMeansDenoisingColored_Async( Mat src, - Mat dst, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _FastNlMeansDenoisingColored_Async( src, - dst, callback, ); } late final _FastNlMeansDenoisingColored_AsyncPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - Mat, Mat, CvCallback_0)>>('FastNlMeansDenoisingColored_Async'); + ffi + .NativeFunction Function(Mat, CvCallback_1)>>( + 'FastNlMeansDenoisingColored_Async'); late final _FastNlMeansDenoisingColored_Async = _FastNlMeansDenoisingColored_AsyncPtr.asFunction< - ffi.Pointer Function(Mat, Mat, CvCallback_0)>(); + ffi.Pointer Function(Mat, CvCallback_1)>(); ffi.Pointer FastNlMeansDenoisingWithParams( Mat src, @@ -6272,15 +6256,13 @@ class CvNative { ffi.Pointer FastNlMeansDenoisingWithParams_Async( Mat src, - Mat dst, double h, int templateWindowSize, int searchWindowSize, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _FastNlMeansDenoisingWithParams_Async( src, - dst, h, templateWindowSize, searchWindowSize, @@ -6290,31 +6272,29 @@ class CvNative { late final _FastNlMeansDenoisingWithParams_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Int, ffi.Int, - CvCallback_0)>>('FastNlMeansDenoisingWithParams_Async'); + 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, Mat, double, int, int, CvCallback_0)>(); + Mat, double, int, int, CvCallback_1)>(); ffi.Pointer FastNlMeansDenoising_Async( Mat src, - Mat dst, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _FastNlMeansDenoising_Async( src, - dst, callback, ); } late final _FastNlMeansDenoising_AsyncPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - Mat, Mat, CvCallback_0)>>('FastNlMeansDenoising_Async'); + ffi + .NativeFunction Function(Mat, CvCallback_1)>>( + 'FastNlMeansDenoising_Async'); late final _FastNlMeansDenoising_Async = _FastNlMeansDenoising_AsyncPtr - .asFunction Function(Mat, Mat, CvCallback_0)>(); + .asFunction Function(Mat, CvCallback_1)>(); ffi.Pointer FillPoly( Mat img, @@ -9083,15 +9063,13 @@ class CvNative { ffi.Pointer IlluminationChange_Async( Mat src, Mat mask, - Mat dst, double alpha, double beta, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _IlluminationChange_Async( src, mask, - dst, alpha, beta, callback, @@ -9100,12 +9078,12 @@ class CvNative { late final _IlluminationChange_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, - CvCallback_0)>>('IlluminationChange_Async'); + 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, Mat, double, double, CvCallback_0)>(); + Mat, Mat, double, double, CvCallback_1)>(); ffi.Pointer Image_IMDecode( VecUChar buf, @@ -15945,25 +15923,22 @@ class CvNative { ffi.Pointer MergeMertens_Process_Async( MergeMertens b, VecMat src, - Mat dst, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _MergeMertens_Process_Async( b, src, - dst, callback, ); } late final _MergeMertens_Process_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(MergeMertens, VecMat, Mat, - CvCallback_0)>>('MergeMertens_Process_Async'); + ffi.Pointer Function(MergeMertens, VecMat, + CvCallback_1)>>('MergeMertens_Process_Async'); late final _MergeMertens_Process_Async = _MergeMertens_Process_AsyncPtr.asFunction< - ffi.Pointer Function( - MergeMertens, VecMat, Mat, CvCallback_0)>(); + ffi.Pointer Function(MergeMertens, VecMat, CvCallback_1)>(); ffi.Pointer MinAreaRect( VecPoint pts, @@ -17772,17 +17747,13 @@ class CvNative { ffi.Pointer PencilSketch_Async( Mat src, - Mat dst1, - Mat dst2, double sigma_s, double sigma_r, double shade_factor, - CvCallback_0 callback, + CvCallback_2 callback, ) { return _PencilSketch_Async( src, - dst1, - dst2, sigma_s, sigma_r, shade_factor, @@ -17792,11 +17763,11 @@ class CvNative { late final _PencilSketch_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, - ffi.Float, CvCallback_0)>>('PencilSketch_Async'); + 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, Mat, Mat, double, double, double, CvCallback_0)>(); + Mat, double, double, double, CvCallback_2)>(); ffi.Pointer PhaseCorrelate( Mat src1, @@ -17869,15 +17840,13 @@ class CvNative { ffi.Pointer PhotoInpaint_Async( Mat src, Mat mask, - Mat dst, double inpaint_radius, int algorithm_type, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _PhotoInpaint_Async( src, mask, - dst, inpaint_radius, algorithm_type, callback, @@ -17886,11 +17855,10 @@ class CvNative { late final _PhotoInpaint_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Int, - CvCallback_0)>>('PhotoInpaint_Async'); + 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, Mat, double, int, CvCallback_0)>(); + ffi.Pointer Function(Mat, Mat, double, int, CvCallback_1)>(); ffi.Pointer PointPolygonTest( VecPoint pts, @@ -19679,19 +19647,15 @@ class CvNative { ffi.Pointer SeamlessClone_Async( Mat src, - Mat dst, Mat mask, Point p, - Mat blend, int flags, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _SeamlessClone_Async( src, - dst, mask, p, - blend, flags, callback, ); @@ -19699,11 +19663,10 @@ class CvNative { late final _SeamlessClone_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, Mat, Point, Mat, ffi.Int, - CvCallback_0)>>('SeamlessClone_Async'); + ffi.Pointer Function( + Mat, Mat, Point, ffi.Int, CvCallback_1)>>('SeamlessClone_Async'); late final _SeamlessClone_Async = _SeamlessClone_AsyncPtr.asFunction< - ffi.Pointer Function( - Mat, Mat, Mat, Point, Mat, int, CvCallback_0)>(); + ffi.Pointer Function(Mat, Mat, Point, int, CvCallback_1)>(); ffi.Pointer SepFilter2D( Mat src, @@ -20933,14 +20896,12 @@ class CvNative { ffi.Pointer Stylization_Async( Mat src, - Mat dst, double sigma_s, double sigma_r, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _Stylization_Async( src, - dst, sigma_s, sigma_r, callback, @@ -20949,10 +20910,10 @@ class CvNative { late final _Stylization_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, ffi.Float, ffi.Float, - CvCallback_0)>>('Stylization_Async'); + ffi.Pointer Function( + Mat, ffi.Float, ffi.Float, CvCallback_1)>>('Stylization_Async'); late final _Stylization_Async = _Stylization_AsyncPtr.asFunction< - ffi.Pointer Function(Mat, Mat, double, double, CvCallback_0)>(); + ffi.Pointer Function(Mat, double, double, CvCallback_1)>(); void Subdiv2D_Close( Subdiv2DPtr self, @@ -21731,16 +21692,14 @@ class CvNative { ffi.Pointer TextureFlattening_Async( Mat src, Mat mask, - Mat dst, double low_threshold, double high_threshold, int kernel_size, - CvCallback_0 callback, + CvCallback_1 callback, ) { return _TextureFlattening_Async( src, mask, - dst, low_threshold, high_threshold, kernel_size, @@ -21750,11 +21709,11 @@ class CvNative { late final _TextureFlattening_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Mat, Mat, Mat, ffi.Float, ffi.Float, - ffi.Int, CvCallback_0)>>('TextureFlattening_Async'); + 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, Mat, double, double, int, CvCallback_0)>(); + Mat, Mat, double, double, int, CvCallback_1)>(); ffi.Pointer TheRNG( ffi.Pointer rval, diff --git a/lib/src/photo/photo_async.dart b/lib/src/photo/photo_async.dart index 9f6dfa54..84665f8e 100644 --- a/lib/src/photo/photo_async.dart +++ b/lib/src/photo/photo_async.dart @@ -13,7 +13,8 @@ import './photo.dart'; extension MergeMertensAsync on MergeMertens { static Future emptyNewAsync() async => cvRunAsync( (callback) => CFFI.MergeMertens_Create_Async(callback), - (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => + c.complete(MergeMertens.fromPointer(p.cast())), ); static Future createAsync({ @@ -28,7 +29,8 @@ extension MergeMertensAsync on MergeMertens { exposureWeight, callback, ), - (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => + c.complete(MergeMertens.fromPointer(p.cast())), ); } @@ -46,7 +48,8 @@ extension AlignMTBAsync on AlignMTB { (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), ); - static Future createAsync({int maxBits = 6, int excludeRange = 4, bool cut = true}) async { + static Future createAsync( + {int maxBits = 6, int excludeRange = 4, bool cut = true}) async { return cvRunAsync( (callback) => CFFI.AlignMTB_CreateWithParams_Async( maxBits, @@ -88,7 +91,6 @@ Future colorChangeAsync( Future seamlessCloneAsync( InputArray src, - InputArray dst, InputArray mask, Point p, int flags, @@ -96,7 +98,6 @@ Future seamlessCloneAsync( return cvRunAsync( (callback) => CFFI.SeamlessClone_Async( src.ref, - dst.ref, mask.ref, p.ref, flags, @@ -246,7 +247,7 @@ Future<(Mat dst1, Mat dst2)> pencilSketchAsync( double sigmaR = 0.07, double shadeFactor = 0.02, }) async { - return cvRunAsync( + return cvRunAsync2( (callback) => CFFI.PencilSketch_Async( src.ref, sigmaS, diff --git a/src/photo/photo_async.cpp b/src/photo/photo_async.cpp index 9be308b2..a732e922 100644 --- a/src/photo/photo_async.cpp +++ b/src/photo/photo_async.cpp @@ -3,7 +3,8 @@ #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) { +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); @@ -12,16 +13,19 @@ CvStatus *ColorChange_Async(Mat src, Mat mask, float red_mul, float green_mul, f } // Asynchronous functions for SeamlessClone -CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, int flags, CvCallback_1 callback) { +CvStatus *SeamlessClone_Async(Mat src, Mat mask, Point p, int flags, CvCallback_2 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)}); + cv::Mat _dst; + cv::seamlessClone(*src.ptr, _dst, *mask.ptr, cv::Point(p.x, p.y), _blend, flags); + callback(new Mat{new cv::Mat(_blend)}, 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) { +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); @@ -30,7 +34,8 @@ CvStatus *IlluminationChange_Async(Mat src, Mat mask, float alpha, float beta, C } // Asynchronous functions for TextureFlattening -CvStatus *TextureFlattening_Async(Mat src, Mat mask, float low_threshold, float high_threshold, int kernel_size, CvCallback_1 callback) { +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); @@ -39,7 +44,8 @@ CvStatus *TextureFlattening_Async(Mat src, Mat mask, float low_threshold, float } // Asynchronous functions for FastNlMeansDenoisingColoredMulti -CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_1 callback) { +CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, CvCallback_1 callback) +{ BEGIN_WRAP cv::Mat _dst; cv::fastNlMeansDenoisingColoredMulti(*src.ptr, _dst, imgToDenoiseIndex, temporalWindowSize); @@ -47,7 +53,8 @@ CvStatus *FastNlMeansDenoisingColoredMulti_Async(VecMat src, int imgToDenoiseInd END_WRAP } -CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, int imgToDenoiseIndex, int temporalWindowSize, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) { +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); @@ -56,7 +63,8 @@ CvStatus *FastNlMeansDenoisingColoredMultiWithParams_Async(VecMat src, int imgTo } // Asynchronous functions for FastNlMeansDenoising -CvStatus *FastNlMeansDenoising_Async(Mat src, CvCallback_1 callback) { +CvStatus *FastNlMeansDenoising_Async(Mat src, CvCallback_1 callback) +{ BEGIN_WRAP cv::Mat _dst; cv::fastNlMeansDenoising(*src.ptr, _dst); @@ -64,7 +72,8 @@ CvStatus *FastNlMeansDenoising_Async(Mat src, CvCallback_1 callback) { END_WRAP } -CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, float h, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) { +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); @@ -73,7 +82,8 @@ CvStatus *FastNlMeansDenoisingWithParams_Async(Mat src, float h, int templateWin } // Asynchronous functions for FastNlMeansDenoisingColored -CvStatus *FastNlMeansDenoisingColored_Async(Mat src, CvCallback_1 callback) { +CvStatus *FastNlMeansDenoisingColored_Async(Mat src, CvCallback_1 callback) +{ BEGIN_WRAP cv::Mat _dst; cv::fastNlMeansDenoisingColored(*src.ptr, _dst); @@ -81,7 +91,8 @@ CvStatus *FastNlMeansDenoisingColored_Async(Mat src, CvCallback_1 callback) { END_WRAP } -CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, float h, float hColor, int templateWindowSize, int searchWindowSize, CvCallback_1 callback) { +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); @@ -90,19 +101,22 @@ CvStatus *FastNlMeansDenoisingColoredWithParams_Async(Mat src, float h, float hC } // Asynchronous functions for MergeMertens -CvStatus *MergeMertens_Create_Async(CvCallback_1 callback) { +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) { +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) { +CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, CvCallback_1 callback) +{ BEGIN_WRAP cv::Mat _dst; (*b.ptr)->process(*src.ptr, _dst); @@ -111,19 +125,22 @@ CvStatus *MergeMertens_Process_Async(MergeMertens b, VecMat src, CvCallback_1 ca } // Asynchronous functions for AlignMTB -CvStatus *AlignMTB_Create_Async(CvCallback_1 callback) { +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) { +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) { +CvStatus *AlignMTB_Process_Async(AlignMTB b, VecMat src, CvCallback_1 callback) +{ BEGIN_WRAP auto vec = std::vector(); (*b.ptr)->process(*src.ptr, vec); @@ -132,7 +149,8 @@ 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) { +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); @@ -141,7 +159,8 @@ CvStatus *DetailEnhance_Async(Mat src, float sigma_s, float sigma_r, CvCallback_ } // Asynchronous functions for EdgePreservingFilter -CvStatus *EdgePreservingFilter_Async(Mat src, int filter, float sigma_s, float sigma_r, CvCallback_1 callback) { +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); @@ -150,15 +169,18 @@ CvStatus *EdgePreservingFilter_Async(Mat src, int filter, float sigma_s, float s } // Asynchronous functions for PencilSketch -CvStatus *PencilSketch_Async(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, CvCallback_1 callback) { +CvStatus *PencilSketch_Async(Mat src, float sigma_s, float sigma_r, float shade_factor, CvCallback_2 callback) +{ BEGIN_WRAP - cv::pencilSketch(*src.ptr, *dst1.ptr, *dst2.ptr, sigma_s, sigma_r, shade_factor); - callback(new Mat{new cv::Mat(*dst1.ptr)}, new Mat{new cv::Mat(*dst2.ptr)}); + 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) { +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); @@ -167,7 +189,8 @@ CvStatus *Stylization_Async(Mat src, float sigma_s, float sigma_r, CvCallback_1 } // Asynchronous functions for PhotoInpaint -CvStatus *PhotoInpaint_Async(Mat src, Mat mask, float inpaint_radius, int algorithm_type, CvCallback_1 callback) { +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); diff --git a/src/photo/photo_async.h b/src/photo/photo_async.h index 29585805..5dfbf82f 100644 --- a/src/photo/photo_async.h +++ b/src/photo/photo_async.h @@ -7,57 +7,58 @@ #ifdef __cplusplus #include -extern "C" { +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 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 SeamlessClone + CvStatus *SeamlessClone_Async(Mat src, 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 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 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 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 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 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 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 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 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 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, Mat dst1, Mat dst2, float sigma_s, float sigma_r, float shade_factor, 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 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); + // Asynchronous functions for PhotoInpaint + CvStatus *PhotoInpaint_Async(Mat src, Mat mask, float inpaint_radius, int algorithm_type, CvCallback_1 callback); #ifdef __cplusplus } From b41921c0479b181a0d95e78659ecf8a43941c24d Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:22:53 +0300 Subject: [PATCH 07/15] fixing params --- lib/src/dnn/dnn_async.dart | 7 +- lib/src/objdetect/objdetect_async.dart | 20 +-- lib/src/opencv.g.dart | 38 ++--- lib/src/photo/photo.dart | 24 +-- lib/src/photo/photo_async.dart | 10 +- lib/src/stitching/stitching.dart | 4 +- lib/src/stitching/stitching_async.dart | 214 +++++++++++++++++++++++++ src/stitching/stitching_async.cpp | 96 +++++++---- src/stitching/stitching_async.h | 8 +- 9 files changed, 328 insertions(+), 93 deletions(-) create mode 100644 lib/src/stitching/stitching_async.dart diff --git a/lib/src/dnn/dnn_async.dart b/lib/src/dnn/dnn_async.dart index a8d6c008..7159390e 100644 --- a/lib/src/dnn/dnn_async.dart +++ b/lib/src/dnn/dnn_async.dart @@ -2,8 +2,8 @@ library cv; import 'dart:ffi' as ffi; import 'dart:typed_data'; + import 'package:ffi/ffi.dart'; -import './dnn.dart'; import '../core/base.dart'; import '../core/mat.dart'; @@ -13,6 +13,7 @@ import '../core/scalar.dart'; import '../core/size.dart'; import '../core/vec.dart'; import '../opencv.g.dart' as cvg; +import './dnn.dart'; extension LayerAsync on Layer { Future get nameAsync async { @@ -94,7 +95,7 @@ extension NetAsync on Net { } static Future fromBytesAsync(String framework, Uint8List bufferModel, - {Uint8List? bufferConfig}) async { + {Uint8List? bufferConfig,}) async { bufferConfig ??= Uint8List(0); final cFramework = framework.toNativeUtf8().cast(); final bufM = VecUChar.fromList(bufferModel); @@ -302,7 +303,7 @@ extension NetAsync on Net { final rval = cvRunAsync2<(VecFloat, VecInt)>( (callback) => CFFI.Net_GetInputDetails_Async(ref, callback), (c, sc, zp) => c.complete( - (VecFloat.fromPointer(sc.cast()), VecInt.fromPointer(zp.cast()))), + (VecFloat.fromPointer(sc.cast()), VecInt.fromPointer(zp.cast())),), ); return rval; } diff --git a/lib/src/objdetect/objdetect_async.dart b/lib/src/objdetect/objdetect_async.dart index 203e7ff8..9dc90762 100644 --- a/lib/src/objdetect/objdetect_async.dart +++ b/lib/src/objdetect/objdetect_async.dart @@ -16,8 +16,8 @@ import './objdetect.dart'; extension CascadeClassifierAsync on CascadeClassifier { static Future emptyNewAsync() async => cvRunAsync( - (callback) => CFFI.CascadeClassifier_New_Async(callback), - (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast()))); + CFFI.CascadeClassifier_New_Async, + (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast())),); static Future fromFileAsync(String filename) async { final cp = filename.toNativeUtf8().cast(); @@ -167,8 +167,8 @@ extension CascadeClassifierAsync on CascadeClassifier { extension HOGDescriptorAsync on HOGDescriptor { static Future emptyNewAsync() async => cvRunAsync( - (callback) => CFFI.HOGDescriptor_New_Async(callback), - (c, p) => c.complete(HOGDescriptor.fromPointer(p.cast()))); + CFFI.HOGDescriptor_New_Async, + (c, p) => c.complete(HOGDescriptor.fromPointer(p.cast())),); static Future fromFileAsync(String filename) async { final cp = filename.toNativeUtf8().cast(); @@ -391,8 +391,8 @@ Future groupRectanglesAsync( extension QRCodeDetectorAsync on QRCodeDetector { static Future emptyNewAsync() async => cvRunAsync( - (callback) => CFFI.QRCodeDetector_New_Async(callback), - (c, p) => c.complete(QRCodeDetector.fromPointer(p.cast()))); + CFFI.QRCodeDetector_New_Async, + (c, p) => c.complete(QRCodeDetector.fromPointer(p.cast())),); Future<(String rval, Mat straightQRcode)> decodeCurvedAsync( InputArray img, @@ -551,8 +551,8 @@ extension QRCodeDetectorAsync on QRCodeDetector { extension FaceDetectorYNAsync on FaceDetectorYN { static Future emptyNewAsync() async => cvRunAsync( - (callback) => CFFI.CascadeClassifier_New_Async(callback), - (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast()))); + CFFI.CascadeClassifier_New_Async, + (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast())),); static Future fromFileAsync( String model, @@ -568,7 +568,7 @@ extension FaceDetectorYNAsync on FaceDetectorYN { final cConfig = config.toNativeUtf8().cast(); final rval = await cvRunAsync( (callback) => CFFI.FaceDetectorYN_New_Async(cModel, cConfig, inputSize.cvd.ref, scoreThreshold, - nmsThreshold, topK, backendId, targetId, callback), (c, p) { + nmsThreshold, topK, backendId, targetId, callback,), (c, p) { return c.complete(FaceDetectorYN.fromPointer(p.cast())); }); calloc.free(cModel); @@ -600,7 +600,7 @@ extension FaceDetectorYNAsync on FaceDetectorYN { topK, backendId, targetId, - callback), (c, p) { + callback,), (c, p) { return c.complete(FaceDetectorYN.fromPointer(p.cast())); }); calloc.free(cFramework); diff --git a/lib/src/opencv.g.dart b/lib/src/opencv.g.dart index 2ae1b92b..9cd1ead4 100644 --- a/lib/src/opencv.g.dart +++ b/lib/src/opencv.g.dart @@ -20114,34 +20114,29 @@ class CvNative { ffi.Pointer Stitcher_ComposePanorama_1_Async( Stitcher self, VecMat mats, - Mat rpano, - CvCallback_1 callback, + CvCallback_2 callback, ) { return _Stitcher_ComposePanorama_1_Async( self, mats, - rpano, callback, ); } late final _Stitcher_ComposePanorama_1_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Stitcher, VecMat, Mat, - CvCallback_1)>>('Stitcher_ComposePanorama_1_Async'); + 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, Mat, CvCallback_1)>(); + ffi.Pointer Function(Stitcher, VecMat, CvCallback_2)>(); ffi.Pointer Stitcher_ComposePanorama_Async( Stitcher self, - Mat rpano, - CvCallback_1 callback, + CvCallback_2 callback, ) { return _Stitcher_ComposePanorama_Async( self, - rpano, callback, ); } @@ -20149,10 +20144,10 @@ class CvNative { late final _Stitcher_ComposePanorama_AsyncPtr = _lookup< ffi.NativeFunction< ffi.Pointer Function( - Stitcher, Mat, CvCallback_1)>>('Stitcher_ComposePanorama_Async'); + Stitcher, CvCallback_2)>>('Stitcher_ComposePanorama_Async'); late final _Stitcher_ComposePanorama_Async = _Stitcher_ComposePanorama_AsyncPtr.asFunction< - ffi.Pointer Function(Stitcher, Mat, CvCallback_1)>(); + ffi.Pointer Function(Stitcher, CvCallback_2)>(); ffi.Pointer Stitcher_Create( int mode, @@ -20832,36 +20827,31 @@ class CvNative { Stitcher self, VecMat mats, VecMat masks, - Mat rpano, - CvCallback_1 callback, + CvCallback_2 callback, ) { return _Stitcher_Stitch_1_Async( self, mats, masks, - rpano, callback, ); } late final _Stitcher_Stitch_1_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function(Stitcher, VecMat, VecMat, Mat, - CvCallback_1)>>('Stitcher_Stitch_1_Async'); + 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, Mat, CvCallback_1)>(); + ffi.Pointer Function(Stitcher, VecMat, VecMat, CvCallback_2)>(); ffi.Pointer Stitcher_Stitch_Async( Stitcher self, VecMat mats, - Mat rpano, - CvCallback_1 callback, + CvCallback_2 callback, ) { return _Stitcher_Stitch_Async( self, mats, - rpano, callback, ); } @@ -20869,9 +20859,9 @@ class CvNative { late final _Stitcher_Stitch_AsyncPtr = _lookup< ffi.NativeFunction< ffi.Pointer Function( - Stitcher, VecMat, Mat, CvCallback_1)>>('Stitcher_Stitch_Async'); + Stitcher, VecMat, CvCallback_2)>>('Stitcher_Stitch_Async'); late final _Stitcher_Stitch_Async = _Stitcher_Stitch_AsyncPtr.asFunction< - ffi.Pointer Function(Stitcher, VecMat, Mat, CvCallback_1)>(); + ffi.Pointer Function(Stitcher, VecMat, CvCallback_2)>(); ffi.Pointer Stylization( Mat src, diff --git a/lib/src/photo/photo.dart b/lib/src/photo/photo.dart index bd839f95..f3baaa0c 100644 --- a/lib/src/photo/photo.dart +++ b/lib/src/photo/photo.dart @@ -24,7 +24,7 @@ class MergeMertens extends CvStruct { } } factory MergeMertens.fromPointer(cvg.MergeMertensPtr ptr, - [bool attach = true]) => + [bool attach = true,]) => MergeMertens._(ptr.cast(), attach); factory MergeMertens.empty() { final p = calloc(); @@ -40,7 +40,7 @@ class MergeMertens extends CvStruct { final p = calloc(); cvRun( () => CFFI.MergeMertens_CreateWithParams( - contrastWeight, saturationWeight, exposureWeight, p), + contrastWeight, saturationWeight, exposureWeight, p,), ); return MergeMertens._(p); } @@ -86,7 +86,7 @@ class AlignMTB extends CvStruct { } } factory AlignMTB.fromPointer(cvg.AlignMTBPtr ptr, - [bool attach = true]) => + [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 @@ -111,7 +111,7 @@ class AlignMTB extends CvStruct { /// 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}) { + {int maxBits = 6, int excludeRange = 4, bool cut = true,}) { final p = calloc(); cvRun(() => CFFI.AlignMTB_CreateWithParams(maxBits, excludeRange, cut, p)); return AlignMTB._(p); @@ -151,7 +151,7 @@ Mat colorChange( }) { final dst = Mat.empty(); cvRun(() => - CFFI.ColorChange(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul)); + CFFI.ColorChange(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul),); return dst; } @@ -160,10 +160,10 @@ 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) { + 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)); + CFFI.SeamlessClone(src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags),); return blend; } @@ -195,7 +195,7 @@ Mat textureFlattening( }) { final dst = Mat.empty(); cvRun(() => CFFI.TextureFlattening( - src.ref, mask.ref, dst.ref, lowThreshold, highThreshold, kernelSize)); + src.ref, mask.ref, dst.ref, lowThreshold, highThreshold, kernelSize,),); return dst; } @@ -300,7 +300,7 @@ Mat edgePreservingFilter( }) { final dst = Mat.empty(); cvRun( - () => CFFI.EdgePreservingFilter(src.ref, dst.ref, flags, sigmaS, sigmaR)); + () => CFFI.EdgePreservingFilter(src.ref, dst.ref, flags, sigmaS, sigmaR),); return dst; } @@ -317,7 +317,7 @@ Mat edgePreservingFilter( final dst1 = Mat.empty(); final dst2 = Mat.empty(); cvRun(() => CFFI.PencilSketch( - src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor)); + src.ref, dst1.ref, dst2.ref, sigmaS, sigmaR, shadeFactor,),); return (dst1, dst2); } @@ -345,9 +345,9 @@ 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) { + InputArray src, InputArray inpaintMask, double inpaintRadius, int flags,) { final dst = Mat.empty(); cvRun(() => CFFI.PhotoInpaint( - src.ref, inpaintMask.ref, dst.ref, inpaintRadius, flags)); + 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 index 84665f8e..4ba958cd 100644 --- a/lib/src/photo/photo_async.dart +++ b/lib/src/photo/photo_async.dart @@ -1,18 +1,14 @@ library cv; -import 'dart:ffi' as ffi; -import 'dart:typed_data'; -import 'package:ffi/ffi.dart'; import '../core/base.dart'; import '../core/mat.dart'; -import '../core/mat_type.dart'; import '../core/point.dart'; import '../opencv.g.dart' as cvg; import './photo.dart'; extension MergeMertensAsync on MergeMertens { static Future emptyNewAsync() async => cvRunAsync( - (callback) => CFFI.MergeMertens_Create_Async(callback), + CFFI.MergeMertens_Create_Async, (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), ); @@ -44,12 +40,12 @@ extension MergeMertensAsync on MergeMertens { extension AlignMTBAsync on AlignMTB { static Future emptyNewAsync() async => cvRunAsync( - (callback) => CFFI.AlignMTB_Create_Async(callback), + 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 { + {int maxBits = 6, int excludeRange = 4, bool cut = true,}) async { return cvRunAsync( (callback) => CFFI.AlignMTB_CreateWithParams_Async( maxBits, diff --git a/lib/src/stitching/stitching.dart b/lib/src/stitching/stitching.dart index 8ccf16de..29f16037 100644 --- a/lib/src/stitching/stitching.dart +++ b/lib/src/stitching/stitching.dart @@ -24,7 +24,9 @@ class Stitcher extends CvStruct { finalizer.attach(this, ptr.cast(), detach: this); } } - + factory Stitcher.fromPointer(cvg.PtrStitcherPtr ptr, + [bool attach = true,]) => + Stitcher._(ptr.cast(), attach); cvg.Stitcher get stitcher { final s = calloc(); cvRun(() => CFFI.Stitcher_Get(ptr.ref, s)); diff --git a/lib/src/stitching/stitching_async.dart b/lib/src/stitching/stitching_async.dart new file mode 100644 index 00000000..9bd7079a --- /dev/null +++ b/lib/src/stitching/stitching_async.dart @@ -0,0 +1,214 @@ +library cv; + +import 'dart:ffi' as ffi; +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 { + return cvRunAsync( + (callback) => CFFI.Stitcher_Create_Async(mode.index, callback), + (c, p) => c.complete(Stitcher.fromPointer(p.cast())), + ); + } + + Future getStitcherAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_Get_Async(ptr.ref, callback), + (c, p) => c.complete(Stitcher.fromPointer(p.cast())), + ); + } + + Future getRegistrationResolAsync() async { + return cvRunAsync( + (callback) => + CFFI.Stitcher_GetRegistrationResol_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setRegistrationResolAsync(double value) async { + await cvRunAsync0( + (callback) => + CFFI.Stitcher_SetRegistrationResol_Async(stitcher, value, callback), + (c) => c.complete(), + ); + } + + Future getSeamEstimationResolAsync() async { + return cvRunAsync( + (callback) => + CFFI.Stitcher_GetSeamEstimationResol_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setSeamEstimationResolAsync(double value) async { + await cvRunAsync0( + (callback) => + CFFI.Stitcher_SetSeamEstimationResol_Async(stitcher, value, callback), + (c) => c.complete(), + ); + } + + Future getCompositingResolAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetCompositingResol_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setCompositingResolAsync(double value) async { + await cvRunAsync0( + (callback) => + CFFI.Stitcher_SetCompositingResol_Async(stitcher, value, callback), + (c) => c.complete(), + ); + } + + Future getPanoConfidenceThreshAsync() async { + return cvRunAsync( + (callback) => + CFFI.Stitcher_GetPanoConfidenceThresh_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setPanoConfidenceThreshAsync(double value) async { + await cvRunAsync0( + (callback) => CFFI.Stitcher_SetPanoConfidenceThresh_Async( + stitcher, + value, + callback, + ), + (c) => c.complete(), + ); + } + + Future getWaveCorrectionAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetWaveCorrection_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setWaveCorrectionAsync(bool value) async { + await cvRunAsync0( + (callback) => + CFFI.Stitcher_SetWaveCorrection_Async(stitcher, value, callback), + ( + c, + ) => + c.complete(), + ); + } + + Future getInterpolationFlagsAsync() async { + return cvRunAsync( + (callback) => + CFFI.Stitcher_GetInterpolationFlags_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setInterpolationFlagsAsync(int value) async { + await cvRunAsync0( + (callback) => + CFFI.Stitcher_SetInterpolationFlags_Async(stitcher, value, callback), + (c) => c.complete(), + ); + } + + Future getWaveCorrectKindAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_GetWaveCorrectKind_Async(stitcher, callback), + (c, p) => c.complete(p.value), + ); + } + + Future setWaveCorrectKindAsync(int value) async { + await cvRunAsync0( + (callback) => + CFFI.Stitcher_SetWaveCorrectKind_Async(stitcher, value, callback), + ( + c, + ) => + c.complete(), + ); + } + + Future estimateTransformAsync( + VecMat images, { + VecMat? masks, + }) async { + masks ??= VecMat.fromList([]); + return cvRunAsync( + (callback) => CFFI.Stitcher_EstimateTransform_Async( + stitcher, + images.ref, + masks!.ref, + callback, + ), + (c, p) => c.complete(StitcherStatus.fromInt(p.value)), + ); + } + + Future<(StitcherStatus, Mat)> composePanoramaAsync({VecMat? images}) async { + return cvRunAsync2( + (callback) => images == null + ? CFFI.Stitcher_ComposePanorama_Async( + stitcher, + callback, + ) + : CFFI.Stitcher_ComposePanorama_1_Async( + stitcher, + images.ref, + callback, + ), + (c, status, pano) => c.complete( + ( + StitcherStatus.fromInt(status.value), + Mat.fromPointer(pano.cast()) + ), + ), + ); + } + + Future<(StitcherStatus, Mat)> stitchAsync( + VecMat images, { + VecMat? masks, + }) async { + return cvRunAsync2( + (callback) => masks == null + ? CFFI.Stitcher_Stitch_Async( + stitcher, + images.ref, + callback, + ) + : CFFI.Stitcher_Stitch_1_Async( + stitcher, + images.ref, + masks.ref, + callback, + ), + (c, status, pano) => c.complete( + ( + StitcherStatus.fromInt(status.value), + Mat.fromPointer(pano.cast()) + ), + ), + ); + } + + Future getComponentAsync() async { + return cvRunAsync( + (callback) => CFFI.Stitcher_Component_Async(stitcher, callback), + (c, p) => c.complete(VecInt.fromPointer(p.cast())), + ); + } +} diff --git a/src/stitching/stitching_async.cpp b/src/stitching/stitching_async.cpp index d97254c9..18b6598a 100644 --- a/src/stitching/stitching_async.cpp +++ b/src/stitching/stitching_async.cpp @@ -3,7 +3,8 @@ #include "core/types.h" // Asynchronous functions for Stitcher_Create -CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback) { +CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback) +{ BEGIN_WRAP const auto ptr = cv::Stitcher::create(static_cast(mode)); callback(new PtrStitcher{new cv::Ptr(ptr)}); @@ -11,98 +12,113 @@ CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback) { } // Asynchronous functions for Stitcher_Get -CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 callback) { +CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 callback) +{ BEGIN_WRAP callback(new Stitcher{self.ptr->get()}); END_WRAP } // Asynchronous getter/setter functions -CvStatus *Stitcher_GetRegistrationResol_Async(Stitcher self, CvCallback_1 callback) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +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) { +CvStatus *Stitcher_SetWaveCorrectKind_Async(Stitcher self, int inval, CvCallback_0 callback) +{ BEGIN_WRAP self.ptr->setWaveCorrectKind(static_cast(inval)); callback(); @@ -110,47 +126,63 @@ CvStatus *Stitcher_SetWaveCorrectKind_Async(Stitcher self, int inval, CvCallback } // Asynchronous functions -CvStatus *Stitcher_EstimateTransform_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_1 callback) { +CvStatus *Stitcher_EstimateTransform_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_1 callback) +{ BEGIN_WRAP int rval; - if (masks.ptr->size() > 0) { + if (masks.ptr->size() > 0) + { rval = static_cast(self.ptr->estimateTransform(*mats.ptr, *masks.ptr)); - } else { + } + else + { rval = static_cast(self.ptr->estimateTransform(*mats.ptr)); } callback(new int(rval)); END_WRAP } -CvStatus *Stitcher_ComposePanorama_Async(Stitcher self, Mat rpano, CvCallback_1 callback) { +CvStatus *Stitcher_ComposePanorama_Async(Stitcher self, CvCallback_2 callback) +{ BEGIN_WRAP - int rval = static_cast(self.ptr->composePanorama(*rpano.ptr)); - callback(new int(rval)); + 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, Mat rpano, CvCallback_1 callback) { +CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, CvCallback_2 callback) +{ BEGIN_WRAP - int rval = static_cast(self.ptr->composePanorama(*mats.ptr, *rpano.ptr)); - callback(new int(rval)); + 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, Mat rpano, CvCallback_1 callback) { +CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, CvCallback_2 callback) +{ BEGIN_WRAP - int rval = static_cast(self.ptr->stitch(*mats.ptr, *rpano.ptr)); - callback(new int(rval)); + 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, Mat rpano, CvCallback_1 callback) { +CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_2 callback) +{ BEGIN_WRAP - int rval = static_cast(self.ptr->stitch(*mats.ptr, *masks.ptr, *rpano.ptr)); - callback(new int(rval)); + 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) { +CvStatus *Stitcher_Component_Async(Stitcher self, CvCallback_1 callback) +{ BEGIN_WRAP std::vector _rval = self.ptr->component(); callback(new VecInt{new std::vector(_rval)}); diff --git a/src/stitching/stitching_async.h b/src/stitching/stitching_async.h index 52f6d0cd..516186a3 100644 --- a/src/stitching/stitching_async.h +++ b/src/stitching/stitching_async.h @@ -37,10 +37,10 @@ CvStatus *Stitcher_SetWaveCorrectKind_Async(Stitcher self, int inval, CvCallback // Asynchronous functions CvStatus *Stitcher_EstimateTransform_Async(Stitcher self, VecMat mats, VecMat masks, CvCallback_1 callback); -CvStatus *Stitcher_ComposePanorama_Async(Stitcher self, Mat rpano, CvCallback_1 callback); -CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, Mat rpano, CvCallback_1 callback); -CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, Mat rpano, CvCallback_1 callback); -CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, Mat rpano, 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 From 4c7d9ca9127d472027d7b9efbf4e12e6c1a868e2 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:27:35 +0300 Subject: [PATCH 08/15] fix casting and returns --- lib/src/core/base.dart | 29 +++++-- lib/src/stitching/stitching_async.dart | 104 +++++++++++++------------ 2 files changed, 75 insertions(+), 58 deletions(-) diff --git a/lib/src/core/base.dart b/lib/src/core/base.dart index 7a5ece10..a082968c 100644 --- a/lib/src/core/base.dart +++ b/lib/src/core/base.dart @@ -43,9 +43,11 @@ 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; + final libPath = + Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath; return ffi.DynamicLibrary.open(libPath); } @@ -61,7 +63,8 @@ abstract class ICvStruct extends CvObject { T get ref; } -abstract class CvStruct extends ICvStruct with EquatableMixin { +abstract class CvStruct extends ICvStruct + with EquatableMixin { CvStruct.fromPointer(super.ptr) : super.fromPointer(); } @@ -136,7 +139,8 @@ Future cvRunAsync2( Future cvRunAsync3( ffi.Pointer Function(cvg.CvCallback_3 callback) func, - void Function(Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2) onComplete, + void Function(Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2) + onComplete, ) { final completer = Completer(); late final NativeCallable ccallback; @@ -152,7 +156,9 @@ 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 +174,9 @@ 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 +197,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 +241,8 @@ 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/stitching/stitching_async.dart b/lib/src/stitching/stitching_async.dart index 9bd7079a..5e891530 100644 --- a/lib/src/stitching/stitching_async.dart +++ b/lib/src/stitching/stitching_async.dart @@ -1,6 +1,8 @@ library cv; import 'dart:ffi' as ffi; +import 'package:ffi/ffi.dart'; + import '../core/base.dart'; import '../core/mat.dart'; import '../core/vec.dart'; @@ -28,7 +30,7 @@ extension StitcherAsync on Stitcher { return cvRunAsync( (callback) => CFFI.Stitcher_GetRegistrationResol_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => doubleCompleter, ); } @@ -44,7 +46,7 @@ extension StitcherAsync on Stitcher { return cvRunAsync( (callback) => CFFI.Stitcher_GetSeamEstimationResol_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => doubleCompleter, ); } @@ -59,7 +61,7 @@ extension StitcherAsync on Stitcher { Future getCompositingResolAsync() async { return cvRunAsync( (callback) => CFFI.Stitcher_GetCompositingResol_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => doubleCompleter, ); } @@ -75,7 +77,7 @@ extension StitcherAsync on Stitcher { return cvRunAsync( (callback) => CFFI.Stitcher_GetPanoConfidenceThresh_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => intCompleter, ); } @@ -93,7 +95,7 @@ extension StitcherAsync on Stitcher { Future getWaveCorrectionAsync() async { return cvRunAsync( (callback) => CFFI.Stitcher_GetWaveCorrection_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => boolCompleter, ); } @@ -112,7 +114,7 @@ extension StitcherAsync on Stitcher { return cvRunAsync( (callback) => CFFI.Stitcher_GetInterpolationFlags_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => intCompleter, ); } @@ -127,7 +129,7 @@ extension StitcherAsync on Stitcher { Future getWaveCorrectKindAsync() async { return cvRunAsync( (callback) => CFFI.Stitcher_GetWaveCorrectKind_Async(stitcher, callback), - (c, p) => c.complete(p.value), + (c, p) => intCompleter, ); } @@ -148,35 +150,36 @@ extension StitcherAsync on Stitcher { }) async { masks ??= VecMat.fromList([]); return cvRunAsync( - (callback) => CFFI.Stitcher_EstimateTransform_Async( - stitcher, - images.ref, - masks!.ref, - callback, - ), - (c, p) => c.complete(StitcherStatus.fromInt(p.value)), - ); + (callback) => CFFI.Stitcher_EstimateTransform_Async( + stitcher, + 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( - stitcher, - callback, - ) - : CFFI.Stitcher_ComposePanorama_1_Async( - stitcher, - images.ref, - callback, - ), - (c, status, pano) => c.complete( - ( - StitcherStatus.fromInt(status.value), - Mat.fromPointer(pano.cast()) - ), - ), - ); + (callback) => images == null + ? CFFI.Stitcher_ComposePanorama_Async( + stitcher, + callback, + ) + : CFFI.Stitcher_ComposePanorama_1_Async( + stitcher, + 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( @@ -184,25 +187,24 @@ extension StitcherAsync on Stitcher { VecMat? masks, }) async { return cvRunAsync2( - (callback) => masks == null - ? CFFI.Stitcher_Stitch_Async( - stitcher, - images.ref, - callback, - ) - : CFFI.Stitcher_Stitch_1_Async( - stitcher, - images.ref, - masks.ref, - callback, - ), - (c, status, pano) => c.complete( - ( - StitcherStatus.fromInt(status.value), - Mat.fromPointer(pano.cast()) - ), - ), - ); + (callback) => masks == null + ? CFFI.Stitcher_Stitch_Async( + stitcher, + images.ref, + callback, + ) + : CFFI.Stitcher_Stitch_1_Async( + stitcher, + 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 { From 0dfa08d23c5a1bbda08b8d09a57d1bd5a4ea4918 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:29:17 +0300 Subject: [PATCH 09/15] dart fixes --- lib/src/core/base.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/core/base.dart b/lib/src/core/base.dart index a082968c..aacf7c57 100644 --- a/lib/src/core/base.dart +++ b/lib/src/core/base.dart @@ -44,7 +44,7 @@ ffi.DynamicLibrary loadNativeLibrary() { "linux" || "android" || "fuchsia" => "lib$_libraryName.so", "macos" => "lib$_libraryName.dylib", _ => throw UnsupportedError( - "Platform ${Platform.operatingSystem} not supported") + "Platform ${Platform.operatingSystem} not supported",) }; final libPath = Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath; @@ -157,7 +157,7 @@ Future cvRunAsync3( Future cvRunAsync4( ffi.Pointer Function(cvg.CvCallback_4 callback) func, void Function( - Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3) + Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2, VoidPtr p3,) onComplete, ) { final completer = Completer(); @@ -175,7 +175,7 @@ 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) + VoidPtr p3, VoidPtr p4,) onComplete, ) { final completer = Completer(); @@ -242,7 +242,7 @@ typedef NativeFinalizerFunctionT = ffi.Pointer>; ffi.NativeFinalizer OcvFinalizer( - NativeFinalizerFunctionT func) => + NativeFinalizerFunctionT func,) => ffi.NativeFinalizer(func.cast()); // native types From a84fc29e65d7a6b204b415b9ed044e0e05495837 Mon Sep 17 00:00:00 2001 From: abdelaziz-mahdy Date: Sat, 29 Jun 2024 08:30:12 +0000 Subject: [PATCH 10/15] =?UTF-8?q?dart=20format=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/src/core/base.dart | 34 +++++++++------- lib/src/dnn/dnn_async.dart | 10 +++-- lib/src/objdetect/objdetect_async.dart | 54 ++++++++++++++++---------- lib/src/photo/photo.dart | 18 +++------ lib/src/photo/photo_async.dart | 15 ++++--- lib/src/stitching/stitching.dart | 6 ++- lib/src/stitching/stitching_async.dart | 30 +++++--------- 7 files changed, 89 insertions(+), 78 deletions(-) diff --git a/lib/src/core/base.dart b/lib/src/core/base.dart index aacf7c57..49c7894c 100644 --- a/lib/src/core/base.dart +++ b/lib/src/core/base.dart @@ -44,10 +44,10 @@ ffi.DynamicLibrary loadNativeLibrary() { "linux" || "android" || "fuchsia" => "lib$_libraryName.so", "macos" => "lib$_libraryName.dylib", _ => throw UnsupportedError( - "Platform ${Platform.operatingSystem} not supported",) + "Platform ${Platform.operatingSystem} not supported", + ) }; - final libPath = - Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath; + final libPath = Platform.environment["OPENCV_DART_LIB_PATH"] ?? defaultLibPath; return ffi.DynamicLibrary.open(libPath); } @@ -63,8 +63,7 @@ abstract class ICvStruct extends CvObject { T get ref; } -abstract class CvStruct extends ICvStruct - with EquatableMixin { +abstract class CvStruct extends ICvStruct with EquatableMixin { CvStruct.fromPointer(super.ptr) : super.fromPointer(); } @@ -139,8 +138,7 @@ Future cvRunAsync2( Future cvRunAsync3( ffi.Pointer Function(cvg.CvCallback_3 callback) func, - void Function(Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2) - onComplete, + void Function(Completer completer, VoidPtr p, VoidPtr p1, VoidPtr p2) onComplete, ) { final completer = Completer(); late final NativeCallable ccallback; @@ -157,8 +155,12 @@ 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, + Completer completer, + VoidPtr p, + VoidPtr p1, + VoidPtr p2, + VoidPtr p3, + ) onComplete, ) { final completer = Completer(); late final NativeCallable ccallback; @@ -174,9 +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; @@ -242,7 +249,8 @@ typedef NativeFinalizerFunctionT = ffi.Pointer>; ffi.NativeFinalizer OcvFinalizer( - NativeFinalizerFunctionT func,) => + NativeFinalizerFunctionT func, +) => ffi.NativeFinalizer(func.cast()); // native types diff --git a/lib/src/dnn/dnn_async.dart b/lib/src/dnn/dnn_async.dart index 7159390e..46c5014a 100644 --- a/lib/src/dnn/dnn_async.dart +++ b/lib/src/dnn/dnn_async.dart @@ -94,8 +94,11 @@ extension NetAsync on Net { return rval; } - static Future fromBytesAsync(String framework, Uint8List bufferModel, - {Uint8List? bufferConfig,}) async { + static Future fromBytesAsync( + String framework, + Uint8List bufferModel, { + Uint8List? bufferConfig, + }) async { bufferConfig ??= Uint8List(0); final cFramework = framework.toNativeUtf8().cast(); final bufM = VecUChar.fromList(bufferModel); @@ -303,7 +306,8 @@ extension NetAsync on Net { final rval = cvRunAsync2<(VecFloat, VecInt)>( (callback) => CFFI.Net_GetInputDetails_Async(ref, callback), (c, sc, zp) => c.complete( - (VecFloat.fromPointer(sc.cast()), VecInt.fromPointer(zp.cast())),), + (VecFloat.fromPointer(sc.cast()), VecInt.fromPointer(zp.cast())), + ), ); return rval; } diff --git a/lib/src/objdetect/objdetect_async.dart b/lib/src/objdetect/objdetect_async.dart index 9dc90762..f3978f34 100644 --- a/lib/src/objdetect/objdetect_async.dart +++ b/lib/src/objdetect/objdetect_async.dart @@ -16,8 +16,9 @@ import './objdetect.dart'; extension CascadeClassifierAsync on CascadeClassifier { static Future emptyNewAsync() async => cvRunAsync( - CFFI.CascadeClassifier_New_Async, - (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast())),); + CFFI.CascadeClassifier_New_Async, + (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast())), + ); static Future fromFileAsync(String filename) async { final cp = filename.toNativeUtf8().cast(); @@ -167,8 +168,9 @@ extension CascadeClassifierAsync on CascadeClassifier { extension HOGDescriptorAsync on HOGDescriptor { static Future emptyNewAsync() async => cvRunAsync( - CFFI.HOGDescriptor_New_Async, - (c, p) => c.complete(HOGDescriptor.fromPointer(p.cast())),); + CFFI.HOGDescriptor_New_Async, + (c, p) => c.complete(HOGDescriptor.fromPointer(p.cast())), + ); static Future fromFileAsync(String filename) async { final cp = filename.toNativeUtf8().cast(); @@ -391,8 +393,9 @@ Future groupRectanglesAsync( extension QRCodeDetectorAsync on QRCodeDetector { static Future emptyNewAsync() async => cvRunAsync( - CFFI.QRCodeDetector_New_Async, - (c, p) => c.complete(QRCodeDetector.fromPointer(p.cast())),); + CFFI.QRCodeDetector_New_Async, + (c, p) => c.complete(QRCodeDetector.fromPointer(p.cast())), + ); Future<(String rval, Mat straightQRcode)> decodeCurvedAsync( InputArray img, @@ -551,8 +554,9 @@ extension QRCodeDetectorAsync on QRCodeDetector { extension FaceDetectorYNAsync on FaceDetectorYN { static Future emptyNewAsync() async => cvRunAsync( - CFFI.CascadeClassifier_New_Async, - (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast())),); + CFFI.CascadeClassifier_New_Async, + (c, p) => c.complete(CascadeClassifier.fromPointer(p.cast())), + ); static Future fromFileAsync( String model, @@ -567,8 +571,17 @@ extension FaceDetectorYNAsync on FaceDetectorYN { final cModel = model.toNativeUtf8().cast(); final cConfig = config.toNativeUtf8().cast(); final rval = await cvRunAsync( - (callback) => CFFI.FaceDetectorYN_New_Async(cModel, cConfig, inputSize.cvd.ref, scoreThreshold, - nmsThreshold, topK, backendId, targetId, callback,), (c, p) { + (callback) => CFFI.FaceDetectorYN_New_Async( + cModel, + cConfig, + inputSize.cvd.ref, + scoreThreshold, + nmsThreshold, + topK, + backendId, + targetId, + callback, + ), (c, p) { return c.complete(FaceDetectorYN.fromPointer(p.cast())); }); calloc.free(cModel); @@ -591,16 +604,17 @@ extension FaceDetectorYNAsync on FaceDetectorYN { final rval = await cvRunAsync( (callback) => CFFI.FaceDetectorYN_NewFromBuffer_Async( - cFramework, - VecUChar.fromList(bufferModel).ref, - VecUChar.fromList(bufferConfig).ref, - inputSize.cvd.ref, - scoreThreshold, - nmsThreshold, - topK, - backendId, - targetId, - callback,), (c, p) { + cFramework, + VecUChar.fromList(bufferModel).ref, + VecUChar.fromList(bufferConfig).ref, + inputSize.cvd.ref, + scoreThreshold, + nmsThreshold, + topK, + backendId, + targetId, + callback, + ), (c, p) { return c.complete(FaceDetectorYN.fromPointer(p.cast())); }); calloc.free(cFramework); diff --git a/lib/src/photo/photo.dart b/lib/src/photo/photo.dart index f14aea07..cd5af23f 100644 --- a/lib/src/photo/photo.dart +++ b/lib/src/photo/photo.dart @@ -17,8 +17,7 @@ import '../opencv.g.dart' as cvg; /// https://docs.opencv.org/master/d7/dd6/classcv_1_1MergeMertens.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga79d59aa3cb3a7c664e59a4b5acc1ccb6 class MergeMertens extends CvStruct { - MergeMertens._(cvg.MergeMertensPtr ptr, [bool attach = true]) - : super.fromPointer(ptr) { + MergeMertens._(cvg.MergeMertensPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { if (attach) { finalizer.attach(this, ptr.cast(), detach: this); } @@ -51,8 +50,7 @@ class MergeMertens extends CvStruct { return MergeMertens._(p); } - static final finalizer = - OcvFinalizer(CFFI.addresses.MergeMertens_Close); + static final finalizer = OcvFinalizer(CFFI.addresses.MergeMertens_Close); void dispose() { finalizer.detach(this); @@ -85,8 +83,7 @@ class MergeMertens extends CvStruct { /// https://docs.opencv.org/master/d7/db6/classcv_1_1AlignMTB.html /// https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga2f1fafc885a5d79dbfb3542e08db0244 class AlignMTB extends CvStruct { - AlignMTB._(cvg.AlignMTBPtr ptr, [bool attach = true]) - : super.fromPointer(ptr) { + AlignMTB._(cvg.AlignMTBPtr ptr, [bool attach = true]) : super.fromPointer(ptr) { if (attach) { finalizer.attach(this, ptr.cast(), detach: this); } @@ -129,8 +126,7 @@ class AlignMTB extends CvStruct { return AlignMTB._(p); } - static final finalizer = - OcvFinalizer(CFFI.addresses.AlignMTB_Close); + static final finalizer = OcvFinalizer(CFFI.addresses.AlignMTB_Close); void dispose() { finalizer.detach(this); @@ -163,8 +159,7 @@ Mat colorChange( }) { final dst = Mat.empty(); cvRun( - () => - CFFI.ColorChange(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul), + () => CFFI.ColorChange(src.ref, mask.ref, dst.ref, redMul, greenMul, blueMul), ); return dst; } @@ -182,8 +177,7 @@ Mat seamlessClone( ) { final blend = Mat.empty(); cvRun( - () => - CFFI.SeamlessClone(src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags), + () => CFFI.SeamlessClone(src.ref, dst.ref, mask.ref, p.ref, blend.ref, flags), ); return blend; } diff --git a/lib/src/photo/photo_async.dart b/lib/src/photo/photo_async.dart index 252dbc3c..5e8825e1 100644 --- a/lib/src/photo/photo_async.dart +++ b/lib/src/photo/photo_async.dart @@ -9,8 +9,7 @@ import './photo.dart'; extension MergeMertensAsync on MergeMertens { static Future emptyNewAsync() async => cvRunAsync( CFFI.MergeMertens_Create_Async, - (c, p) => - c.complete(MergeMertens.fromPointer(p.cast())), + (c, p) => c.complete(MergeMertens.fromPointer(p.cast())), ); static Future createAsync({ @@ -43,8 +42,11 @@ extension AlignMTBAsync on AlignMTB { (c, p) => c.complete(AlignMTB.fromPointer(p.cast())), ); - static Future createAsync( - {int maxBits = 6, int excludeRange = 4, bool cut = true,}) async { + static Future createAsync({ + int maxBits = 6, + int excludeRange = 4, + bool cut = true, + }) async { return cvRunAsync( (callback) => CFFI.AlignMTB_CreateWithParams_Async( maxBits, @@ -251,10 +253,7 @@ Future<(Mat dst1, Mat dst2)> pencilSketchAsync( callback, ), (c, pdst1, pdst2) => c.complete( - ( - Mat.fromPointer(pdst1.cast()), - Mat.fromPointer(pdst2.cast()) - ), + (Mat.fromPointer(pdst1.cast()), Mat.fromPointer(pdst2.cast())), ), ); } diff --git a/lib/src/stitching/stitching.dart b/lib/src/stitching/stitching.dart index 29f16037..c60ee6a2 100644 --- a/lib/src/stitching/stitching.dart +++ b/lib/src/stitching/stitching.dart @@ -24,8 +24,10 @@ class Stitcher extends CvStruct { finalizer.attach(this, ptr.cast(), detach: this); } } - factory Stitcher.fromPointer(cvg.PtrStitcherPtr ptr, - [bool attach = true,]) => + factory Stitcher.fromPointer( + cvg.PtrStitcherPtr ptr, [ + bool attach = true, + ]) => Stitcher._(ptr.cast(), attach); cvg.Stitcher get stitcher { final s = calloc(); diff --git a/lib/src/stitching/stitching_async.dart b/lib/src/stitching/stitching_async.dart index 5e891530..c324015e 100644 --- a/lib/src/stitching/stitching_async.dart +++ b/lib/src/stitching/stitching_async.dart @@ -28,32 +28,28 @@ extension StitcherAsync on Stitcher { Future getRegistrationResolAsync() async { return cvRunAsync( - (callback) => - CFFI.Stitcher_GetRegistrationResol_Async(stitcher, callback), + (callback) => CFFI.Stitcher_GetRegistrationResol_Async(stitcher, callback), (c, p) => doubleCompleter, ); } Future setRegistrationResolAsync(double value) async { await cvRunAsync0( - (callback) => - CFFI.Stitcher_SetRegistrationResol_Async(stitcher, value, callback), + (callback) => CFFI.Stitcher_SetRegistrationResol_Async(stitcher, value, callback), (c) => c.complete(), ); } Future getSeamEstimationResolAsync() async { return cvRunAsync( - (callback) => - CFFI.Stitcher_GetSeamEstimationResol_Async(stitcher, callback), + (callback) => CFFI.Stitcher_GetSeamEstimationResol_Async(stitcher, callback), (c, p) => doubleCompleter, ); } Future setSeamEstimationResolAsync(double value) async { await cvRunAsync0( - (callback) => - CFFI.Stitcher_SetSeamEstimationResol_Async(stitcher, value, callback), + (callback) => CFFI.Stitcher_SetSeamEstimationResol_Async(stitcher, value, callback), (c) => c.complete(), ); } @@ -67,16 +63,14 @@ extension StitcherAsync on Stitcher { Future setCompositingResolAsync(double value) async { await cvRunAsync0( - (callback) => - CFFI.Stitcher_SetCompositingResol_Async(stitcher, value, callback), + (callback) => CFFI.Stitcher_SetCompositingResol_Async(stitcher, value, callback), (c) => c.complete(), ); } Future getPanoConfidenceThreshAsync() async { return cvRunAsync( - (callback) => - CFFI.Stitcher_GetPanoConfidenceThresh_Async(stitcher, callback), + (callback) => CFFI.Stitcher_GetPanoConfidenceThresh_Async(stitcher, callback), (c, p) => intCompleter, ); } @@ -101,8 +95,7 @@ extension StitcherAsync on Stitcher { Future setWaveCorrectionAsync(bool value) async { await cvRunAsync0( - (callback) => - CFFI.Stitcher_SetWaveCorrection_Async(stitcher, value, callback), + (callback) => CFFI.Stitcher_SetWaveCorrection_Async(stitcher, value, callback), ( c, ) => @@ -112,16 +105,14 @@ extension StitcherAsync on Stitcher { Future getInterpolationFlagsAsync() async { return cvRunAsync( - (callback) => - CFFI.Stitcher_GetInterpolationFlags_Async(stitcher, callback), + (callback) => CFFI.Stitcher_GetInterpolationFlags_Async(stitcher, callback), (c, p) => intCompleter, ); } Future setInterpolationFlagsAsync(int value) async { await cvRunAsync0( - (callback) => - CFFI.Stitcher_SetInterpolationFlags_Async(stitcher, value, callback), + (callback) => CFFI.Stitcher_SetInterpolationFlags_Async(stitcher, value, callback), (c) => c.complete(), ); } @@ -135,8 +126,7 @@ extension StitcherAsync on Stitcher { Future setWaveCorrectKindAsync(int value) async { await cvRunAsync0( - (callback) => - CFFI.Stitcher_SetWaveCorrectKind_Async(stitcher, value, callback), + (callback) => CFFI.Stitcher_SetWaveCorrectKind_Async(stitcher, value, callback), ( c, ) => From 046a17d897e1dc19f1460d5498df53cdc4bd3600 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:36:41 +0300 Subject: [PATCH 11/15] added tests --- lib/opencv_dart.dart | 2 + test/photo/photo_async_test.dart | 150 +++++++++++++++++++++++ test/{ => photo}/photo_test.dart | 0 test/stitching/stitching_async_test.dart | 78 ++++++++++++ test/{ => stitching}/stitching_test.dart | 0 5 files changed, 230 insertions(+) create mode 100644 test/photo/photo_async_test.dart rename test/{ => photo}/photo_test.dart (100%) create mode 100644 test/stitching/stitching_async_test.dart rename test/{ => stitching}/stitching_test.dart (100%) diff --git a/lib/opencv_dart.dart b/lib/opencv_dart.dart index 9c286afc..0d5ce8bd 100644 --- a/lib/opencv_dart.dart +++ b/lib/opencv_dart.dart @@ -42,7 +42,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/test/photo/photo_async_test.dart b/test/photo/photo_async_test.dart new file mode 100644 index 00000000..a6bafeb3 --- /dev/null +++ b/test/photo/photo_async_test.dart @@ -0,0 +1,150 @@ +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, 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 From 3af3dea7e8fdef6e18ad9d8131d3f43dbe9e4c6a Mon Sep 17 00:00:00 2001 From: abdelaziz-mahdy Date: Sat, 29 Jun 2024 08:37:35 +0000 Subject: [PATCH 12/15] =?UTF-8?q?dart=20format=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/photo/photo_async_test.dart | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/test/photo/photo_async_test.dart b/test/photo/photo_async_test.dart index a6bafeb3..2b0778af 100644 --- a/test/photo/photo_async_test.dart +++ b/test/photo/photo_async_test.dart @@ -37,8 +37,7 @@ void main() { }); test('cv.fastNlMeansDenoisingAsync', () async { - final img = await cv.imreadAsync("test/images/lenna.png", - flags: cv.IMREAD_GRAYSCALE); + final img = await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE); expect(img.isEmpty, false); final dst = await cv.fastNlMeansDenoisingAsync(img); @@ -59,8 +58,7 @@ void main() { }); test('cv.fastNlMeansDenoisingColoredAsync', () async { - final img = - await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR); + final img = await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR); expect(img.isEmpty, false); final dst = await cv.fastNlMeansDenoisingColoredAsync(img); @@ -99,11 +97,9 @@ void main() { }); test('cv.inpaintAsync', () async { - final src = await cv.imreadAsync("test/images/inpaint-src.jpg", - flags: cv.IMREAD_COLOR); + 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); + 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)); From 75c6b72b92b22676c0beff9b0f989e356e68bab5 Mon Sep 17 00:00:00 2001 From: Abdelaziz Mahdy Date: Sat, 29 Jun 2024 11:37:42 +0300 Subject: [PATCH 13/15] dart fixes --- test/photo/photo_async_test.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/photo/photo_async_test.dart b/test/photo/photo_async_test.dart index a6bafeb3..41f4e7b6 100644 --- a/test/photo/photo_async_test.dart +++ b/test/photo/photo_async_test.dart @@ -38,7 +38,7 @@ void main() { test('cv.fastNlMeansDenoisingAsync', () async { final img = await cv.imreadAsync("test/images/lenna.png", - flags: cv.IMREAD_GRAYSCALE); + flags: cv.IMREAD_GRAYSCALE,); expect(img.isEmpty, false); final dst = await cv.fastNlMeansDenoisingAsync(img); @@ -100,10 +100,10 @@ void main() { test('cv.inpaintAsync', () async { final src = await cv.imreadAsync("test/images/inpaint-src.jpg", - flags: cv.IMREAD_COLOR); + flags: cv.IMREAD_COLOR,); expect(src.isEmpty, false); final mask = await cv.imreadAsync("test/images/inpaint-mask.jpg", - flags: cv.IMREAD_GRAYSCALE); + flags: cv.IMREAD_GRAYSCALE,); expect(mask.isEmpty, false); final dst = await cv.inpaintAsync(src, mask, 10, cv.INPAINT_TELEA); expect(dst.channels, greaterThan(1)); From 54e9583415bdce566b9c5a6a419aa25493513cb7 Mon Sep 17 00:00:00 2001 From: abdelaziz-mahdy Date: Sat, 29 Jun 2024 08:38:53 +0000 Subject: [PATCH 14/15] =?UTF-8?q?dart=20format=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/photo/photo_async_test.dart | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/photo/photo_async_test.dart b/test/photo/photo_async_test.dart index 4a98cf5c..c1426428 100644 --- a/test/photo/photo_async_test.dart +++ b/test/photo/photo_async_test.dart @@ -37,8 +37,10 @@ void main() { }); test('cv.fastNlMeansDenoisingAsync', () async { - final img = await cv.imreadAsync("test/images/lenna.png", - flags: cv.IMREAD_GRAYSCALE,); + final img = await cv.imreadAsync( + "test/images/lenna.png", + flags: cv.IMREAD_GRAYSCALE, + ); expect(img.isEmpty, false); final dst = await cv.fastNlMeansDenoisingAsync(img); @@ -98,11 +100,15 @@ void main() { }); test('cv.inpaintAsync', () async { - final src = await cv.imreadAsync("test/images/inpaint-src.jpg", - flags: cv.IMREAD_COLOR,); + 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,); + 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)); From 1b61a7ee34255f91447f1eedb8442a6ce8ec4903 Mon Sep 17 00:00:00 2001 From: rainy liu Date: Sat, 29 Jun 2024 18:29:38 +0800 Subject: [PATCH 15/15] fix --- lib/src/opencv.g.dart | 69 +++++------- lib/src/photo/photo_async.dart | 4 +- lib/src/stitching/stitching.dart | 61 +++++----- lib/src/stitching/stitching_async.dart | 148 ++++++++++--------------- src/photo/photo_async.cpp | 7 +- src/photo/photo_async.h | 2 +- src/stitching/stitching.cpp | 53 ++++----- src/stitching/stitching.h | 12 +- src/stitching/stitching_async.cpp | 52 ++++----- src/stitching/stitching_async.h | 5 +- test/photo/photo_async_test.dart | 2 +- 11 files changed, 169 insertions(+), 246 deletions(-) diff --git a/lib/src/opencv.g.dart b/lib/src/opencv.g.dart index 9cd1ead4..3263a010 100644 --- a/lib/src/opencv.g.dart +++ b/lib/src/opencv.g.dart @@ -19647,6 +19647,7 @@ class CvNative { ffi.Pointer SeamlessClone_Async( Mat src, + Mat dst, Mat mask, Point p, int flags, @@ -19654,6 +19655,7 @@ class CvNative { ) { return _SeamlessClone_Async( src, + dst, mask, p, flags, @@ -19663,10 +19665,11 @@ class CvNative { late final _SeamlessClone_AsyncPtr = _lookup< ffi.NativeFunction< - ffi.Pointer Function( - Mat, Mat, Point, ffi.Int, CvCallback_1)>>('SeamlessClone_Async'); + 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, Point, int, CvCallback_1)>(); + ffi.Pointer Function( + Mat, Mat, Mat, Point, int, CvCallback_1)>(); ffi.Pointer SepFilter2D( Mat src, @@ -20004,7 +20007,7 @@ class CvNative { ffi.Pointer Function(Mat, int, Size, CvCallback_1)>(); void Stitcher_Close( - PtrStitcherPtr stitcher, + StitcherPtr stitcher, ) { return _Stitcher_Close( stitcher, @@ -20012,13 +20015,13 @@ class CvNative { } late final _Stitcher_ClosePtr = - _lookup>( + _lookup>( 'Stitcher_Close'); late final _Stitcher_Close = - _Stitcher_ClosePtr.asFunction(); + _Stitcher_ClosePtr.asFunction(); void Stitcher_Close_Async( - PtrStitcherPtr stitcher, + StitcherPtr stitcher, CvCallback_0 callback, ) { return _Stitcher_Close_Async( @@ -20027,11 +20030,11 @@ class CvNative { ); } - late final _Stitcher_Close_AsyncPtr = _lookup< - ffi.NativeFunction>( - 'Stitcher_Close_Async'); + late final _Stitcher_Close_AsyncPtr = + _lookup>( + 'Stitcher_Close_Async'); late final _Stitcher_Close_Async = _Stitcher_Close_AsyncPtr.asFunction< - void Function(PtrStitcherPtr, CvCallback_0)>(); + void Function(StitcherPtr, CvCallback_0)>(); ffi.Pointer Stitcher_Component( Stitcher self, @@ -20151,7 +20154,7 @@ class CvNative { ffi.Pointer Stitcher_Create( int mode, - ffi.Pointer rval, + ffi.Pointer rval, ) { return _Stitcher_Create( mode, @@ -20162,9 +20165,9 @@ 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, @@ -20230,7 +20233,7 @@ class CvNative { Stitcher, VecMat, VecMat, CvCallback_1)>(); ffi.Pointer Stitcher_Get( - PtrStitcher self, + Stitcher self, ffi.Pointer rval, ) { return _Stitcher_Get( @@ -20242,9 +20245,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, @@ -20498,23 +20501,6 @@ class CvNative { _Stitcher_GetWaveCorrection_AsyncPtr.asFunction< ffi.Pointer Function(Stitcher, CvCallback_1)>(); - ffi.Pointer Stitcher_Get_Async( - PtrStitcher self, - CvCallback_1 callback, - ) { - return _Stitcher_Get_Async( - self, - callback, - ); - } - - late final _Stitcher_Get_AsyncPtr = _lookup< - ffi.NativeFunction< - ffi.Pointer Function( - PtrStitcher, CvCallback_1)>>('Stitcher_Get_Async'); - late final _Stitcher_Get_Async = _Stitcher_Get_AsyncPtr.asFunction< - ffi.Pointer Function(PtrStitcher, CvCallback_1)>(); - ffi.Pointer Stitcher_SetCompositingResol( Stitcher self, double inval, @@ -28950,10 +28936,9 @@ class _SymbolAddresses { _library._SIFT_ClosePtr; ffi.Pointer> get SimpleBlobDetector_Close => _library._SimpleBlobDetector_ClosePtr; - ffi.Pointer> + ffi.Pointer> get Stitcher_Close => _library._Stitcher_ClosePtr; - ffi.Pointer< - ffi.NativeFunction> + ffi.Pointer> get Stitcher_Close_Async => _library._Stitcher_Close_AsyncPtr; ffi.Pointer> get Subdiv2D_Close => _library._Subdiv2D_ClosePtr; @@ -29476,12 +29461,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; } @@ -29645,9 +29624,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_async.dart b/lib/src/photo/photo_async.dart index 5e8825e1..c343118d 100644 --- a/lib/src/photo/photo_async.dart +++ b/lib/src/photo/photo_async.dart @@ -88,6 +88,7 @@ Future colorChangeAsync( Future seamlessCloneAsync( InputArray src, + InputArray dst, InputArray mask, Point p, int flags, @@ -95,12 +96,13 @@ Future seamlessCloneAsync( return cvRunAsync( (callback) => CFFI.SeamlessClone_Async( src.ref, + dst.ref, mask.ref, p.ref, flags, callback, ), - (c, pdst) => c.complete(Mat.fromPointer(pdst.cast())), + matCompleter, ); } diff --git a/lib/src/stitching/stitching.dart b/lib/src/stitching/stitching.dart index c60ee6a2..9ecef6ac 100644 --- a/lib/src/stitching/stitching.dart +++ b/lib/src/stitching/stitching.dart @@ -18,27 +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); } } - factory Stitcher.fromPointer( - cvg.PtrStitcherPtr ptr, [ - bool attach = true, - ]) => - Stitcher._(ptr.cast(), attach); - 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_); } @@ -47,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. @@ -147,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); }); } @@ -161,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); }); } @@ -175,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); }); } @@ -184,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); @@ -199,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 index c324015e..42ccdf78 100644 --- a/lib/src/stitching/stitching_async.dart +++ b/lib/src/stitching/stitching_async.dart @@ -12,127 +12,97 @@ import './stitching.dart'; extension StitcherAsync on Stitcher { static Future createAsync({ StitcherMode mode = StitcherMode.PANORAMA, - }) async { - return cvRunAsync( - (callback) => CFFI.Stitcher_Create_Async(mode.index, callback), - (c, p) => c.complete(Stitcher.fromPointer(p.cast())), - ); - } - - Future getStitcherAsync() async { - return cvRunAsync( - (callback) => CFFI.Stitcher_Get_Async(ptr.ref, callback), - (c, p) => c.complete(Stitcher.fromPointer(p.cast())), - ); - } + }) async => + cvRunAsync( + (callback) => CFFI.Stitcher_Create_Async(mode.index, callback), + (c, p) => c.complete(Stitcher.fromPointer(p.cast())), + ); - Future getRegistrationResolAsync() async { - return cvRunAsync( - (callback) => CFFI.Stitcher_GetRegistrationResol_Async(stitcher, callback), - (c, p) => doubleCompleter, - ); - } + Future getRegistrationResolAsync() async => cvRunAsync( + (callback) => CFFI.Stitcher_GetRegistrationResol_Async(ref, callback), + doubleCompleter, + ); - Future setRegistrationResolAsync(double value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetRegistrationResol_Async(stitcher, value, callback), - (c) => c.complete(), - ); - } + 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(stitcher, callback), - (c, p) => doubleCompleter, + (callback) => CFFI.Stitcher_GetSeamEstimationResol_Async(ref, callback), + doubleCompleter, ); } - Future setSeamEstimationResolAsync(double value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetSeamEstimationResol_Async(stitcher, value, callback), - (c) => c.complete(), - ); - } + 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(stitcher, callback), - (c, p) => doubleCompleter, + (callback) => CFFI.Stitcher_GetCompositingResol_Async(ref, callback), + doubleCompleter, ); } - Future setCompositingResolAsync(double value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetCompositingResol_Async(stitcher, value, callback), - (c) => c.complete(), - ); - } + 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(stitcher, callback), - (c, p) => intCompleter, + (callback) => CFFI.Stitcher_GetPanoConfidenceThresh_Async(ref, callback), + doubleCompleter, ); } - Future setPanoConfidenceThreshAsync(double value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetPanoConfidenceThresh_Async( - stitcher, - value, - callback, - ), - (c) => c.complete(), - ); - } + 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(stitcher, callback), - (c, p) => boolCompleter, + (callback) => CFFI.Stitcher_GetWaveCorrection_Async(ref, callback), + boolCompleter, ); } - Future setWaveCorrectionAsync(bool value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetWaveCorrection_Async(stitcher, value, callback), - ( - c, - ) => - c.complete(), - ); - } + 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(stitcher, callback), - (c, p) => intCompleter, + (callback) => CFFI.Stitcher_GetInterpolationFlags_Async(ref, callback), + intCompleter, ); } - Future setInterpolationFlagsAsync(int value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetInterpolationFlags_Async(stitcher, value, callback), - (c) => c.complete(), - ); - } + 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(stitcher, callback), - (c, p) => intCompleter, + (callback) => CFFI.Stitcher_GetWaveCorrectKind_Async(ref, callback), + intCompleter, ); } - Future setWaveCorrectKindAsync(int value) async { - await cvRunAsync0( - (callback) => CFFI.Stitcher_SetWaveCorrectKind_Async(stitcher, value, callback), - ( - c, - ) => - c.complete(), - ); - } + Future setWaveCorrectKindAsync(int value) async => cvRunAsync0( + (callback) => CFFI.Stitcher_SetWaveCorrectKind_Async(ref, value, callback), + (c) => c.complete(), + ); Future estimateTransformAsync( VecMat images, { @@ -141,7 +111,7 @@ extension StitcherAsync on Stitcher { masks ??= VecMat.fromList([]); return cvRunAsync( (callback) => CFFI.Stitcher_EstimateTransform_Async( - stitcher, + ref, images.ref, masks!.ref, callback, @@ -156,11 +126,11 @@ extension StitcherAsync on Stitcher { return cvRunAsync2( (callback) => images == null ? CFFI.Stitcher_ComposePanorama_Async( - stitcher, + ref, callback, ) : CFFI.Stitcher_ComposePanorama_1_Async( - stitcher, + ref, images.ref, callback, ), (c, status, pano) { @@ -179,12 +149,12 @@ extension StitcherAsync on Stitcher { return cvRunAsync2( (callback) => masks == null ? CFFI.Stitcher_Stitch_Async( - stitcher, + ref, images.ref, callback, ) : CFFI.Stitcher_Stitch_1_Async( - stitcher, + ref, images.ref, masks.ref, callback, @@ -199,7 +169,7 @@ extension StitcherAsync on Stitcher { Future getComponentAsync() async { return cvRunAsync( - (callback) => CFFI.Stitcher_Component_Async(stitcher, callback), + (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 index a732e922..55a8cad5 100644 --- a/src/photo/photo_async.cpp +++ b/src/photo/photo_async.cpp @@ -13,13 +13,12 @@ CvStatus *ColorChange_Async(Mat src, Mat mask, float red_mul, float green_mul, f } // Asynchronous functions for SeamlessClone -CvStatus *SeamlessClone_Async(Mat src, Mat mask, Point p, int flags, CvCallback_2 callback) +CvStatus *SeamlessClone_Async(Mat src, Mat dst, Mat mask, Point p, int flags, CvCallback_1 callback) { BEGIN_WRAP cv::Mat _blend; - cv::Mat _dst; - cv::seamlessClone(*src.ptr, _dst, *mask.ptr, cv::Point(p.x, p.y), _blend, flags); - callback(new Mat{new cv::Mat(_blend)}, new Mat{new 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 } diff --git a/src/photo/photo_async.h b/src/photo/photo_async.h index 5dfbf82f..75d69187 100644 --- a/src/photo/photo_async.h +++ b/src/photo/photo_async.h @@ -15,7 +15,7 @@ extern "C" 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 mask, Point p, int flags, CvCallback_1 callback); + 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); 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 index 18b6598a..56c8e6c2 100644 --- a/src/stitching/stitching_async.cpp +++ b/src/stitching/stitching_async.cpp @@ -7,15 +7,7 @@ CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback) { BEGIN_WRAP const auto ptr = cv::Stitcher::create(static_cast(mode)); - callback(new PtrStitcher{new cv::Ptr(ptr)}); - END_WRAP -} - -// Asynchronous functions for Stitcher_Get -CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 callback) -{ - BEGIN_WRAP - callback(new Stitcher{self.ptr->get()}); + callback(new Stitcher{new cv::Ptr(ptr)}); END_WRAP } @@ -23,14 +15,14 @@ CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 callback) CvStatus *Stitcher_GetRegistrationResol_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new double(self.ptr->registrationResol())); + 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); + (*self.ptr)->setRegistrationResol(inval); callback(); END_WRAP } @@ -38,14 +30,14 @@ CvStatus *Stitcher_SetRegistrationResol_Async(Stitcher self, double inval, CvCal CvStatus *Stitcher_GetSeamEstimationResol_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new double(self.ptr->seamEstimationResol())); + 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); + (*self.ptr)->setSeamEstimationResol(inval); callback(); END_WRAP } @@ -53,14 +45,14 @@ CvStatus *Stitcher_SetSeamEstimationResol_Async(Stitcher self, double inval, CvC CvStatus *Stitcher_GetCompositingResol_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new double(self.ptr->compositingResol())); + 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); + (*self.ptr)->setCompositingResol(inval); callback(); END_WRAP } @@ -68,14 +60,14 @@ CvStatus *Stitcher_SetCompositingResol_Async(Stitcher self, double inval, CvCall CvStatus *Stitcher_GetPanoConfidenceThresh_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new double(self.ptr->panoConfidenceThresh())); + 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); + (*self.ptr)->setPanoConfidenceThresh(inval); callback(); END_WRAP } @@ -83,14 +75,14 @@ CvStatus *Stitcher_SetPanoConfidenceThresh_Async(Stitcher self, double inval, Cv CvStatus *Stitcher_GetWaveCorrection_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new bool(self.ptr->waveCorrection())); + 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); + (*self.ptr)->setWaveCorrection(inval); callback(); END_WRAP } @@ -98,14 +90,14 @@ CvStatus *Stitcher_SetWaveCorrection_Async(Stitcher self, bool inval, CvCallback CvStatus *Stitcher_GetInterpolationFlags_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new int(static_cast(self.ptr->interpolationFlags()))); + 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)); + (*self.ptr)->setInterpolationFlags(static_cast(inval)); callback(); END_WRAP } @@ -113,14 +105,14 @@ CvStatus *Stitcher_SetInterpolationFlags_Async(Stitcher self, int inval, CvCallb CvStatus *Stitcher_GetWaveCorrectKind_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - callback(new int(static_cast(self.ptr->waveCorrectKind()))); + 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)); + (*self.ptr)->setWaveCorrectKind(static_cast(inval)); callback(); END_WRAP } @@ -132,11 +124,11 @@ CvStatus *Stitcher_EstimateTransform_Async(Stitcher self, VecMat mats, VecMat ma int rval; 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)); } callback(new int(rval)); END_WRAP @@ -147,7 +139,7 @@ CvStatus *Stitcher_ComposePanorama_Async(Stitcher self, CvCallback_2 callback) BEGIN_WRAP cv::Mat ـrpano; - int rval = static_cast(self.ptr->composePanorama(ـrpano)); + int rval = static_cast((*self.ptr)->composePanorama(ـrpano)); callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); END_WRAP } @@ -157,7 +149,7 @@ CvStatus *Stitcher_ComposePanorama_1_Async(Stitcher self, VecMat mats, CvCallbac BEGIN_WRAP cv::Mat ـrpano; - int rval = static_cast(self.ptr->composePanorama(*mats.ptr, ـrpano)); + int rval = static_cast((*self.ptr)->composePanorama(*mats.ptr, ـrpano)); callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); END_WRAP } @@ -167,7 +159,7 @@ CvStatus *Stitcher_Stitch_Async(Stitcher self, VecMat mats, CvCallback_2 callbac BEGIN_WRAP cv::Mat ـrpano; - int rval = static_cast(self.ptr->stitch(*mats.ptr, ـrpano)); + int rval = static_cast((*self.ptr)->stitch(*mats.ptr, ـrpano)); callback(new int(rval), new Mat{new cv::Mat(ـrpano)}); END_WRAP } @@ -176,7 +168,7 @@ CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, CvCa { BEGIN_WRAP cv::Mat ـrpano; - int rval = static_cast(self.ptr->stitch(*mats.ptr, *masks.ptr, ـ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 } @@ -184,7 +176,7 @@ CvStatus *Stitcher_Stitch_1_Async(Stitcher self, VecMat mats, VecMat masks, CvCa CvStatus *Stitcher_Component_Async(Stitcher self, CvCallback_1 callback) { BEGIN_WRAP - std::vector _rval = self.ptr->component(); + 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 index 516186a3..2312d667 100644 --- a/src/stitching/stitching_async.h +++ b/src/stitching/stitching_async.h @@ -14,10 +14,7 @@ extern "C" { CvStatus *Stitcher_Create_Async(int mode, CvCallback_1 callback); // Asynchronous functions for Stitcher_Close -void Stitcher_Close_Async(PtrStitcherPtr stitcher, CvCallback_0 callback); - -// Asynchronous functions for Stitcher_Get -CvStatus *Stitcher_Get_Async(PtrStitcher self, CvCallback_1 callback); +void Stitcher_Close_Async(StitcherPtr stitcher, CvCallback_0 callback); // Asynchronous getter/setter functions CvStatus *Stitcher_GetRegistrationResol_Async(Stitcher self, CvCallback_1 callback); diff --git a/test/photo/photo_async_test.dart b/test/photo/photo_async_test.dart index c1426428..c07b249a 100644 --- a/test/photo/photo_async_test.dart +++ b/test/photo/photo_async_test.dart @@ -15,7 +15,7 @@ void main() { final mask = src.clone(); final dst = src.clone(); final p = cv.Point(dst.cols ~/ 2, dst.rows ~/ 2); - final blend = await cv.seamlessCloneAsync(src, mask, p, cv.NORMAL_CLONE); + 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)); });