Skip to content

Commit 3377fb9

Browse files
Enhance README and CMakeLists for OpenCV module customization (#355)
* Enhance README and CMakeLists for OpenCV module customization - Added documentation on customizing OpenCV modules via `opencv_config.cmake` in both `opencv_core` and `opencv_dart` READMEs. - Updated `CMakeLists.txt` in both packages to include user-defined configurations if `opencv_config.cmake` exists, falling back to default settings otherwise. * Refactor OpenCV module customization to use pubspec.yaml - Updated README files for both `opencv_core` and `opencv_dart` to reflect the new method of customizing OpenCV modules via the `pubspec.yaml` file instead of `opencv_config.cmake`. - Introduced a Dart script to generate `dartcv_modules.cmake` based on the specified modules in `pubspec.yaml`. - Modified `CMakeLists.txt` in both packages to include the generated `dartcv_modules.cmake`, ensuring proper module configuration during the build process. * added default fallback incase target-platform is not set, and upgraded gradle versions * Update Android Gradle plugin and Gradle wrapper versions - Upgraded Android Gradle plugin from version 8.1.0 to 8.10.0. - Updated Gradle wrapper distribution from version 8.5 to 8.11.1. * add gen_cmake_vars.dart for dartcv4, make CMakeLists.txt run the script to get module configurations * dart format ✅ * fix cmakelists.txt * fix windows * dart format ✅ * fix linux * bump dartcv4 to 1.1.4, fix android * update readme and changelog --------- Co-authored-by: rainyl <[email protected]> Co-authored-by: rainyl <[email protected]>
1 parent 033b500 commit 3377fb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1042
-899
lines changed

packages/dartcv/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* add `MatType.elemSize` `MatType.elemSize1`
55
* remove deprecated `(double x, double y, double z).asPoint3f`
66
`(double x, double y).asPoint2f` `(int x, int y).asPoint` `VecPoint.toVecVecPoint`
7+
* add `bin/gen_cmake_vars.dart` for generating optional module vars for CMake
78

89
## 1.1.3
910

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// ignore_for_file: avoid_dynamic_calls, avoid_print
2+
3+
import 'dart:io';
4+
5+
import 'package:yaml/yaml.dart';
6+
7+
const defaultModuleSettings = {
8+
// "core": "ON", // not configurable
9+
"calib3d": "ON",
10+
"contrib": "ON",
11+
"dnn": "ON",
12+
"features2d": "ON",
13+
"flann": "ON",
14+
// "gapi", // disabled
15+
"highgui": "OFF",
16+
"imgproc": "ON",
17+
"imgcodecs": "ON",
18+
"objdetect": "ON",
19+
"photo": "ON",
20+
"stitching": "ON",
21+
"video": "ON",
22+
"videoio": "ON",
23+
};
24+
25+
void main(List<String> args) {
26+
final pubspecPath = Platform.script.resolve("../../../../pubspec.yaml");
27+
final excludeModules = parseUserDefinedExcludeModules(pubspecPath.toFilePath());
28+
29+
final cmakeVars = StringBuffer("###DARTCV_GEN_CMAKE_VAR_BEGIN###\n");
30+
for (final k in excludeModules.entries) {
31+
cmakeVars.write("${k.key.toUpperCase()}=${k.value.toUpperCase()}\n");
32+
}
33+
cmakeVars.write("###DARTCV_GEN_CMAKE_VAR_END###");
34+
print(cmakeVars);
35+
}
36+
37+
/// Parse the user defined exclude modules from pubspec.yaml
38+
///
39+
/// Returns a list of excluded module names
40+
Map<String, String> parseUserDefinedExcludeModules(String pubspecPath, {bool excludeMode = true}) {
41+
try {
42+
print("Generating cmake vars from $pubspecPath");
43+
// Read the pubspec.yaml file
44+
final File file = File(pubspecPath);
45+
if (!file.existsSync()) {
46+
print("$pubspecPath not found");
47+
return defaultModuleSettings;
48+
}
49+
50+
// Parse the YAML content
51+
final String yamlContent = file.readAsStringSync();
52+
final dynamic yamlMap = loadYaml(yamlContent);
53+
54+
// Navigate to the hooks.user_defines.dartcv4.exclude_modules section
55+
if (yamlMap is YamlMap &&
56+
yamlMap['hooks'] is YamlMap &&
57+
yamlMap['hooks']['user_defines'] is YamlMap &&
58+
yamlMap['hooks']['user_defines']['dartcv4'] is YamlMap) {
59+
final dartcvDefines = yamlMap['hooks']['user_defines']['dartcv4'] as YamlMap;
60+
61+
final excludeModules = dartcvDefines['exclude_modules'] as YamlList? ?? YamlList();
62+
// include is priority over exclude
63+
final includeModules = dartcvDefines['include_modules'] as YamlList? ?? YamlList();
64+
65+
final include = includeModules
66+
.map((dynamic module) => module.toString().toLowerCase())
67+
.where((e) => defaultModuleSettings.containsKey(e))
68+
.toList();
69+
final exclude = excludeModules
70+
.map((dynamic module) => module.toString().toLowerCase())
71+
.where((e) => defaultModuleSettings.containsKey(e) && !include.contains(e))
72+
.toList();
73+
74+
final result = {
75+
for (final e in defaultModuleSettings.keys)
76+
e: exclude.contains(e) ? "OFF" : defaultModuleSettings[e]!,
77+
};
78+
79+
return result;
80+
}
81+
82+
print("parse error");
83+
return defaultModuleSettings;
84+
} catch (e) {
85+
// Return empty list in case of any error
86+
print('Error parsing exclude_modules: $e');
87+
return defaultModuleSettings;
88+
}
89+
}

packages/dartcv/lib/src/calib3d/fisheye.dart

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -107,25 +107,24 @@ class Fisheye {
107107
distorted ??= Mat.empty();
108108

109109
cvRun(
110-
() =>
111-
Kundistorted == null
112-
? ccalib3d.cv_fisheye_distortPoints(
113-
undistorted.ref,
114-
distorted!.ref,
115-
K.ref,
116-
D.ref,
117-
alpha,
118-
ffi.nullptr,
119-
)
120-
: ccalib3d.cv_fisheye_distortPoints_1(
121-
undistorted.ref,
122-
distorted!.ref,
123-
Kundistorted.ref,
124-
K.ref,
125-
D.ref,
126-
alpha,
127-
ffi.nullptr,
128-
),
110+
() => Kundistorted == null
111+
? ccalib3d.cv_fisheye_distortPoints(
112+
undistorted.ref,
113+
distorted!.ref,
114+
K.ref,
115+
D.ref,
116+
alpha,
117+
ffi.nullptr,
118+
)
119+
: ccalib3d.cv_fisheye_distortPoints_1(
120+
undistorted.ref,
121+
distorted!.ref,
122+
Kundistorted.ref,
123+
K.ref,
124+
D.ref,
125+
alpha,
126+
ffi.nullptr,
127+
),
129128
);
130129
return distorted;
131130
}
@@ -142,25 +141,17 @@ class Fisheye {
142141
distorted ??= Mat.empty();
143142

144143
return cvRunAsync0(
145-
(callback) =>
146-
Kundistorted == null
147-
? ccalib3d.cv_fisheye_distortPoints(
148-
undistorted.ref,
149-
distorted!.ref,
150-
K.ref,
151-
D.ref,
152-
alpha,
153-
callback,
154-
)
155-
: ccalib3d.cv_fisheye_distortPoints_1(
156-
undistorted.ref,
157-
distorted!.ref,
158-
Kundistorted.ref,
159-
K.ref,
160-
D.ref,
161-
alpha,
162-
callback,
163-
),
144+
(callback) => Kundistorted == null
145+
? ccalib3d.cv_fisheye_distortPoints(undistorted.ref, distorted!.ref, K.ref, D.ref, alpha, callback)
146+
: ccalib3d.cv_fisheye_distortPoints_1(
147+
undistorted.ref,
148+
distorted!.ref,
149+
Kundistorted.ref,
150+
K.ref,
151+
D.ref,
152+
alpha,
153+
callback,
154+
),
164155
(c) => c.complete(distorted),
165156
);
166157
}

packages/dartcv/lib/src/calib3d/usac_params.dart

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@ class UsacParams extends CvStruct<cvg.UsacParams> {
2626
int finalPolisher = NONE_POLISHER,
2727
int finalPolisherIterations = 0,
2828
}) {
29-
final p =
30-
calloc<cvg.UsacParams>()
31-
..ref.confidence = confidence
32-
..ref.isParallel = isParallel
33-
..ref.loIterations = loIterations
34-
..ref.loMethod = loMethod
35-
..ref.loSampleSize = loSampleSize
36-
..ref.maxIterations = maxIterations
37-
..ref.neighborsSearch = neighborsSearch
38-
..ref.randomGeneratorState = randomGeneratorState
39-
..ref.sampler = sampler
40-
..ref.score = score
41-
..ref.threshold = threshold
42-
..ref.final_polisher = finalPolisher
43-
..ref.final_polisher_iterations = finalPolisherIterations;
29+
final p = calloc<cvg.UsacParams>()
30+
..ref.confidence = confidence
31+
..ref.isParallel = isParallel
32+
..ref.loIterations = loIterations
33+
..ref.loMethod = loMethod
34+
..ref.loSampleSize = loSampleSize
35+
..ref.maxIterations = maxIterations
36+
..ref.neighborsSearch = neighborsSearch
37+
..ref.randomGeneratorState = randomGeneratorState
38+
..ref.sampler = sampler
39+
..ref.score = score
40+
..ref.threshold = threshold
41+
..ref.final_polisher = finalPolisher
42+
..ref.final_polisher_iterations = finalPolisherIterations;
4443
return UsacParams.fromPointer(p);
4544
}
4645

