diff --git a/packages/dartcv/CHANGELOG.md b/packages/dartcv/CHANGELOG.md index 2402c439..59e79a5d 100644 --- a/packages/dartcv/CHANGELOG.md +++ b/packages/dartcv/CHANGELOG.md @@ -4,6 +4,7 @@ * add `MatType.elemSize` `MatType.elemSize1` * remove deprecated `(double x, double y, double z).asPoint3f` `(double x, double y).asPoint2f` `(int x, int y).asPoint` `VecPoint.toVecVecPoint` +* add `bin/gen_cmake_vars.dart` for generating optional module vars for CMake ## 1.1.3 diff --git a/packages/dartcv/bin/gen_cmake_vars.dart b/packages/dartcv/bin/gen_cmake_vars.dart new file mode 100644 index 00000000..07dfc111 --- /dev/null +++ b/packages/dartcv/bin/gen_cmake_vars.dart @@ -0,0 +1,89 @@ +// ignore_for_file: avoid_dynamic_calls, avoid_print + +import 'dart:io'; + +import 'package:yaml/yaml.dart'; + +const defaultModuleSettings = { + // "core": "ON", // not configurable + "calib3d": "ON", + "contrib": "ON", + "dnn": "ON", + "features2d": "ON", + "flann": "ON", + // "gapi", // disabled + "highgui": "OFF", + "imgproc": "ON", + "imgcodecs": "ON", + "objdetect": "ON", + "photo": "ON", + "stitching": "ON", + "video": "ON", + "videoio": "ON", +}; + +void main(List args) { + final pubspecPath = Platform.script.resolve("../../../../pubspec.yaml"); + final excludeModules = parseUserDefinedExcludeModules(pubspecPath.toFilePath()); + + final cmakeVars = StringBuffer("###DARTCV_GEN_CMAKE_VAR_BEGIN###\n"); + for (final k in excludeModules.entries) { + cmakeVars.write("${k.key.toUpperCase()}=${k.value.toUpperCase()}\n"); + } + cmakeVars.write("###DARTCV_GEN_CMAKE_VAR_END###"); + print(cmakeVars); +} + +/// Parse the user defined exclude modules from pubspec.yaml +/// +/// Returns a list of excluded module names +Map parseUserDefinedExcludeModules(String pubspecPath, {bool excludeMode = true}) { + try { + print("Generating cmake vars from $pubspecPath"); + // Read the pubspec.yaml file + final File file = File(pubspecPath); + if (!file.existsSync()) { + print("$pubspecPath not found"); + return defaultModuleSettings; + } + + // Parse the YAML content + final String yamlContent = file.readAsStringSync(); + final dynamic yamlMap = loadYaml(yamlContent); + + // Navigate to the hooks.user_defines.dartcv4.exclude_modules section + if (yamlMap is YamlMap && + yamlMap['hooks'] is YamlMap && + yamlMap['hooks']['user_defines'] is YamlMap && + yamlMap['hooks']['user_defines']['dartcv4'] is YamlMap) { + final dartcvDefines = yamlMap['hooks']['user_defines']['dartcv4'] as YamlMap; + + final excludeModules = dartcvDefines['exclude_modules'] as YamlList? ?? YamlList(); + // include is priority over exclude + final includeModules = dartcvDefines['include_modules'] as YamlList? ?? YamlList(); + + final include = includeModules + .map((dynamic module) => module.toString().toLowerCase()) + .where((e) => defaultModuleSettings.containsKey(e)) + .toList(); + final exclude = excludeModules + .map((dynamic module) => module.toString().toLowerCase()) + .where((e) => defaultModuleSettings.containsKey(e) && !include.contains(e)) + .toList(); + + final result = { + for (final e in defaultModuleSettings.keys) + e: exclude.contains(e) ? "OFF" : defaultModuleSettings[e]!, + }; + + return result; + } + + print("parse error"); + return defaultModuleSettings; + } catch (e) { + // Return empty list in case of any error + print('Error parsing exclude_modules: $e'); + return defaultModuleSettings; + } +} diff --git a/packages/dartcv/lib/src/calib3d/fisheye.dart b/packages/dartcv/lib/src/calib3d/fisheye.dart index 1b32df95..839319cf 100644 --- a/packages/dartcv/lib/src/calib3d/fisheye.dart +++ b/packages/dartcv/lib/src/calib3d/fisheye.dart @@ -107,25 +107,24 @@ class Fisheye { distorted ??= Mat.empty(); cvRun( - () => - Kundistorted == null - ? ccalib3d.cv_fisheye_distortPoints( - undistorted.ref, - distorted!.ref, - K.ref, - D.ref, - alpha, - ffi.nullptr, - ) - : ccalib3d.cv_fisheye_distortPoints_1( - undistorted.ref, - distorted!.ref, - Kundistorted.ref, - K.ref, - D.ref, - alpha, - ffi.nullptr, - ), + () => Kundistorted == null + ? ccalib3d.cv_fisheye_distortPoints( + undistorted.ref, + distorted!.ref, + K.ref, + D.ref, + alpha, + ffi.nullptr, + ) + : ccalib3d.cv_fisheye_distortPoints_1( + undistorted.ref, + distorted!.ref, + Kundistorted.ref, + K.ref, + D.ref, + alpha, + ffi.nullptr, + ), ); return distorted; } @@ -142,25 +141,17 @@ class Fisheye { distorted ??= Mat.empty(); return cvRunAsync0( - (callback) => - Kundistorted == null - ? ccalib3d.cv_fisheye_distortPoints( - undistorted.ref, - distorted!.ref, - K.ref, - D.ref, - alpha, - callback, - ) - : ccalib3d.cv_fisheye_distortPoints_1( - undistorted.ref, - distorted!.ref, - Kundistorted.ref, - K.ref, - D.ref, - alpha, - callback, - ), + (callback) => Kundistorted == null + ? ccalib3d.cv_fisheye_distortPoints(undistorted.ref, distorted!.ref, K.ref, D.ref, alpha, callback) + : ccalib3d.cv_fisheye_distortPoints_1( + undistorted.ref, + distorted!.ref, + Kundistorted.ref, + K.ref, + D.ref, + alpha, + callback, + ), (c) => c.complete(distorted), ); } diff --git a/packages/dartcv/lib/src/calib3d/usac_params.dart b/packages/dartcv/lib/src/calib3d/usac_params.dart index 712e74d1..da3ed97f 100644 --- a/packages/dartcv/lib/src/calib3d/usac_params.dart +++ b/packages/dartcv/lib/src/calib3d/usac_params.dart @@ -26,21 +26,20 @@ class UsacParams extends CvStruct { int finalPolisher = NONE_POLISHER, int finalPolisherIterations = 0, }) { - final p = - calloc() - ..ref.confidence = confidence - ..ref.isParallel = isParallel - ..ref.loIterations = loIterations - ..ref.loMethod = loMethod - ..ref.loSampleSize = loSampleSize - ..ref.maxIterations = maxIterations - ..ref.neighborsSearch = neighborsSearch - ..ref.randomGeneratorState = randomGeneratorState - ..ref.sampler = sampler - ..ref.score = score - ..ref.threshold = threshold - ..ref.final_polisher = finalPolisher - ..ref.final_polisher_iterations = finalPolisherIterations; + final p = calloc() + ..ref.confidence = confidence + ..ref.isParallel = isParallel + ..ref.loIterations = loIterations + ..ref.loMethod = loMethod + ..ref.loSampleSize = loSampleSize + ..ref.maxIterations = maxIterations + ..ref.neighborsSearch = neighborsSearch + ..ref.randomGeneratorState = randomGeneratorState + ..ref.sampler = sampler + ..ref.score = score + ..ref.threshold = threshold + ..ref.final_polisher = finalPolisher + ..ref.final_polisher_iterations = finalPolisherIterations; return UsacParams.fromPointer(p); } diff --git a/packages/dartcv/lib/src/contrib/ximgproc.dart b/packages/dartcv/lib/src/contrib/ximgproc.dart index c9d4be9d..cd25facf 100644 --- a/packages/dartcv/lib/src/contrib/ximgproc.dart +++ b/packages/dartcv/lib/src/contrib/ximgproc.dart @@ -590,21 +590,20 @@ class EdgeDrawingParams extends CvStruct { double Sigma = 1.0, bool SumFlag = true, }) { - final p = - calloc() - ..ref.AnchorThresholdValue = AnchorThresholdValue - ..ref.EdgeDetectionOperator = EdgeDetectionOperator - ..ref.GradientThresholdValue = GradientThresholdValue - ..ref.LineFitErrorThreshold = LineFitErrorThreshold - ..ref.MaxDistanceBetweenTwoLines = MaxDistanceBetweenTwoLines - ..ref.MaxErrorThreshold = MaxErrorThreshold - ..ref.MinLineLength = MinLineLength - ..ref.MinPathLength = MinPathLength - ..ref.NFAValidation = NFAValidation - ..ref.PFmode = PFmode - ..ref.ScanInterval = ScanInterval - ..ref.Sigma = Sigma - ..ref.SumFlag = SumFlag; + final p = calloc() + ..ref.AnchorThresholdValue = AnchorThresholdValue + ..ref.EdgeDetectionOperator = EdgeDetectionOperator + ..ref.GradientThresholdValue = GradientThresholdValue + ..ref.LineFitErrorThreshold = LineFitErrorThreshold + ..ref.MaxDistanceBetweenTwoLines = MaxDistanceBetweenTwoLines + ..ref.MaxErrorThreshold = MaxErrorThreshold + ..ref.MinLineLength = MinLineLength + ..ref.MinPathLength = MinPathLength + ..ref.NFAValidation = NFAValidation + ..ref.PFmode = PFmode + ..ref.ScanInterval = ScanInterval + ..ref.Sigma = Sigma + ..ref.SumFlag = SumFlag; return EdgeDrawingParams.fromPointer(p); } diff --git a/packages/dartcv/lib/src/core/core_async.dart b/packages/dartcv/lib/src/core/core_async.dart index 5ad972b7..5cbf5923 100644 --- a/packages/dartcv/lib/src/core/core_async.dart +++ b/packages/dartcv/lib/src/core/core_async.dart @@ -81,13 +81,13 @@ Future bitwiseANDAsync(InputArray src1, InputArray src2, {OutputArray? dst, dst ??= Mat.empty(); return mask == null ? cvRunAsync0((callback) => ccore.cv_bitwise_and(src1.ref, src2.ref, dst!.ref, callback), (c) { - return c.complete(dst); - }) + return c.complete(dst); + }) : cvRunAsync0((callback) => ccore.cv_bitwise_and_1(src1.ref, src2.ref, dst!.ref, mask.ref, callback), ( - c, - ) { - return c.complete(dst); - }); + c, + ) { + return c.complete(dst); + }); } /// BitwiseNot inverts every bit of an array. @@ -98,11 +98,11 @@ Future bitwiseNOTAsync(InputArray src, {OutputArray? dst, InputArray? mask} dst ??= Mat.empty(); return mask == null ? cvRunAsync0((callback) => ccore.cv_bitwise_not(src.ref, dst!.ref, callback), (c) { - return c.complete(dst); - }) + return c.complete(dst); + }) : cvRunAsync0((callback) => ccore.cv_bitwise_not_1(src.ref, dst!.ref, mask.ref, callback), (c) { - return c.complete(dst); - }); + return c.complete(dst); + }); } /// BitwiseOr calculates the per-element bit-wise disjunction of two arrays @@ -114,13 +114,13 @@ Future bitwiseORAsync(InputArray src1, InputArray src2, {OutputArray? dst, dst ??= Mat.empty(); return mask == null ? cvRunAsync0((callback) => ccore.cv_bitwise_or(src1.ref, src2.ref, dst!.ref, callback), (c) { - return c.complete(dst); - }) + return c.complete(dst); + }) : cvRunAsync0((callback) => ccore.cv_bitwise_or_1(src1.ref, src2.ref, dst!.ref, mask.ref, callback), ( - c, - ) { - return c.complete(dst); - }); + c, + ) { + return c.complete(dst); + }); } /// BitwiseXor calculates the per-element bit-wise "exclusive or" operation @@ -132,13 +132,13 @@ Future bitwiseXORAsync(InputArray src1, InputArray src2, {OutputArray? dst, dst ??= Mat.empty(); return mask == null ? cvRunAsync0((callback) => ccore.cv_bitwise_xor(src1.ref, src2.ref, dst!.ref, callback), (c) { - return c.complete(dst); - }) + return c.complete(dst); + }) : cvRunAsync0((callback) => ccore.cv_bitwise_xor_1(src1.ref, src2.ref, dst!.ref, mask.ref, callback), ( - c, - ) { - return c.complete(dst); - }); + c, + ) { + return c.complete(dst); + }); } /// BatchDistance is a naive nearest neighbor finder. @@ -856,11 +856,11 @@ Future<(Scalar mean, Scalar stddev)> meanStdDevAsync(InputArray src, {InputArray final stddev = calloc(); return mask == null ? cvRunAsync0((callback) => ccore.cv_meanStdDev(src.ref, mean, stddev, callback), (c) { - return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev))); - }) + return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev))); + }) : cvRunAsync0((callback) => ccore.cv_meanStdDev_1(src.ref, mean, stddev, mask.ref, callback), (c) { - return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev))); - }); + return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev))); + }); } /// Merge creates one multi-channel array out of several single-channel ones. diff --git a/packages/dartcv/lib/src/core/cv_vec.dart b/packages/dartcv/lib/src/core/cv_vec.dart index 81eb42c9..c23a04bf 100644 --- a/packages/dartcv/lib/src/core/cv_vec.dart +++ b/packages/dartcv/lib/src/core/cv_vec.dart @@ -25,19 +25,17 @@ class Vec2b extends CvVec { } } factory Vec2b(int v1, int v2) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2; return Vec2b._(p); } factory Vec2b.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec2b._(ptr, attach); factory Vec2b.fromNative(cvg.Vec2b v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2; return Vec2b._(p); } @@ -80,21 +78,19 @@ class Vec3b extends CvVec { } } factory Vec3b(int v1, int v2, int v3) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3; return Vec3b._(p); } factory Vec3b.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec3b._(ptr, attach); factory Vec3b.fromNative(cvg.Vec3b v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3; return Vec3b._(p); } @@ -141,23 +137,21 @@ class Vec4b extends CvVec { } } factory Vec4b(int v1, int v2, int v3, int v4) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4; return Vec4b._(p); } factory Vec4b.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec4b._(ptr, attach); factory Vec4b.fromNative(cvg.Vec4b v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4; return Vec4b._(p); } @@ -208,19 +202,17 @@ class Vec2w extends CvVec { } } factory Vec2w(int v1, int v2) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2; return Vec2w._(p); } factory Vec2w.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec2w._(ptr, attach); factory Vec2w.fromNative(cvg.Vec2w v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2; return Vec2w._(p); } @@ -263,21 +255,19 @@ class Vec3w extends CvVec { } } factory Vec3w(int v1, int v2, int v3) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3; return Vec3w._(p); } factory Vec3w.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec3w._(ptr, attach); factory Vec3w.fromNative(cvg.Vec3w v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3; return Vec3w._(p); } @@ -324,23 +314,21 @@ class Vec4w extends CvVec { } } factory Vec4w(int v1, int v2, int v3, int v4) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4; return Vec4w._(p); } factory Vec4w.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec4w._(ptr, attach); factory Vec4w.fromNative(cvg.Vec4w v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4; return Vec4w._(p); } int get val1 => ref.val1; @@ -390,19 +378,17 @@ class Vec2s extends CvVec { } } factory Vec2s(int v1, int v2) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2; return Vec2s._(p); } factory Vec2s.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec2s._(ptr, attach); factory Vec2s.fromNative(cvg.Vec2s v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2; return Vec2s._(p); } int get val1 => ref.val1; @@ -444,21 +430,19 @@ class Vec3s extends CvVec { } } factory Vec3s(int v1, int v2, int v3) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3; return Vec3s._(p); } factory Vec3s.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec3s._(ptr, attach); factory Vec3s.fromNative(cvg.Vec3s v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3; return Vec3s._(p); } @@ -505,23 +489,21 @@ class Vec4s extends CvVec { } } factory Vec4s(int v1, int v2, int v3, int v4) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4; return Vec4s._(p); } factory Vec4s.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec4s._(ptr, attach); factory Vec4s.fromNative(cvg.Vec4s v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4; return Vec4s._(p); } @@ -572,19 +554,17 @@ class Vec2i extends CvVec { } } factory Vec2i(int v1, int v2) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2; return Vec2i._(p); } factory Vec2i.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec2i._(ptr, attach); factory Vec2i.fromNative(cvg.Vec2i v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2; return Vec2i._(p); } @@ -627,21 +607,19 @@ class Vec3i extends CvVec { } } factory Vec3i(int v1, int v2, int v3) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3; return Vec3i._(p); } factory Vec3i.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec3i._(ptr, attach); factory Vec3i.fromNative(cvg.Vec3i v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3; return Vec3i._(p); } @@ -688,23 +666,21 @@ class Vec4i extends CvVec { } } factory Vec4i(int v1, int v2, int v3, int v4) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4; return Vec4i._(p); } factory Vec4i.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec4i._(ptr, attach); factory Vec4i.fromNative(cvg.Vec4i v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4; return Vec4i._(p); } @@ -755,27 +731,25 @@ class Vec6i extends CvVec { } } factory Vec6i(int v1, int v2, int v3, int v4, int v5, int v6) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4 - ..ref.val5 = v5 - ..ref.val6 = v6; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4 + ..ref.val5 = v5 + ..ref.val6 = v6; return Vec6i._(p); } factory Vec6i.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec6i._(ptr, attach); factory Vec6i.fromNative(cvg.Vec6i v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4 - ..ref.val5 = v.val5 - ..ref.val6 = v.val6; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4 + ..ref.val5 = v.val5 + ..ref.val6 = v.val6; return Vec6i._(p); } @@ -834,31 +808,29 @@ class Vec8i extends CvVec { } } factory Vec8i(int v1, int v2, int v3, int v4, int v5, int v6, int v7, int v8) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4 - ..ref.val5 = v5 - ..ref.val6 = v6 - ..ref.val7 = v7 - ..ref.val8 = v8; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4 + ..ref.val5 = v5 + ..ref.val6 = v6 + ..ref.val7 = v7 + ..ref.val8 = v8; return Vec8i._(p); } factory Vec8i.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec8i._(ptr, attach); factory Vec8i.fromNative(cvg.Vec8i v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4 - ..ref.val5 = v.val5 - ..ref.val6 = v.val6 - ..ref.val7 = v.val7 - ..ref.val8 = v.val8; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4 + ..ref.val5 = v.val5 + ..ref.val6 = v.val6 + ..ref.val7 = v.val7 + ..ref.val8 = v.val8; return Vec8i._(p); } @@ -925,19 +897,17 @@ class Vec2f extends CvVec { } } factory Vec2f(double v1, double v2) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2; return Vec2f._(p); } factory Vec2f.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec2f._(ptr, attach); factory Vec2f.fromNative(cvg.Vec2f v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2; return Vec2f._(p); } @@ -980,21 +950,19 @@ class Vec3f extends CvVec { } } factory Vec3f(double v1, double v2, double v3) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3; return Vec3f._(p); } factory Vec3f.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec3f._(ptr, attach); factory Vec3f.fromNative(cvg.Vec3f v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3; return Vec3f._(p); } @@ -1042,23 +1010,21 @@ class Vec4f extends CvVec { } } factory Vec4f(double v1, double v2, double v3, double v4) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4; return Vec4f._(p); } factory Vec4f.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec4f._(ptr, attach); factory Vec4f.fromNative(cvg.Vec4f v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4; return Vec4f._(p); } @@ -1110,27 +1076,25 @@ class Vec6f extends CvVec { } } factory Vec6f(double v1, double v2, double v3, double v4, double v5, double v6) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4 - ..ref.val5 = v5 - ..ref.val6 = v6; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4 + ..ref.val5 = v5 + ..ref.val6 = v6; return Vec6f._(p); } factory Vec6f.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec6f._(ptr, attach); factory Vec6f.fromNative(cvg.Vec6f v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4 - ..ref.val5 = v.val5 - ..ref.val6 = v.val6; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4 + ..ref.val5 = v.val5 + ..ref.val6 = v.val6; return Vec6f._(p); } @@ -1190,19 +1154,17 @@ class Vec2d extends CvVec { } } factory Vec2d(double v1, double v2) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2; return Vec2d._(p); } factory Vec2d.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec2d._(ptr, attach); factory Vec2d.fromNative(cvg.Vec2d v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2; return Vec2d._(p); } @@ -1245,21 +1207,19 @@ class Vec3d extends CvVec { } } factory Vec3d(double v1, double v2, double v3) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3; return Vec3d._(p); } factory Vec3d.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec3d._(ptr, attach); factory Vec3d.fromNative(cvg.Vec3d v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3; return Vec3d._(p); } @@ -1307,23 +1267,21 @@ class Vec4d extends CvVec { } } factory Vec4d(double v1, double v2, double v3, double v4) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4; return Vec4d._(p); } factory Vec4d.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec4d._(ptr, attach); factory Vec4d.fromNative(cvg.Vec4d v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4; return Vec4d._(p); } @@ -1375,27 +1333,25 @@ class Vec6d extends CvVec { } } factory Vec6d(double v1, double v2, double v3, double v4, double v5, double v6) { - final p = - calloc() - ..ref.val1 = v1 - ..ref.val2 = v2 - ..ref.val3 = v3 - ..ref.val4 = v4 - ..ref.val5 = v5 - ..ref.val6 = v6; + final p = calloc() + ..ref.val1 = v1 + ..ref.val2 = v2 + ..ref.val3 = v3 + ..ref.val4 = v4 + ..ref.val5 = v5 + ..ref.val6 = v6; return Vec6d._(p); } factory Vec6d.fromPointer(ffi.Pointer ptr, [bool attach = true]) => Vec6d._(ptr, attach); factory Vec6d.fromNative(cvg.Vec6d v) { - final p = - calloc() - ..ref.val1 = v.val1 - ..ref.val2 = v.val2 - ..ref.val3 = v.val3 - ..ref.val4 = v.val4 - ..ref.val5 = v.val5 - ..ref.val6 = v.val6; + final p = calloc() + ..ref.val1 = v.val1 + ..ref.val2 = v.val2 + ..ref.val3 = v.val3 + ..ref.val4 = v.val4 + ..ref.val5 = v.val5 + ..ref.val6 = v.val6; return Vec6d._(p); } diff --git a/packages/dartcv/lib/src/core/dmatch.dart b/packages/dartcv/lib/src/core/dmatch.dart index 5e1bab45..e7118f00 100644 --- a/packages/dartcv/lib/src/core/dmatch.dart +++ b/packages/dartcv/lib/src/core/dmatch.dart @@ -20,12 +20,11 @@ class DMatch extends CvStruct { } } factory DMatch(int queryIdx, int trainIdx, int imgIdx, double distance) { - final ptr = - calloc() - ..ref.queryIdx = queryIdx - ..ref.trainIdx = trainIdx - ..ref.imgIdx = imgIdx - ..ref.distance = distance; + final ptr = calloc() + ..ref.queryIdx = queryIdx + ..ref.trainIdx = trainIdx + ..ref.imgIdx = imgIdx + ..ref.distance = distance; return DMatch._(ptr); } factory DMatch.fromNative(cvg.DMatch r) => DMatch(r.queryIdx, r.trainIdx, r.imgIdx, r.distance); diff --git a/packages/dartcv/lib/src/core/keypoint.dart b/packages/dartcv/lib/src/core/keypoint.dart index 8790e170..85ca2e87 100644 --- a/packages/dartcv/lib/src/core/keypoint.dart +++ b/packages/dartcv/lib/src/core/keypoint.dart @@ -20,15 +20,14 @@ class KeyPoint extends CvStruct { } } factory KeyPoint(double x, double y, double size, double angle, double response, int octave, int classID) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y - ..ref.size = size - ..ref.angle = angle - ..ref.response = response - ..ref.octave = octave - ..ref.classID = classID; + final ptr = calloc() + ..ref.x = x + ..ref.y = y + ..ref.size = size + ..ref.angle = angle + ..ref.response = response + ..ref.octave = octave + ..ref.classID = classID; return KeyPoint._(ptr); } factory KeyPoint.fromNative(cvg.KeyPoint r) => diff --git a/packages/dartcv/lib/src/core/mat.dart b/packages/dartcv/lib/src/core/mat.dart index f62676bb..219aef6a 100644 --- a/packages/dartcv/lib/src/core/mat.dart +++ b/packages/dartcv/lib/src/core/mat.dart @@ -34,10 +34,9 @@ class Mat extends CvStruct { final p = calloc(); final (rows, cols, elemsize) = (mat.rows, mat.cols, mat.elemSize); cvRun( - () => - roi == null - ? ccore.cv_Mat_create_11(mat.ref, rows, cols, mat.type.value, 0, 0, p, ffi.nullptr) - : ccore.cv_Mat_create_13(mat.ref, roi.ref, p, ffi.nullptr), + () => roi == null + ? ccore.cv_Mat_create_11(mat.ref, rows, cols, mat.type.value, 0, 0, p, ffi.nullptr) + : ccore.cv_Mat_create_13(mat.ref, roi.ref, p, ffi.nullptr), ); final dst = Mat._(p, attach: false, externalSize: rows * cols * elemsize); if (copy) return dst.clone(); @@ -201,10 +200,9 @@ class Mat extends CvStruct { case VecF64() when rows != null && cols != null && type != null: case VecF16() when rows != null && cols != null && type != null: cvRun( - () => - copyData - ? ccore.cv_Mat_create_6(rows, cols, type.value, vec.asVoid(), p, ffi.nullptr) - : ccore.cv_Mat_create_6_no_copy(rows, cols, type.value, vec.asVoid(), p, ffi.nullptr), + () => copyData + ? ccore.cv_Mat_create_6(rows, cols, type.value, vec.asVoid(), p, ffi.nullptr) + : ccore.cv_Mat_create_6_no_copy(rows, cols, type.value, vec.asVoid(), p, ffi.nullptr), ); default: throw UnsupportedError("Unsupported Vec type ${vec.runtimeType}"); @@ -379,40 +377,33 @@ class Mat extends CvStruct { //!SECTION - Properties //SECTION - At Set - int atU8(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_u8_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_u8_2(ref, i0, i1) : ccore.cv_Mat_get_u8_3(ref, i0, i1, i2)); - - int atI8(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_i8_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_i8_2(ref, i0, i1) : ccore.cv_Mat_get_i8_3(ref, i0, i1, i2)); - - int atU16(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_u16_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_u16_2(ref, i0, i1) : ccore.cv_Mat_get_u16_3(ref, i0, i1, i2)); - - int atI16(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_i16_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_i16_2(ref, i0, i1) : ccore.cv_Mat_get_i16_3(ref, i0, i1, i2)); - - int atI32(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_i32_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_i32_2(ref, i0, i1) : ccore.cv_Mat_get_i32_3(ref, i0, i1, i2)); - - double atF32(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_f32_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_f32_2(ref, i0, i1) : ccore.cv_Mat_get_f32_3(ref, i0, i1, i2)); - - double atF64(int i0, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_get_f64_1(ref, i0) - : (i2 == null ? ccore.cv_Mat_get_f64_2(ref, i0, i1) : ccore.cv_Mat_get_f64_3(ref, i0, i1, i2)); + int atU8(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_u8_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_u8_2(ref, i0, i1) : ccore.cv_Mat_get_u8_3(ref, i0, i1, i2)); + + int atI8(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_i8_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_i8_2(ref, i0, i1) : ccore.cv_Mat_get_i8_3(ref, i0, i1, i2)); + + int atU16(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_u16_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_u16_2(ref, i0, i1) : ccore.cv_Mat_get_u16_3(ref, i0, i1, i2)); + + int atI16(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_i16_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_i16_2(ref, i0, i1) : ccore.cv_Mat_get_i16_3(ref, i0, i1, i2)); + + int atI32(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_i32_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_i32_2(ref, i0, i1) : ccore.cv_Mat_get_i32_3(ref, i0, i1, i2)); + + double atF32(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_f32_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_f32_2(ref, i0, i1) : ccore.cv_Mat_get_f32_3(ref, i0, i1, i2)); + + double atF64(int i0, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_get_f64_1(ref, i0) + : (i2 == null ? ccore.cv_Mat_get_f64_2(ref, i0, i1) : ccore.cv_Mat_get_f64_3(ref, i0, i1, i2)); /// wrapper of cv::Mat::at() /// @@ -548,54 +539,43 @@ class Mat extends CvStruct { //!SECTION At //SECTION - Set - void setU8(int i0, int val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_u8_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_u8_2(ref, i0, i1, val) - : ccore.cv_Mat_set_u8_3(ref, i0, i1, i2, val)); - - void setI8(int i0, int val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_i8_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_i8_2(ref, i0, i1, val) - : ccore.cv_Mat_set_i8_3(ref, i0, i1, i2, val)); - - void setU16(int i0, int val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_u16_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_u16_2(ref, i0, i1, val) - : ccore.cv_Mat_set_u16_3(ref, i0, i1, i2, val)); - - void setI16(int i0, int val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_i16_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_i16_2(ref, i0, i1, val) - : ccore.cv_Mat_set_i16_3(ref, i0, i1, i2, val)); - - void setI32(int i0, int val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_i32_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_i32_2(ref, i0, i1, val) - : ccore.cv_Mat_set_i32_3(ref, i0, i1, i2, val)); - - void setF32(int i0, double val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_f32_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_f32_2(ref, i0, i1, val) - : ccore.cv_Mat_set_f32_3(ref, i0, i1, i2, val)); - - void setF64(int i0, double val, {int? i1, int? i2}) => - i1 == null - ? ccore.cv_Mat_set_f64_1(ref, i0, val) - : (i2 == null - ? ccore.cv_Mat_set_f64_2(ref, i0, i1, val) - : ccore.cv_Mat_set_f64_3(ref, i0, i1, i2, val)); + void setU8(int i0, int val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_u8_1(ref, i0, val) + : (i2 == null ? ccore.cv_Mat_set_u8_2(ref, i0, i1, val) : ccore.cv_Mat_set_u8_3(ref, i0, i1, i2, val)); + + void setI8(int i0, int val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_i8_1(ref, i0, val) + : (i2 == null ? ccore.cv_Mat_set_i8_2(ref, i0, i1, val) : ccore.cv_Mat_set_i8_3(ref, i0, i1, i2, val)); + + void setU16(int i0, int val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_u16_1(ref, i0, val) + : (i2 == null + ? ccore.cv_Mat_set_u16_2(ref, i0, i1, val) + : ccore.cv_Mat_set_u16_3(ref, i0, i1, i2, val)); + + void setI16(int i0, int val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_i16_1(ref, i0, val) + : (i2 == null + ? ccore.cv_Mat_set_i16_2(ref, i0, i1, val) + : ccore.cv_Mat_set_i16_3(ref, i0, i1, i2, val)); + + void setI32(int i0, int val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_i32_1(ref, i0, val) + : (i2 == null + ? ccore.cv_Mat_set_i32_2(ref, i0, i1, val) + : ccore.cv_Mat_set_i32_3(ref, i0, i1, i2, val)); + + void setF32(int i0, double val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_f32_1(ref, i0, val) + : (i2 == null + ? ccore.cv_Mat_set_f32_2(ref, i0, i1, val) + : ccore.cv_Mat_set_f32_3(ref, i0, i1, i2, val)); + + void setF64(int i0, double val, {int? i1, int? i2}) => i1 == null + ? ccore.cv_Mat_set_f64_1(ref, i0, val) + : (i2 == null + ? ccore.cv_Mat_set_f64_2(ref, i0, i1, val) + : ccore.cv_Mat_set_f64_3(ref, i0, i1, i2, val)); void setVec(int row, int col, T val) { switch (val) { @@ -1237,10 +1217,9 @@ class Mat extends CvStruct { /// zeros before copying the data. /// /// https://docs.opencv.org/4.x/d3/d63/classcv_1_1Mat.html#a33fd5d125b4c302b0c9aa86980791a77 - void copyTo(Mat dst, {Mat? mask}) => - mask == null - ? cvRun(() => ccore.cv_Mat_copyTo(ref, dst.ref, ffi.nullptr)) - : cvRun(() => ccore.cv_Mat_copyTo_1(ref, dst.ref, mask.ref, ffi.nullptr)); + void copyTo(Mat dst, {Mat? mask}) => mask == null + ? cvRun(() => ccore.cv_Mat_copyTo(ref, dst.ref, ffi.nullptr)) + : cvRun(() => ccore.cv_Mat_copyTo_1(ref, dst.ref, mask.ref, ffi.nullptr)); /// Converts an array to another data type with optional scaling. /// diff --git a/packages/dartcv/lib/src/core/mat_async.dart b/packages/dartcv/lib/src/core/mat_async.dart index 2b436838..9ff7e3aa 100644 --- a/packages/dartcv/lib/src/core/mat_async.dart +++ b/packages/dartcv/lib/src/core/mat_async.dart @@ -70,10 +70,9 @@ extension MatAsync on Mat { } Future copyToAsync(Mat dst, {Mat? mask}) async => cvRunAsync0( - (callback) => - mask == null - ? ccore.cv_Mat_copyTo(ref, dst.ref, callback) - : ccore.cv_Mat_copyTo_1(ref, dst.ref, mask.ref, callback), + (callback) => mask == null + ? ccore.cv_Mat_copyTo(ref, dst.ref, callback) + : ccore.cv_Mat_copyTo_1(ref, dst.ref, mask.ref, callback), (c) => c.complete(), ); diff --git a/packages/dartcv/lib/src/core/point.dart b/packages/dartcv/lib/src/core/point.dart index 0baa356e..56b4cb3e 100644 --- a/packages/dartcv/lib/src/core/point.dart +++ b/packages/dartcv/lib/src/core/point.dart @@ -19,10 +19,9 @@ class Point extends CvStruct { } } factory Point(int x, int y) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y; + final ptr = calloc() + ..ref.x = x + ..ref.y = y; return Point.fromPointer(ptr); } factory Point.fromNative(cvg.CvPoint p) => Point(p.x, p.y); @@ -55,10 +54,9 @@ class Point2f extends CvStruct { } } factory Point2f(double x, double y) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y; + final ptr = calloc() + ..ref.x = x + ..ref.y = y; return Point2f.fromPointer(ptr); } factory Point2f.fromNative(cvg.CvPoint2f p) => Point2f(p.x, p.y); @@ -91,10 +89,9 @@ class Point2d extends CvStruct { } } factory Point2d(double x, double y) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y; + final ptr = calloc() + ..ref.x = x + ..ref.y = y; return Point2d.fromPointer(ptr); } factory Point2d.fromNative(cvg.CvPoint2d p) => Point2d(p.x, p.y); @@ -127,11 +124,10 @@ class Point3f extends CvStruct { } } factory Point3f(double x, double y, double z) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y - ..ref.z = z; + final ptr = calloc() + ..ref.x = x + ..ref.y = y + ..ref.z = z; return Point3f.fromPointer(ptr); } factory Point3f.fromNative(cvg.CvPoint3f p) => Point3f(p.x, p.y, p.z); @@ -167,11 +163,10 @@ class Point3i extends CvStruct { } } factory Point3i(int x, int y, int z) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y - ..ref.z = z; + final ptr = calloc() + ..ref.x = x + ..ref.y = y + ..ref.z = z; return Point3i.fromPointer(ptr); } factory Point3i.fromNative(cvg.CvPoint3i p) => Point3i(p.x, p.y, p.z); diff --git a/packages/dartcv/lib/src/core/rect.dart b/packages/dartcv/lib/src/core/rect.dart index cb5a77de..c9dc87ac 100644 --- a/packages/dartcv/lib/src/core/rect.dart +++ b/packages/dartcv/lib/src/core/rect.dart @@ -20,12 +20,11 @@ class Rect extends CvStruct { } } factory Rect(int x, int y, int width, int height) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y - ..ref.width = width - ..ref.height = height; + final ptr = calloc() + ..ref.x = x + ..ref.y = y + ..ref.width = width + ..ref.height = height; return Rect._(ptr); } factory Rect.fromNative(cvg.CvRect p) => Rect(p.x, p.y, p.width, p.height); @@ -68,12 +67,11 @@ class Rect2f extends CvStruct { } } factory Rect2f(double x, double y, double width, double height) { - final ptr = - calloc() - ..ref.x = x - ..ref.y = y - ..ref.width = width - ..ref.height = height; + final ptr = calloc() + ..ref.x = x + ..ref.y = y + ..ref.width = width + ..ref.height = height; return Rect2f._(ptr); } factory Rect2f.fromNative(cvg.CvRect2f p) => Rect2f(p.x, p.y, p.width, p.height); @@ -117,15 +115,13 @@ class RotatedRect extends CvStruct { } } factory RotatedRect(Point2f center, (double, double) size, double angle) { - final sz = - calloc() - ..ref.width = size.$1 - ..ref.height = size.$2; - final ptr = - calloc() - ..ref.center = center.ref - ..ref.size = sz.ref - ..ref.angle = angle; + final sz = calloc() + ..ref.width = size.$1 + ..ref.height = size.$2; + final ptr = calloc() + ..ref.center = center.ref + ..ref.size = sz.ref + ..ref.angle = angle; final rect = RotatedRect._(ptr); calloc.free(sz); return rect; diff --git a/packages/dartcv/lib/src/core/scalar.dart b/packages/dartcv/lib/src/core/scalar.dart index c694cdb5..31eba49f 100644 --- a/packages/dartcv/lib/src/core/scalar.dart +++ b/packages/dartcv/lib/src/core/scalar.dart @@ -18,12 +18,11 @@ class Scalar extends CvStruct { } factory Scalar([double val1 = 0.0, double val2 = 0.0, double val3 = 0.0, double val4 = 0.0]) { - final p = - calloc() - ..ref.val1 = val1 - ..ref.val2 = val2 - ..ref.val3 = val3 - ..ref.val4 = val4; + final p = calloc() + ..ref.val1 = val1 + ..ref.val2 = val2 + ..ref.val3 = val3 + ..ref.val4 = val4; return Scalar._(p); } factory Scalar.fromNative(cvg.Scalar s) => Scalar(s.val1, s.val2, s.val3, s.val4); diff --git a/packages/dartcv/lib/src/core/size.dart b/packages/dartcv/lib/src/core/size.dart index c7469018..6a1dfd26 100644 --- a/packages/dartcv/lib/src/core/size.dart +++ b/packages/dartcv/lib/src/core/size.dart @@ -17,20 +17,18 @@ class Size extends CvStruct { } factory Size(int width, int height) { - final p = - calloc() - ..ref.height = height - ..ref.width = width; + final p = calloc() + ..ref.height = height + ..ref.width = width; return Size.fromPointer(p); } factory Size.fromNative(cvg.CvSize sz) => Size(sz.width, sz.height); factory Size.fromRecord((int, int) record) { - final p = - calloc() - ..ref.height = record.$2 - ..ref.width = record.$1; + final p = calloc() + ..ref.height = record.$2 + ..ref.width = record.$1; return Size.fromPointer(p); } @@ -67,28 +65,25 @@ class Size2f extends CvStruct { } factory Size2f(double width, double height) { - final p = - calloc() - ..ref.height = height - ..ref.width = width; + final p = calloc() + ..ref.height = height + ..ref.width = width; return Size2f.fromPointer(p); } factory Size2f.fromNative(cvg.CvSize2f sz) => Size2f(sz.width, sz.height); factory Size2f.fromRecord((double, double) record) { - final p = - calloc() - ..ref.height = record.$2 - ..ref.width = record.$1; + final p = calloc() + ..ref.height = record.$2 + ..ref.width = record.$1; return Size2f.fromPointer(p); } factory Size2f.fromSize(Size size) { - final p = - calloc() - ..ref.height = size.height.toDouble() - ..ref.width = size.width.toDouble(); + final p = calloc() + ..ref.height = size.height.toDouble() + ..ref.width = size.width.toDouble(); return Size2f.fromPointer(p); } diff --git a/packages/dartcv/lib/src/core/termcriteria.dart b/packages/dartcv/lib/src/core/termcriteria.dart index 95ffb912..fc2e2372 100644 --- a/packages/dartcv/lib/src/core/termcriteria.dart +++ b/packages/dartcv/lib/src/core/termcriteria.dart @@ -23,11 +23,10 @@ class TermCriteria extends CvStruct { } factory TermCriteria(int type, int cound, double eps) { - final p = - calloc() - ..ref.type = type - ..ref.maxCount = cound - ..ref.epsilon = eps; + final p = calloc() + ..ref.type = type + ..ref.maxCount = cound + ..ref.epsilon = eps; return TermCriteria.fromPointer(p); } diff --git a/packages/dartcv/lib/src/imgproc/clahe.dart b/packages/dartcv/lib/src/imgproc/clahe.dart index 28a5589a..cb9bbcdc 100644 --- a/packages/dartcv/lib/src/imgproc/clahe.dart +++ b/packages/dartcv/lib/src/imgproc/clahe.dart @@ -35,10 +35,9 @@ class CLAHE extends CvStruct { /// https:///docs.opencv.org/master/d6/db6/classcv_1_1CLAHE.html factory CLAHE.create([double clipLimit = 40, (int width, int height) tileGridSize = (8, 8)]) { final p = calloc(); - final size = - calloc() - ..ref.width = tileGridSize.$1 - ..ref.height = tileGridSize.$2; + final size = calloc() + ..ref.width = tileGridSize.$1 + ..ref.height = tileGridSize.$2; cimgproc.cv_CLAHE_create_1(clipLimit, size.ref, p); calloc.free(size); return CLAHE._(p); diff --git a/packages/dartcv/lib/src/stitching/stitching.dart b/packages/dartcv/lib/src/stitching/stitching.dart index fe834724..8f6975de 100644 --- a/packages/dartcv/lib/src/stitching/stitching.dart +++ b/packages/dartcv/lib/src/stitching/stitching.dart @@ -102,8 +102,8 @@ class Stitcher extends CvStruct { images == null ? cvRun(() => cstitching.cv_Stitcher_composePanorama(ref, rpano.ref, rptr, ffi.nullptr)) : cvRun( - () => cstitching.cv_Stitcher_composePanorama_1(ref, images.ref, rpano.ref, rptr, ffi.nullptr), - ); + () => cstitching.cv_Stitcher_composePanorama_1(ref, images.ref, rpano.ref, rptr, ffi.nullptr), + ); final rval = (StitcherStatus.fromInt(rptr.value), rpano); calloc.free(rptr); return rval; @@ -118,8 +118,8 @@ class Stitcher extends CvStruct { masks == null ? cvRun(() => cstitching.cv_Stitcher_stitch(ref, images.ref, rpano.ref, rptr, ffi.nullptr)) : cvRun( - () => cstitching.cv_Stitcher_stitch_1(ref, images.ref, masks.ref, rpano.ref, rptr, ffi.nullptr), - ); + () => cstitching.cv_Stitcher_stitch_1(ref, images.ref, masks.ref, rpano.ref, rptr, ffi.nullptr), + ); final rval = (StitcherStatus.fromInt(rptr.value), rpano); calloc.free(rptr); return rval; diff --git a/packages/dartcv/lib/src/videoio/videoio.dart b/packages/dartcv/lib/src/videoio/videoio.dart index b824d274..63a86c07 100644 --- a/packages/dartcv/lib/src/videoio/videoio.dart +++ b/packages/dartcv/lib/src/videoio/videoio.dart @@ -169,30 +169,30 @@ class VideoWriter extends CvStruct { final codec_ = VideoWriter.fourcc(codec); apiPreference == null ? cvRun( - () => cvideoio.cv_VideoWriter_create_1( - cname.cast(), - codec_, - fps, - frameSize.$1, - frameSize.$2, - isColor, - p, - ffi.nullptr, - ), - ) + () => cvideoio.cv_VideoWriter_create_1( + cname.cast(), + codec_, + fps, + frameSize.$1, + frameSize.$2, + isColor, + p, + ffi.nullptr, + ), + ) : cvRun( - () => cvideoio.cv_VideoWriter_create_2( - cname.cast(), - apiPreference, - codec_, - fps, - frameSize.$1, - frameSize.$2, - isColor, - p, - ffi.nullptr, - ), - ); + () => cvideoio.cv_VideoWriter_create_2( + cname.cast(), + apiPreference, + codec_, + fps, + frameSize.$1, + frameSize.$2, + isColor, + p, + ffi.nullptr, + ), + ); calloc.free(cname); return VideoWriter._(p); } @@ -210,32 +210,32 @@ class VideoWriter extends CvStruct { final p = calloc(); apiPreference == null ? cvRun( - () => cvideoio.cv_VideoWriter_open( - ref, - cname, - codec_, - fps, - frameSize.$1, - frameSize.$2, - isColor, - p, - ffi.nullptr, - ), - ) + () => cvideoio.cv_VideoWriter_open( + ref, + cname, + codec_, + fps, + frameSize.$1, + frameSize.$2, + isColor, + p, + ffi.nullptr, + ), + ) : cvRun( - () => cvideoio.cv_VideoWriter_open_1( - ref, - cname, - apiPreference, - codec_, - fps, - frameSize.$1, - frameSize.$2, - isColor, - p, - ffi.nullptr, - ), - ); + () => cvideoio.cv_VideoWriter_open_1( + ref, + cname, + apiPreference, + codec_, + fps, + frameSize.$1, + frameSize.$2, + isColor, + p, + ffi.nullptr, + ), + ); calloc.free(cname); calloc.free(p); } diff --git a/packages/dartcv/pubspec.yaml b/packages/dartcv/pubspec.yaml index 9532eaae..c8d36fc0 100644 --- a/packages/dartcv/pubspec.yaml +++ b/packages/dartcv/pubspec.yaml @@ -1,8 +1,8 @@ name: dartcv4 description: > OpenCV bindings for Dart language. dartcv is for pure dart only, - for Flutter, use opencv_core or opencv_dart (if videoio module is required). -version: 1.1.3 + for Flutter, use opencv_core or opencv_dart. +version: 1.1.4 repository: https://github.com/rainyl/opencv_dart homepage: https://github.com/rainyl/opencv_dart/tree/main/packages/dartcv @@ -11,6 +11,7 @@ environment: dependencies: ffi: ^2.1.3 + yaml: ^3.1.3 dev_dependencies: ffigen: ">=13.0.0 <19.0.0" diff --git a/packages/dartcv/test/contrib/aruco_test.dart b/packages/dartcv/test/contrib/aruco_test.dart index dced1981..8900b875 100644 --- a/packages/dartcv/test/contrib/aruco_test.dart +++ b/packages/dartcv/test/contrib/aruco_test.dart @@ -99,37 +99,36 @@ void main() async { const int aprilTagMinWhiteBlackDiff = 1; const int aprilTagDeglitch = 1; const bool detectInvertedMarker = false; - final params = - cv.ArucoDetectorParameters.empty() - ..adaptiveThreshWinSizeMin = adaptiveThreshWinSizeMin - ..adaptiveThreshWinSizeMax = adaptiveThreshWinSizeMax - ..adaptiveThreshWinSizeStep = adaptiveThreshWinSizeStep - ..adaptiveThreshConstant = adaptiveThreshConstant - ..minMarkerPerimeterRate = minMarkerPerimeterRate - ..maxMarkerPerimeterRate = maxMarkerPerimeterRate - ..polygonalApproxAccuracyRate = polygonalApproxAccuracyRate - ..minCornerDistanceRate = minCornerDistanceRate - ..minDistanceToBorder = minDistanceToBorder - ..minMarkerDistanceRate = minMarkerDistanceRate - ..cornerRefinementMethod = cornerRefinementMethod - ..cornerRefinementWinSize = cornerRefinementWinSize - ..cornerRefinementMaxIterations = cornerRefinementMaxIterations - ..cornerRefinementMinAccuracy = cornerRefinementMinAccuracy - ..markerBorderBits = markerBorderBits - ..perspectiveRemovePixelPerCell = perspectiveRemovePixelPerCell - ..perspectiveRemoveIgnoredMarginPerCell = perspectiveRemoveIgnoredMarginPerCell - ..maxErroneousBitsInBorderRate = maxErroneousBitsInBorderRate - ..minOtsuStdDev = minOtsuStdDev - ..errorCorrectionRate = errorCorrectionRate - ..aprilTagQuadDecimate = aprilTagQuadDecimate - ..aprilTagQuadSigma = aprilTagQuadSigma - ..aprilTagMinClusterPixels = aprilTagMinClusterPixels - ..aprilTagMaxNmaxima = aprilTagMaxNmaxima - ..aprilTagCriticalRad = aprilTagCriticalRad - ..aprilTagMaxLineFitMse = aprilTagMaxLineFitMse - ..aprilTagMinWhiteBlackDiff = aprilTagMinWhiteBlackDiff - ..aprilTagDeglitch = aprilTagDeglitch - ..detectInvertedMarker = detectInvertedMarker; + final params = cv.ArucoDetectorParameters.empty() + ..adaptiveThreshWinSizeMin = adaptiveThreshWinSizeMin + ..adaptiveThreshWinSizeMax = adaptiveThreshWinSizeMax + ..adaptiveThreshWinSizeStep = adaptiveThreshWinSizeStep + ..adaptiveThreshConstant = adaptiveThreshConstant + ..minMarkerPerimeterRate = minMarkerPerimeterRate + ..maxMarkerPerimeterRate = maxMarkerPerimeterRate + ..polygonalApproxAccuracyRate = polygonalApproxAccuracyRate + ..minCornerDistanceRate = minCornerDistanceRate + ..minDistanceToBorder = minDistanceToBorder + ..minMarkerDistanceRate = minMarkerDistanceRate + ..cornerRefinementMethod = cornerRefinementMethod + ..cornerRefinementWinSize = cornerRefinementWinSize + ..cornerRefinementMaxIterations = cornerRefinementMaxIterations + ..cornerRefinementMinAccuracy = cornerRefinementMinAccuracy + ..markerBorderBits = markerBorderBits + ..perspectiveRemovePixelPerCell = perspectiveRemovePixelPerCell + ..perspectiveRemoveIgnoredMarginPerCell = perspectiveRemoveIgnoredMarginPerCell + ..maxErroneousBitsInBorderRate = maxErroneousBitsInBorderRate + ..minOtsuStdDev = minOtsuStdDev + ..errorCorrectionRate = errorCorrectionRate + ..aprilTagQuadDecimate = aprilTagQuadDecimate + ..aprilTagQuadSigma = aprilTagQuadSigma + ..aprilTagMinClusterPixels = aprilTagMinClusterPixels + ..aprilTagMaxNmaxima = aprilTagMaxNmaxima + ..aprilTagCriticalRad = aprilTagCriticalRad + ..aprilTagMaxLineFitMse = aprilTagMaxLineFitMse + ..aprilTagMinWhiteBlackDiff = aprilTagMinWhiteBlackDiff + ..aprilTagDeglitch = aprilTagDeglitch + ..detectInvertedMarker = detectInvertedMarker; expect(params.adaptiveThreshWinSizeMin, adaptiveThreshWinSizeMin); expect(params.adaptiveThreshWinSizeMax, adaptiveThreshWinSizeMax); diff --git a/packages/dartcv/test/core/core_async_test.dart b/packages/dartcv/test/core/core_async_test.dart index 5466be0a..93e8ab17 100644 --- a/packages/dartcv/test/core/core_async_test.dart +++ b/packages/dartcv/test/core/core_async_test.dart @@ -410,12 +410,11 @@ void main() async { }); test('cv.merge async', () async { - final src = - [ - cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), - cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), - cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), - ].cvd; + final src = [ + cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), + cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), + cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), + ].cvd; final dst = await cv.mergeAsync(src); expect(dst.isEmpty, equals(false)); expect(dst.channels, equals(3)); diff --git a/packages/dartcv/test/core/core_test.dart b/packages/dartcv/test/core/core_test.dart index e5a8062b..b8badb1d 100644 --- a/packages/dartcv/test/core/core_test.dart +++ b/packages/dartcv/test/core/core_test.dart @@ -680,12 +680,11 @@ void main() async { }); test('cv.merge', () { - final src = - [ - cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), - cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), - cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), - ].cvd; + final src = [ + cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), + cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), + cv.Mat.randu(101, 102, cv.MatType.CV_8UC1), + ].cvd; final dst = cv.merge(src); expect(dst.isEmpty, equals(false)); expect(dst.channels, equals(3)); diff --git a/packages/dartcv/test/dnn/dnn_async_test.dart b/packages/dartcv/test/dnn/dnn_async_test.dart index 53062a3c..ceed0445 100644 --- a/packages/dartcv/test/dnn/dnn_async_test.dart +++ b/packages/dartcv/test/dnn/dnn_async_test.dart @@ -221,11 +221,10 @@ void main() async { }); test('cv.blobFromImagesAsync, cv.imagesFromBlobAsync, cv.getBlobChannelAsync', () async { - final imgs = - [ - await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR), - await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR), - ].cvd; + final imgs = [ + await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR), + await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_COLOR), + ].cvd; final blob = await cv.blobFromImagesAsync(imgs); expect(blob.isEmpty, false); @@ -242,11 +241,10 @@ void main() async { }); test('cv.blobFromImagesAsync GrayScale', () async { - final imgs = - [ - await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), - await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), - ].cvd; + final imgs = [ + await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), + await cv.imreadAsync("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), + ].cvd; final blob = await cv.blobFromImagesAsync(imgs); expect(blob.isEmpty, false); @@ -258,14 +256,13 @@ void main() async { expect(img.isEmpty, false); img = await img.convertToAsync(cv.MatType.CV_32FC1); - final bboxes = - [ - cv.Rect(53, 47, 589, 451), - cv.Rect(118, 54, 618, 450), - cv.Rect(53, 66, 605, 480), - cv.Rect(111, 65, 630, 480), - cv.Rect(156, 51, 640, 480), - ].cvd; + final bboxes = [ + cv.Rect(53, 47, 589, 451), + cv.Rect(118, 54, 618, 450), + cv.Rect(53, 66, 605, 480), + cv.Rect(111, 65, 630, 480), + cv.Rect(156, 51, 640, 480), + ].cvd; final scores = [0.82094115, 0.7998236, 0.9809663, 0.99717456, 0.89628726].f32; final indices = await cv.NMSBoxesAsync(bboxes, scores, 0.5, 0.4); expect(indices.first, 3); diff --git a/packages/dartcv/test/dnn/dnn_test.dart b/packages/dartcv/test/dnn/dnn_test.dart index 28896544..de56e4fd 100644 --- a/packages/dartcv/test/dnn/dnn_test.dart +++ b/packages/dartcv/test/dnn/dnn_test.dart @@ -237,11 +237,10 @@ void main() async { }); test('cv.blobFromImages, cv.imagesFromBlob, cv.getBlobChannel', () { - final imgs = - [ - cv.imread("test/images/lenna.png", flags: cv.IMREAD_COLOR), - cv.imread("test/images/lenna.png", flags: cv.IMREAD_COLOR), - ].cvd; + final imgs = [ + cv.imread("test/images/lenna.png", flags: cv.IMREAD_COLOR), + cv.imread("test/images/lenna.png", flags: cv.IMREAD_COLOR), + ].cvd; final blob = cv.blobFromImages(imgs); expect(blob.isEmpty, false); @@ -258,11 +257,10 @@ void main() async { }); test('cv.blobFromImages GrayScale', () { - final imgs = - [ - cv.imread("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), - cv.imread("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), - ].cvd; + final imgs = [ + cv.imread("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), + cv.imread("test/images/lenna.png", flags: cv.IMREAD_GRAYSCALE), + ].cvd; final blob = cv.blobFromImages(imgs); expect(blob.isEmpty, false); @@ -275,14 +273,13 @@ void main() async { img.convertTo(cv.MatType.CV_32FC1); - final bboxes = - [ - cv.Rect(53, 47, 589, 451), - cv.Rect(118, 54, 618, 450), - cv.Rect(53, 66, 605, 480), - cv.Rect(111, 65, 630, 480), - cv.Rect(156, 51, 640, 480), - ].cvd; + final bboxes = [ + cv.Rect(53, 47, 589, 451), + cv.Rect(118, 54, 618, 450), + cv.Rect(53, 66, 605, 480), + cv.Rect(111, 65, 630, 480), + cv.Rect(156, 51, 640, 480), + ].cvd; final scores = [0.82094115, 0.7998236, 0.9809663, 0.99717456, 0.89628726].f32; final indices = cv.NMSBoxes(bboxes, scores, 0.5, 0.4); expect(indices.first, 3); diff --git a/packages/dartcv/test/imgproc/imgproc_async_test.dart b/packages/dartcv/test/imgproc/imgproc_async_test.dart index 89113c10..db2eb99a 100644 --- a/packages/dartcv/test/imgproc/imgproc_async_test.dart +++ b/packages/dartcv/test/imgproc/imgproc_async_test.dart @@ -268,18 +268,17 @@ void main() async { // fitEllipse test('cv.fitEllipseAsync', () async { - final pv = - [ - cv.Point(1, 1), - cv.Point(0, 1), - cv.Point(0, 2), - cv.Point(1, 3), - cv.Point(2, 3), - cv.Point(4, 2), - cv.Point(4, 1), - cv.Point(0, 3), - cv.Point(0, 2), - ].cvd; + final pv = [ + cv.Point(1, 1), + cv.Point(0, 1), + cv.Point(0, 2), + cv.Point(1, 3), + cv.Point(2, 3), + cv.Point(4, 2), + cv.Point(4, 1), + cv.Point(0, 3), + cv.Point(0, 2), + ].cvd; final rect = await cv.fitEllipseAsync(pv); expect(rect.center.x, closeTo(1.92, 0.1)); expect(rect.center.y, closeTo(1.78, 0.1)); @@ -852,8 +851,9 @@ void main() async { handleNested: handleNested, ); if (intersectArea > 0) { - final fillColor = - !cv.isContourConvex(p1) || !cv.isContourConvex(p2) ? cv.Scalar(0, 0, 255) : cv.Scalar.all(200); + final fillColor = !cv.isContourConvex(p1) || !cv.isContourConvex(p2) + ? cv.Scalar(0, 0, 255) + : cv.Scalar.all(200); await cv.fillPolyAsync(image, cv.VecVecPoint.fromVecPoint(intersectionPolygon), fillColor); } await cv.polylinesAsync(image, cv.VecVecPoint.fromVecPoint(intersectionPolygon), true, cv.Scalar.black); @@ -943,15 +943,14 @@ void main() async { await drawDescription(image, intersectionArea.toInt(), "", cv.Point(70, 520)); // This concave polygon is invalid input to intersectConvexConvex so it returns an invalid intersection - final cv.VecPoint notConvex = - [ - cv.Point(25, 560), - cv.Point(25, 590), - cv.Point(45, 580), - cv.Point(60, 600), - cv.Point(60, 550), - cv.Point(45, 570), - ].asVec(); + final cv.VecPoint notConvex = [ + cv.Point(25, 560), + cv.Point(25, 590), + cv.Point(45, 580), + cv.Point(60, 600), + cv.Point(60, 550), + cv.Point(45, 570), + ].asVec(); intersectionArea = await drawIntersection( image, makeRectangle(cv.Point(10, 550), cv.Point(50, 600)), diff --git a/packages/dartcv/test/imgproc/imgproc_test.dart b/packages/dartcv/test/imgproc/imgproc_test.dart index 020af160..dcbde331 100644 --- a/packages/dartcv/test/imgproc/imgproc_test.dart +++ b/packages/dartcv/test/imgproc/imgproc_test.dart @@ -290,18 +290,17 @@ void main() async { // fitEllipse test('cv.fitEllipse', () { - final pv = - [ - cv.Point(1, 1), - cv.Point(0, 1), - cv.Point(0, 2), - cv.Point(1, 3), - cv.Point(2, 3), - cv.Point(4, 2), - cv.Point(4, 1), - cv.Point(0, 3), - cv.Point(0, 2), - ].cvd; + final pv = [ + cv.Point(1, 1), + cv.Point(0, 1), + cv.Point(0, 2), + cv.Point(1, 3), + cv.Point(2, 3), + cv.Point(4, 2), + cv.Point(4, 1), + cv.Point(0, 3), + cv.Point(0, 2), + ].cvd; final rect = cv.fitEllipse(pv); expect(rect.center.x, closeTo(1.92, 0.1)); expect(rect.center.y, closeTo(1.78, 0.1)); @@ -854,15 +853,14 @@ void main() async { final res = cv.isContourConvex(rectangle); expect(res, true); - final notConvex = - [ - cv.Point(25, 560), - cv.Point(25, 590), - cv.Point(45, 580), - cv.Point(60, 600), - cv.Point(60, 550), - cv.Point(45, 570), - ].asVec(); + final notConvex = [ + cv.Point(25, 560), + cv.Point(25, 590), + cv.Point(45, 580), + cv.Point(60, 600), + cv.Point(60, 550), + cv.Point(45, 570), + ].asVec(); expect(cv.isContourConvex(notConvex), false); }); @@ -879,8 +877,9 @@ void main() async { handleNested: handleNested, ); if (intersectArea > 0) { - final fillColor = - !cv.isContourConvex(p1) || !cv.isContourConvex(p2) ? cv.Scalar(0, 0, 255) : cv.Scalar.all(200); + final fillColor = !cv.isContourConvex(p1) || !cv.isContourConvex(p2) + ? cv.Scalar(0, 0, 255) + : cv.Scalar.all(200); cv.fillPoly(image, cv.VecVecPoint.fromVecPoint(intersectionPolygon), fillColor); } cv.polylines(image, cv.VecVecPoint.fromVecPoint(intersectionPolygon), true, cv.Scalar.black); @@ -965,15 +964,14 @@ void main() async { drawDescription(image, intersectionArea.toInt(), "", cv.Point(70, 520)); // This concave polygon is invalid input to intersectConvexConvex so it returns an invalid intersection - final cv.VecPoint notConvex = - [ - cv.Point(25, 560), - cv.Point(25, 590), - cv.Point(45, 580), - cv.Point(60, 600), - cv.Point(60, 550), - cv.Point(45, 570), - ].asVec(); + final cv.VecPoint notConvex = [ + cv.Point(25, 560), + cv.Point(25, 590), + cv.Point(45, 580), + cv.Point(60, 600), + cv.Point(60, 550), + cv.Point(45, 570), + ].asVec(); intersectionArea = drawIntersection( image, makeRectangle(cv.Point(10, 550), cv.Point(50, 600)), diff --git a/packages/opencv_core/CHANGELOG.md b/packages/opencv_core/CHANGELOG.md index b1c3e8ee..158021fc 100644 --- a/packages/opencv_core/CHANGELOG.md +++ b/packages/opencv_core/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.4.2 + +* support optional modules, configure it in `pubspec.yaml`, from this version, both opencv_core and + opencv_dart can enable/disable optional modules. + ## 1.4.1 * add `VideoCapture.grabAsync` diff --git a/packages/opencv_core/README.md b/packages/opencv_core/README.md index 07db67ca..47b6335f 100644 --- a/packages/opencv_core/README.md +++ b/packages/opencv_core/README.md @@ -22,6 +22,37 @@ OpenCV for Flutter, if `highgui` or `videoio` is required, use [opencv_dart](htt [Supported modules](https://github.com/rainyl/opencv_dart?tab=readme-ov-file#status) +## Customizing OpenCV Modules + +You can enable or disable specific OpenCV modules for your build by specifying them in your app's `pubspec.yaml` file. + +> [!NOTE] +> +> Currently only Android, Windows, and Linux are supported. + +### Example `pubspec.yaml` configuration + +```yaml +# ...Your existing configuration... +hooks: + user_defines: + dartcv4: + exclude_modules: + - contrib + - dnn + - features2d + - core + include_modules: + - core # core is always required thus will be ignored even configured here. + - imgproc + - videoio +``` + +- valid modules: `core`, `calib3d`, `contrib`, `dnn`, `features2d`, `flann`, `highgui`, `imgproc`, `imgcodecs`, `objdetect`, `photo`, `stitching`, `video`, `videoio` +- Use `exclude_modules` to disable specific modules, or `include_modules` to enable specific modules. +- If neither is specified, all modules except `highgui` will be enabled. +- also refer to [example/pubspec.yaml](https://github.com/rainyl/opencv_dart/blob/main/packages/opencv_dart/example/pubspec.yaml) + ## Package Size ![opencv_dart_size_report](images/opencv_core_size_report.svg) diff --git a/packages/opencv_core/android/build.gradle b/packages/opencv_core/android/build.gradle index 493e062d..2481790d 100644 --- a/packages/opencv_core/android/build.gradle +++ b/packages/opencv_core/android/build.gradle @@ -81,7 +81,7 @@ android { } } - def targetPlatforms = project.getProperty('target-platform').split(',') as List + def targetPlatforms = (project.hasProperty('target-platform') ? project.getProperty('target-platform') : 'android-arm,android-arm64,android-x86,android-x64').split(',') as List if (!targetPlatforms.isEmpty()) { def platformAbiMap = [ 'android-arm64': 'arm64-v8a', diff --git a/packages/opencv_core/example/.gitignore b/packages/opencv_core/example/.gitignore index 29a3a501..79c113f9 100644 --- a/packages/opencv_core/example/.gitignore +++ b/packages/opencv_core/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/packages/opencv_core/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/opencv_core/example/android/gradle/wrapper/gradle-wrapper.properties index 7bb2df6b..efdcc4ac 100644 --- a/packages/opencv_core/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/opencv_core/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip diff --git a/packages/opencv_core/example/android/settings.gradle b/packages/opencv_core/example/android/settings.gradle index b9e43bd3..f7392abf 100644 --- a/packages/opencv_core/example/android/settings.gradle +++ b/packages/opencv_core/example/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.1.0" apply false + id "com.android.application" version '8.10.0' apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false } diff --git a/packages/opencv_core/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/opencv_core/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index bb927d4d..65c15db9 100644 --- a/packages/opencv_core/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/opencv_core/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -59,6 +59,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> diff --git a/packages/opencv_core/example/macos/Runner/AppDelegate.swift b/packages/opencv_core/example/macos/Runner/AppDelegate.swift index 8e02df28..b3c17614 100644 --- a/packages/opencv_core/example/macos/Runner/AppDelegate.swift +++ b/packages/opencv_core/example/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/packages/opencv_core/example/pubspec.yaml b/packages/opencv_core/example/pubspec.yaml index fd02ec78..e7a7e109 100644 --- a/packages/opencv_core/example/pubspec.yaml +++ b/packages/opencv_core/example/pubspec.yaml @@ -1,97 +1,42 @@ name: opencv_core_example description: "Demonstrates how to use the opencv_core plugin." -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -# In Windows, build-name is used as the major, minor, and patch parts -# of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: ^3.5.3 -# Dependencies specify other packages that your package needs in order to work. -# To automatically upgrade your package dependencies to the latest versions -# consider running `flutter pub upgrade --major-versions`. Alternatively, -# dependencies can be manually updated by changing the version numbers below to -# the latest version available on pub.dev. To see which dependencies have newer -# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter opencv_core: - # When depending on this package from a real application you should use: - # opencv_core: ^x.y.z - # See https://dart.dev/tools/pub/dependencies#version-constraints - # The example app is bundled with the plugin so we use a path dependency on - # the parent directory to use the current plugin's version. path: ../ + # dartcv4: ^1.1.4 - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 image_picker: ^1.0.7 dev_dependencies: flutter_test: sdk: flutter - - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. flutter_lints: ^4.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: assets: - images/lenna.png - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/to/resolution-aware-images - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/to/asset-from-package - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/to/font-from-package +hooks: + user_defines: + dartcv4: + exclude_modules: + - contrib + - dnn + - features2d + - core + include_modules: + - core + - imgproc + - videoio diff --git a/packages/opencv_core/pubspec.yaml b/packages/opencv_core/pubspec.yaml index 6f6cc1af..26402246 100644 --- a/packages/opencv_core/pubspec.yaml +++ b/packages/opencv_core/pubspec.yaml @@ -1,9 +1,7 @@ name: opencv_core description: | OpenCV4 bindings for Flutter. - This plugin does NOT include `highgui` and `videoio`, - if you need them, please use `opencv_dart` instead. -version: 1.4.1 +version: 1.4.2 opencv_version: 4.11.0+0 dartcv_version: 4.11.0.2 repository: https://github.com/rainyl/opencv_dart @@ -16,7 +14,9 @@ environment: dependencies: flutter: sdk: flutter - dartcv4: 1.1.3 + dartcv4: 1.1.4 + # dartcv4: + # path: ../dartcv dev_dependencies: test: ^1.25.2 diff --git a/packages/opencv_core/src/CMakeLists.txt b/packages/opencv_core/src/CMakeLists.txt index a0276352..7890a694 100644 --- a/packages/opencv_core/src/CMakeLists.txt +++ b/packages/opencv_core/src/CMakeLists.txt @@ -13,6 +13,79 @@ macro(_find_version _version_var _version_file _regex_find _regex_replace) endif() endmacro() +function(_parse_dartcv_cmake_vars) + # Generate module config from pubspec.yaml using Dart script + # The step should not be mendatary for better user experience + if(WIN32) + find_program(DART_EXECUTABLE dart.bat) + else() + find_program(DART_EXECUTABLE dart) + endif() + + if(NOT DART_EXECUTABLE) + message(WARNING "Dart SDK not found! Will use default modules.") + return() + else() + message(STATUS "Dart SDK found: ${DART_EXECUTABLE}") + endif() + + # Infer working directory + message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + if(ANDROID AND DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) + get_filename_component(_working_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" DIRECTORY) + elseif(WIN32 OR UNIX) + get_filename_component(_working_dir "${CMAKE_BINARY_DIR}" DIRECTORY) + endif() + + message(STATUS "WORKING_DIR: ${_working_dir}") + + if(NOT DEFINED _working_dir) + message(FATAL_ERROR "Can not infer working directory.") + endif() + + while(NOT EXISTS "${_working_dir}/build" AND NOT "${_working_dir}" STREQUAL "/") + get_filename_component(_working_dir "${_working_dir}" DIRECTORY) + endwhile() + + message(STATUS "Final WORKING_DIR: ${_working_dir}") + + execute_process( + COMMAND ${DART_EXECUTABLE} run dartcv4:gen_cmake_vars + OUTPUT_VARIABLE _output + ERROR_VARIABLE _error + WORKING_DIRECTORY ${_working_dir} + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + message(STATUS "Generate command output:\n${_output}") + + if(_error) + message(FATAL_ERROR "Error while running dartcv4:gen_cmake_vars: ${_error}") + endif(_error) + + string(REGEX MATCH "###DARTCV_GEN_CMAKE_VAR_BEGIN###\n.*###DARTCV_GEN_CMAKE_VAR_END###" _content ${_output}) + + if(_content) + string(REGEX REPLACE "###DARTCV_GEN_CMAKE_VAR_BEGIN###\n" "" _content ${_content}) + string(REGEX REPLACE "###DARTCV_GEN_CMAKE_VAR_END###" "" _content ${_content}) + string(STRIP _content ${_content}) + else() + message(WARNING "No matching DARTCV_GEN_CMAKE_VAR block found.") + return() + endif() + + # Split to lines + string(REGEX REPLACE "\r?\n" ";" _lines "${_content}") + + foreach(_line IN LISTS _lines) + if(_line MATCHES "^([^=]+)=(ON|OFF)$") + set(_var_name "DARTCV_WITH_${CMAKE_MATCH_1}") + set(_var_value "${CMAKE_MATCH_2}") + set(${_var_name} ${_var_value} CACHE BOOL "Enable OpenCV ${CMAKE_MATCH_1} module" FORCE) + endif() + endforeach() +endfunction() + _find_version(_version_project "${PROJ_DIR}/pubspec.yaml" "^version: (.+)*$" "version: (.+)*$") _find_version(_version_opencv "${PROJ_DIR}/pubspec.yaml" "^opencv_version: (.+)*$" "opencv_version: (.+)*$") _find_version(_version_dartcv "${PROJ_DIR}/pubspec.yaml" "^dartcv_version: (.+)*$" "dartcv_version: (.+)*$") @@ -34,23 +107,45 @@ if(ANDROID AND(DEFINED ANDROID_ABI)) endif() endif() -set(DARTCV_WITH_CALIB3D ON CACHE BOOL "Enable OpenCV calib3d module" FORCE) -set(DARTCV_WITH_CONTRIB ON CACHE BOOL "Enable OpenCV contrib module" FORCE) -set(DARTCV_WITH_DNN ON CACHE BOOL "Enable OpenCV dnn module" FORCE) -set(DARTCV_WITH_FEATURE2D ON CACHE BOOL "Enable OpenCV feature2d module" FORCE) -set(DARTCV_WITH_HIGHGUI OFF CACHE BOOL "Enable OpenCV highgui module" FORCE) -set(DARTCV_WITH_IMGPROC ON CACHE BOOL "Enable OpenCV imgproc module" FORCE) -set(DARTCV_WITH_OBJDETECT ON CACHE BOOL "Enable OpenCV objdetect module" FORCE) -set(DARTCV_WITH_PHOTO ON CACHE BOOL "Enable OpenCV photo module" FORCE) -set(DARTCV_WITH_STITCHING ON CACHE BOOL "Enable OpenCV stitching module" FORCE) -set(DARTCV_WITH_VIDEO ON CACHE BOOL "Enable OpenCV video module") -set(DARTCV_WITH_VIDEOIO OFF CACHE BOOL "Enable OpenCV videoio module" FORCE) +_parse_dartcv_cmake_vars() + +set(_enabled_modules "core") +set(_disabled_modules) + +# ebabled modules by default +set(_modules CALIB3D CONTRIB DNN FEATURES2D HIGHGUI IMGPROC OBJDETECT PHOTO STITCHING VIDEO VIDEOIO) + +foreach(_m IN LISTS _modules) + string(TOLOWER ${_m} _m_lower) + + if(${DARTCV_WITH_${_m}}) + set(_enabled_modules ${_enabled_modules} ${_m_lower}) + else() + set(_disabled_modules ${_disabled_modules} ${_m_lower}) + endif() +endforeach() + set(DARTCV_WITH_GAPI OFF CACHE BOOL "Enable OpenCV gapi module" FORCE) set(DARTCV_WORLD OFF CACHE BOOL "Enable OpenCV world module" FORCE) set(OPENCV_VERSION "${_version_opencv}") set(DARTCV_DISABLE_DOWNLOAD_OPENCV OFF) +message(DEBUG "DARTCV_WITH_CALIB3D: ${DARTCV_WITH_CALIB3D}") +message(DEBUG "DARTCV_WITH_CONTRIB: ${DARTCV_WITH_CONTRIB}") +message(DEBUG "DARTCV_WITH_DNN: ${DARTCV_WITH_DNN}") +message(DEBUG "DARTCV_WITH_FEATURES2D: ${DARTCV_WITH_FEATURES2D}") +message(DEBUG "DARTCV_WITH_HIGHGUI: ${DARTCV_WITH_HIGHGUI}") +message(DEBUG "DARTCV_WITH_IMGPROC: ${DARTCV_WITH_IMGPROC}") +message(DEBUG "DARTCV_WITH_OBJDETECT: ${DARTCV_WITH_OBJDETECT}") +message(DEBUG "DARTCV_WITH_PHOTO: ${DARTCV_WITH_PHOTO}") +message(DEBUG "DARTCV_WITH_STITCHING: ${DARTCV_WITH_STITCHING}") +message(DEBUG "DARTCV_WITH_VIDEO: ${DARTCV_WITH_VIDEO}") +message(DEBUG "DARTCV_WITH_VIDEOIO: ${DARTCV_WITH_VIDEOIO}") + +message(STATUS "Enabled modules: ${_enabled_modules}") +message(STATUS "Disabled modules: ${_disabled_modules}") + include(FetchContent) FetchContent_Declare( libdartcv diff --git a/packages/opencv_dart/CHANGELOG.md b/packages/opencv_dart/CHANGELOG.md index 1a2b744d..b205bece 100644 --- a/packages/opencv_dart/CHANGELOG.md +++ b/packages/opencv_dart/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.4.2 + +* support optional modules, configure it in `pubspec.yaml`, from this version, both opencv_core and + opencv_dart can enable/disable optional modules. + ## 1.4.1 * add `VideoCapture.grabAsync` diff --git a/packages/opencv_dart/README.md b/packages/opencv_dart/README.md index 5eb8b90d..d567c11a 100644 --- a/packages/opencv_dart/README.md +++ b/packages/opencv_dart/README.md @@ -12,7 +12,6 @@ use [opencv_core](https://pub.dev/packages/opencv_core) > > - Q&A: [#212](https://github.com/rainyl/opencv_dart/issues/212) or open new issues. > - ~~If you are using flutter with [Native Assets](https://github.com/flutter/flutter/issues/129757) feature supported, consider using v2.x version, see more in [native-assets branch](https://github.com/rainyl/opencv_dart/tree/native-assets)~~ Won't update until `Native Assets` being stable. -> ## Supported platforms @@ -28,6 +27,37 @@ use [opencv_core](https://pub.dev/packages/opencv_core) [Supported modules](https://github.com/rainyl/opencv_dart?tab=readme-ov-file#status) +## Customizing OpenCV Modules + +You can enable or disable specific OpenCV modules for your build by specifying them in your app's `pubspec.yaml` file. + +> [!NOTE] +> +> Currently only Android, Windows, and Linux are supported. + +### Example `pubspec.yaml` configuration + +```yaml +# ...Your existing configuration... +hooks: + user_defines: + dartcv4: + exclude_modules: + - contrib + - dnn + - features2d + - core + include_modules: + - core # core is always required thus will be ignored even configured here. + - imgproc + - videoio +``` + +- valid modules: `core`, `calib3d`, `contrib`, `dnn`, `features2d`, `flann`, `highgui`, `imgproc`, `imgcodecs`, `objdetect`, `photo`, `stitching`, `video`, `videoio` +- Use `exclude_modules` to disable specific modules, or `include_modules` to enable specific modules. +- If neither is specified, all modules except `highgui` will be enabled. +- also refer to [example/pubspec.yaml](https://github.com/rainyl/opencv_dart/blob/main/packages/opencv_dart/example/pubspec.yaml) + ## Package Size ![opencv_dart_size_report](images/opencv_dart_size_report.svg) diff --git a/packages/opencv_dart/android/build.gradle b/packages/opencv_dart/android/build.gradle index 41930cdf..36db0073 100644 --- a/packages/opencv_dart/android/build.gradle +++ b/packages/opencv_dart/android/build.gradle @@ -78,7 +78,7 @@ android { } } - def targetPlatforms = project.getProperty('target-platform').split(',') as List + def targetPlatforms = (project.hasProperty('target-platform') ? project.getProperty('target-platform') : 'android-arm,android-arm64,android-x86,android-x64').split(',') as List if (!targetPlatforms.isEmpty()) { def platformAbiMap = [ 'android-arm64': 'arm64-v8a', diff --git a/packages/opencv_dart/example/.gitignore b/packages/opencv_dart/example/.gitignore index 29a3a501..79c113f9 100644 --- a/packages/opencv_dart/example/.gitignore +++ b/packages/opencv_dart/example/.gitignore @@ -5,9 +5,11 @@ *.swp .DS_Store .atom/ +.build/ .buildlog/ .history .svn/ +.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/packages/opencv_dart/example/android/gradle/wrapper/gradle-wrapper.properties b/packages/opencv_dart/example/android/gradle/wrapper/gradle-wrapper.properties index 7bb2df6b..fde127d7 100644 --- a/packages/opencv_dart/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/packages/opencv_dart/example/android/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Fri May 09 23:15:35 ADT 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip diff --git a/packages/opencv_dart/example/android/settings.gradle b/packages/opencv_dart/example/android/settings.gradle index b9e43bd3..f7392abf 100644 --- a/packages/opencv_dart/example/android/settings.gradle +++ b/packages/opencv_dart/example/android/settings.gradle @@ -18,7 +18,7 @@ pluginManagement { plugins { id "dev.flutter.flutter-plugin-loader" version "1.0.0" - id "com.android.application" version "8.1.0" apply false + id "com.android.application" version '8.10.0' apply false id "org.jetbrains.kotlin.android" version "1.8.22" apply false } diff --git a/packages/opencv_dart/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/opencv_dart/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index af2756a1..2d100bed 100644 --- a/packages/opencv_dart/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/opencv_dart/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -59,6 +59,7 @@ ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" debugServiceExtension = "internal" + enableGPUValidationMode = "1" allowLocationSimulation = "YES"> diff --git a/packages/opencv_dart/example/macos/Runner/AppDelegate.swift b/packages/opencv_dart/example/macos/Runner/AppDelegate.swift index 8e02df28..b3c17614 100644 --- a/packages/opencv_dart/example/macos/Runner/AppDelegate.swift +++ b/packages/opencv_dart/example/macos/Runner/AppDelegate.swift @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } + + override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { + return true + } } diff --git a/packages/opencv_dart/example/pubspec.yaml b/packages/opencv_dart/example/pubspec.yaml index b016fee0..f8c376f6 100644 --- a/packages/opencv_dart/example/pubspec.yaml +++ b/packages/opencv_dart/example/pubspec.yaml @@ -1,99 +1,44 @@ name: opencv_dart_example description: "Demonstrates how to use the opencv_dart plugin." -# The following line prevents the package from being accidentally published to -# pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -# In Windows, build-name is used as the major, minor, and patch parts -# of the product and file versions while build-number is used as the build suffix. version: 1.0.0+1 environment: sdk: ^3.5.3 -# Dependencies specify other packages that your package needs in order to work. -# To automatically upgrade your package dependencies to the latest versions -# consider running `flutter pub upgrade --major-versions`. Alternatively, -# dependencies can be manually updated by changing the version numbers below to -# the latest version available on pub.dev. To see which dependencies have newer -# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter opencv_dart: - # When depending on this package from a real application you should use: - # opencv_dart: ^x.y.z - # See https://dart.dev/tools/pub/dependencies#version-constraints - # The example app is bundled with the plugin so we use a path dependency on - # the parent directory to use the current plugin's version. path: ../ - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 image_picker: ^1.1.2 dev_dependencies: flutter_test: sdk: flutter - - # The "flutter_lints" package below contains a set of recommended lints to - # encourage good coding practices. The lint set provided by the package is - # activated in the `analysis_options.yaml` file located at the root of your - # package. See that file for information about deactivating specific lint - # rules and activating additional ones. flutter_lints: ^4.0.0 -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter packages. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - # To add assets to your application, add an assets section, like this: assets: - images/lenna.png # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/to/resolution-aware-images - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/to/asset-from-package - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/to/font-from-package +hooks: + user_defines: + dartcv4: + exclude_modules: + - contrib + - dnn + - features2d + - core + include_modules: + - core # core is always required thus will be ignored even configured here. + - imgproc + - videoio diff --git a/packages/opencv_dart/pubspec.yaml b/packages/opencv_dart/pubspec.yaml index ac7fba61..598ba9a9 100644 --- a/packages/opencv_dart/pubspec.yaml +++ b/packages/opencv_dart/pubspec.yaml @@ -1,9 +1,7 @@ name: opencv_dart description: | OpenCV4 bindings for Flutter, using dart:ffi. - This plugin include `videoio` module, if you don't need it, - please use `opencv_core` instead. -version: 1.4.1 +version: 1.4.2 opencv_version: 4.11.0+0 dartcv_version: 4.11.0.2 repository: https://github.com/rainyl/opencv_dart @@ -16,7 +14,9 @@ environment: dependencies: flutter: sdk: flutter - dartcv4: 1.1.3 + dartcv4: 1.1.4 + # dartcv4: + # path: ../dartcv dev_dependencies: test: ^1.25.2 diff --git a/packages/opencv_dart/src/CMakeLists.txt b/packages/opencv_dart/src/CMakeLists.txt index caa55480..7890a694 100644 --- a/packages/opencv_dart/src/CMakeLists.txt +++ b/packages/opencv_dart/src/CMakeLists.txt @@ -13,6 +13,79 @@ macro(_find_version _version_var _version_file _regex_find _regex_replace) endif() endmacro() +function(_parse_dartcv_cmake_vars) + # Generate module config from pubspec.yaml using Dart script + # The step should not be mendatary for better user experience + if(WIN32) + find_program(DART_EXECUTABLE dart.bat) + else() + find_program(DART_EXECUTABLE dart) + endif() + + if(NOT DART_EXECUTABLE) + message(WARNING "Dart SDK not found! Will use default modules.") + return() + else() + message(STATUS "Dart SDK found: ${DART_EXECUTABLE}") + endif() + + # Infer working directory + message(STATUS "CMAKE_LIBRARY_OUTPUT_DIRECTORY: ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") + if(ANDROID AND DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY) + get_filename_component(_working_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" DIRECTORY) + elseif(WIN32 OR UNIX) + get_filename_component(_working_dir "${CMAKE_BINARY_DIR}" DIRECTORY) + endif() + + message(STATUS "WORKING_DIR: ${_working_dir}") + + if(NOT DEFINED _working_dir) + message(FATAL_ERROR "Can not infer working directory.") + endif() + + while(NOT EXISTS "${_working_dir}/build" AND NOT "${_working_dir}" STREQUAL "/") + get_filename_component(_working_dir "${_working_dir}" DIRECTORY) + endwhile() + + message(STATUS "Final WORKING_DIR: ${_working_dir}") + + execute_process( + COMMAND ${DART_EXECUTABLE} run dartcv4:gen_cmake_vars + OUTPUT_VARIABLE _output + ERROR_VARIABLE _error + WORKING_DIRECTORY ${_working_dir} + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + message(STATUS "Generate command output:\n${_output}") + + if(_error) + message(FATAL_ERROR "Error while running dartcv4:gen_cmake_vars: ${_error}") + endif(_error) + + string(REGEX MATCH "###DARTCV_GEN_CMAKE_VAR_BEGIN###\n.*###DARTCV_GEN_CMAKE_VAR_END###" _content ${_output}) + + if(_content) + string(REGEX REPLACE "###DARTCV_GEN_CMAKE_VAR_BEGIN###\n" "" _content ${_content}) + string(REGEX REPLACE "###DARTCV_GEN_CMAKE_VAR_END###" "" _content ${_content}) + string(STRIP _content ${_content}) + else() + message(WARNING "No matching DARTCV_GEN_CMAKE_VAR block found.") + return() + endif() + + # Split to lines + string(REGEX REPLACE "\r?\n" ";" _lines "${_content}") + + foreach(_line IN LISTS _lines) + if(_line MATCHES "^([^=]+)=(ON|OFF)$") + set(_var_name "DARTCV_WITH_${CMAKE_MATCH_1}") + set(_var_value "${CMAKE_MATCH_2}") + set(${_var_name} ${_var_value} CACHE BOOL "Enable OpenCV ${CMAKE_MATCH_1} module" FORCE) + endif() + endforeach() +endfunction() + _find_version(_version_project "${PROJ_DIR}/pubspec.yaml" "^version: (.+)*$" "version: (.+)*$") _find_version(_version_opencv "${PROJ_DIR}/pubspec.yaml" "^opencv_version: (.+)*$" "opencv_version: (.+)*$") _find_version(_version_dartcv "${PROJ_DIR}/pubspec.yaml" "^dartcv_version: (.+)*$" "dartcv_version: (.+)*$") @@ -34,23 +107,45 @@ if(ANDROID AND(DEFINED ANDROID_ABI)) endif() endif() -set(DARTCV_WITH_CALIB3D ON CACHE BOOL "Enable OpenCV calib3d module" FORCE) -set(DARTCV_WITH_CONTRIB ON CACHE BOOL "Enable OpenCV contrib module" FORCE) -set(DARTCV_WITH_DNN ON CACHE BOOL "Enable OpenCV dnn module" FORCE) -set(DARTCV_WITH_FEATURE2D ON CACHE BOOL "Enable OpenCV feature2d module" FORCE) -set(DARTCV_WITH_HIGHGUI OFF CACHE BOOL "Enable OpenCV highgui module" FORCE) -set(DARTCV_WITH_IMGPROC ON CACHE BOOL "Enable OpenCV imgproc module" FORCE) -set(DARTCV_WITH_OBJDETECT ON CACHE BOOL "Enable OpenCV objdetect module" FORCE) -set(DARTCV_WITH_PHOTO ON CACHE BOOL "Enable OpenCV photo module" FORCE) -set(DARTCV_WITH_STITCHING ON CACHE BOOL "Enable OpenCV stitching module" FORCE) -set(DARTCV_WITH_VIDEO ON CACHE BOOL "Enable OpenCV video module") -set(DARTCV_WITH_VIDEOIO ON CACHE BOOL "Enable OpenCV videoio module" FORCE) +_parse_dartcv_cmake_vars() + +set(_enabled_modules "core") +set(_disabled_modules) + +# ebabled modules by default +set(_modules CALIB3D CONTRIB DNN FEATURES2D HIGHGUI IMGPROC OBJDETECT PHOTO STITCHING VIDEO VIDEOIO) + +foreach(_m IN LISTS _modules) + string(TOLOWER ${_m} _m_lower) + + if(${DARTCV_WITH_${_m}}) + set(_enabled_modules ${_enabled_modules} ${_m_lower}) + else() + set(_disabled_modules ${_disabled_modules} ${_m_lower}) + endif() +endforeach() + set(DARTCV_WITH_GAPI OFF CACHE BOOL "Enable OpenCV gapi module" FORCE) set(DARTCV_WORLD OFF CACHE BOOL "Enable OpenCV world module" FORCE) set(OPENCV_VERSION "${_version_opencv}") set(DARTCV_DISABLE_DOWNLOAD_OPENCV OFF) +message(DEBUG "DARTCV_WITH_CALIB3D: ${DARTCV_WITH_CALIB3D}") +message(DEBUG "DARTCV_WITH_CONTRIB: ${DARTCV_WITH_CONTRIB}") +message(DEBUG "DARTCV_WITH_DNN: ${DARTCV_WITH_DNN}") +message(DEBUG "DARTCV_WITH_FEATURES2D: ${DARTCV_WITH_FEATURES2D}") +message(DEBUG "DARTCV_WITH_HIGHGUI: ${DARTCV_WITH_HIGHGUI}") +message(DEBUG "DARTCV_WITH_IMGPROC: ${DARTCV_WITH_IMGPROC}") +message(DEBUG "DARTCV_WITH_OBJDETECT: ${DARTCV_WITH_OBJDETECT}") +message(DEBUG "DARTCV_WITH_PHOTO: ${DARTCV_WITH_PHOTO}") +message(DEBUG "DARTCV_WITH_STITCHING: ${DARTCV_WITH_STITCHING}") +message(DEBUG "DARTCV_WITH_VIDEO: ${DARTCV_WITH_VIDEO}") +message(DEBUG "DARTCV_WITH_VIDEOIO: ${DARTCV_WITH_VIDEOIO}") + +message(STATUS "Enabled modules: ${_enabled_modules}") +message(STATUS "Disabled modules: ${_disabled_modules}") + include(FetchContent) FetchContent_Declare( libdartcv diff --git a/packages/opencv_dart/windows/CMakeLists.txt b/packages/opencv_dart/windows/CMakeLists.txt index 7c9e4b0f..74d792de 100644 --- a/packages/opencv_dart/windows/CMakeLists.txt +++ b/packages/opencv_dart/windows/CMakeLists.txt @@ -22,12 +22,6 @@ set(FFMPEG_USE_STATIC_LIBS OFF) # This can be changed to accommodate different builds. add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../src" "${CMAKE_CURRENT_BINARY_DIR}/shared") -if(NOT FFMPEG_LIB_PATHS) - message(FATAL_ERROR "FFMPEG library paths not found!") -else() - message(STATUS "FFMPEG_LIB_PATHS: ${FFMPEG_LIB_PATHS}") -endif() - # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an # external build triggered from this build file.