packages/dartcv/lib/src/contrib/ximgproc.dart

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -590,21 +590,20 @@ class EdgeDrawingParams extends CvStruct<cvg.EdgeDrawingParams> {
590590
double Sigma = 1.0,
591591
bool SumFlag = true,
592592
}) {
593-
final p =
594-
calloc<cvg.EdgeDrawingParams>()
595-
..ref.AnchorThresholdValue = AnchorThresholdValue
596-
..ref.EdgeDetectionOperator = EdgeDetectionOperator
597-
..ref.GradientThresholdValue = GradientThresholdValue
598-
..ref.LineFitErrorThreshold = LineFitErrorThreshold
599-
..ref.MaxDistanceBetweenTwoLines = MaxDistanceBetweenTwoLines
600-
..ref.MaxErrorThreshold = MaxErrorThreshold
601-
..ref.MinLineLength = MinLineLength
602-
..ref.MinPathLength = MinPathLength
603-
..ref.NFAValidation = NFAValidation
604-
..ref.PFmode = PFmode
605-
..ref.ScanInterval = ScanInterval
606-
..ref.Sigma = Sigma
607-
..ref.SumFlag = SumFlag;
593+
final p = calloc<cvg.EdgeDrawingParams>()
594+
..ref.AnchorThresholdValue = AnchorThresholdValue
595+
..ref.EdgeDetectionOperator = EdgeDetectionOperator
596+
..ref.GradientThresholdValue = GradientThresholdValue
597+
..ref.LineFitErrorThreshold = LineFitErrorThreshold
598+
..ref.MaxDistanceBetweenTwoLines = MaxDistanceBetweenTwoLines
599+
..ref.MaxErrorThreshold = MaxErrorThreshold
600+
..ref.MinLineLength = MinLineLength
601+
..ref.MinPathLength = MinPathLength
602+
..ref.NFAValidation = NFAValidation
603+
..ref.PFmode = PFmode
604+
..ref.ScanInterval = ScanInterval
605+
..ref.Sigma = Sigma
606+
..ref.SumFlag = SumFlag;
608607
return EdgeDrawingParams.fromPointer(p);
609608
}
610609

packages/dartcv/lib/src/core/core_async.dart

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ Future<Mat> bitwiseANDAsync(InputArray src1, InputArray src2, {OutputArray? dst,
8181
dst ??= Mat.empty();
8282
return mask == null
8383
? cvRunAsync0((callback) => ccore.cv_bitwise_and(src1.ref, src2.ref, dst!.ref, callback), (c) {
84-
return c.complete(dst);
85-
})
84+
return c.complete(dst);
85+
})
8686
: cvRunAsync0((callback) => ccore.cv_bitwise_and_1(src1.ref, src2.ref, dst!.ref, mask.ref, callback), (
87-
c,
88-
) {
89-
return c.complete(dst);
90-
});
87+
c,
88+
) {
89+
return c.complete(dst);
90+
});
9191
}
9292

9393
/// BitwiseNot inverts every bit of an array.
@@ -98,11 +98,11 @@ Future<Mat> bitwiseNOTAsync(InputArray src, {OutputArray? dst, InputArray? mask}
9898
dst ??= Mat.empty();
9999
return mask == null
100100
? cvRunAsync0((callback) => ccore.cv_bitwise_not(src.ref, dst!.ref, callback), (c) {
101-
return c.complete(dst);
102-
})
101+
return c.complete(dst);
102+
})
103103
: cvRunAsync0((callback) => ccore.cv_bitwise_not_1(src.ref, dst!.ref, mask.ref, callback), (c) {
104-
return c.complete(dst);
105-
});
104+
return c.complete(dst);
105+
});
106106
}
107107

108108
/// BitwiseOr calculates the per-element bit-wise disjunction of two arrays
@@ -114,13 +114,13 @@ Future<Mat> bitwiseORAsync(InputArray src1, InputArray src2, {OutputArray? dst,
114114
dst ??= Mat.empty();
115115
return mask == null
116116
? cvRunAsync0((callback) => ccore.cv_bitwise_or(src1.ref, src2.ref, dst!.ref, callback), (c) {
117-
return c.complete(dst);
118-
})
117+
return c.complete(dst);
118+
})
119119
: cvRunAsync0((callback) => ccore.cv_bitwise_or_1(src1.ref, src2.ref, dst!.ref, mask.ref, callback), (
120-
c,
121-
) {
122-
return c.complete(dst);
123-
});
120+
c,
121+
) {
122+
return c.complete(dst);
123+
});
124124
}
125125

126126
/// BitwiseXor calculates the per-element bit-wise "exclusive or" operation
@@ -132,13 +132,13 @@ Future<Mat> bitwiseXORAsync(InputArray src1, InputArray src2, {OutputArray? dst,
132132
dst ??= Mat.empty();
133133
return mask == null
134134
? cvRunAsync0((callback) => ccore.cv_bitwise_xor(src1.ref, src2.ref, dst!.ref, callback), (c) {
135-
return c.complete(dst);
136-
})
135+
return c.complete(dst);
136+
})
137137
: cvRunAsync0((callback) => ccore.cv_bitwise_xor_1(src1.ref, src2.ref, dst!.ref, mask.ref, callback), (
138-
c,
139-
) {
140-
return c.complete(dst);
141-
});
138+
c,
139+
) {
140+
return c.complete(dst);
141+
});
142142
}
143143

144144
/// BatchDistance is a naive nearest neighbor finder.
@@ -856,11 +856,11 @@ Future<(Scalar mean, Scalar stddev)> meanStdDevAsync(InputArray src, {InputArray
856856
final stddev = calloc<cvg.Scalar>();
857857
return mask == null
858858
? cvRunAsync0((callback) => ccore.cv_meanStdDev(src.ref, mean, stddev, callback), (c) {
859-
return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev)));
860-
})
859+
return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev)));
860+
})
861861
: cvRunAsync0((callback) => ccore.cv_meanStdDev_1(src.ref, mean, stddev, mask.ref, callback), (c) {
862-
return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev)));
863-
});
862+
return c.complete((Scalar.fromPointer(mean), Scalar.fromPointer(stddev)));
863+
});
864864
}
865865

866866
/// Merge creates one multi-channel array out of several single-channel ones.

0 commit comments

Comments
 (0)