Skip to content

Commit 6a9b633

Browse files
Merge pull request #20 from lukaszkurantdev/feat/optional-parameters
feat: additional fields in gaussianBlur, getStructuringElement and mo…
2 parents e71b738 + 278c7cf commit 6a9b633

File tree

6 files changed

+163
-25
lines changed

6 files changed

+163
-25
lines changed

cpp/FOCV_Function.cpp

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,10 +1058,21 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
10581058
auto dst = args.asMatPtr(2);
10591059
auto ksize = args.asSizePtr(3);
10601060
auto sigmaX = args.asNumber(4);
1061-
auto sigmaY = args.asNumber(5);
1062-
auto borderType = args.asNumber(6);
10631061

1064-
cv::GaussianBlur(*src, *dst, *ksize, sigmaX, sigmaY, borderType);
1062+
if(args.isNumber(5)) {
1063+
auto sigmaY = args.asNumber(5);
1064+
1065+
if(args.isNumber(6)) {
1066+
auto borderType = args.asNumber(6);
1067+
cv::GaussianBlur(*src, *dst, *ksize, sigmaX, sigmaY, borderType);
1068+
break;
1069+
}
1070+
1071+
cv::GaussianBlur(*src, *dst, *ksize, sigmaX, sigmaY);
1072+
break;
1073+
}
1074+
1075+
cv::GaussianBlur(*src, *dst, *ksize, sigmaX);
10651076
} break;
10661077
case hashString("getGaborKernel", 14): {
10671078
auto ksize = args.asSizePtr(1);
@@ -1098,12 +1109,19 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
10981109
return FOCV_JsiObject::wrap(runtime, "mat", id);
10991110
} break;
11001111
case hashString("getStructuringElement", 21): {
1112+
std::string id;
1113+
11011114
auto shape = args.asNumber(1);
11021115
auto ksize = args.asSizePtr(2);
1103-
auto anchor = args.asPointPtr(3);
11041116

1105-
cv::Mat result = cv::getStructuringElement(shape, *ksize, *anchor);
1106-
std::string id = FOCV_Storage::save(result);
1117+
if (args.isPoint(3)) {
1118+
auto anchor = args.asPointPtr(3);
1119+
cv::Mat result = cv::getStructuringElement(shape, *ksize, *anchor);
1120+
id = FOCV_Storage::save(result);
1121+
} else {
1122+
cv::Mat result = cv::getStructuringElement(shape, *ksize);
1123+
id = FOCV_Storage::save(result);
1124+
}
11071125

11081126
return FOCV_JsiObject::wrap(runtime, "mat", id);
11091127
} break;
@@ -1136,12 +1154,35 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
11361154
auto dst = args.asMatPtr(2);
11371155
auto op = args.asNumber(3);
11381156
auto kernel = args.asMatPtr(4);
1139-
auto anchor = args.asPointPtr(5);
1140-
auto iterations = args.asNumber(6);
1141-
auto borderType = args.asNumber(7);
1142-
auto borderValue = args.asScalarPtr(8);
11431157

1144-
cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations, borderType, *borderValue);
1158+
if(args.isPoint(5)) {
1159+
auto anchor = args.asPointPtr(5);
1160+
1161+
if(args.isNumber(6)) {
1162+
auto iterations = args.asNumber(6);
1163+
1164+
if(args.isNumber(7)) {
1165+
auto borderType = args.asNumber(7);
1166+
1167+
if(args.isScalar(8)) {
1168+
auto borderValue = args.asScalarPtr(8);
1169+
cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations, borderType, *borderValue);
1170+
break;
1171+
}
1172+
1173+
cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations, borderType);
1174+
break;
1175+
}
1176+
1177+
cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations);
1178+
break;
1179+
}
1180+
1181+
cv::morphologyEx(*src, *dst, op, *kernel, *anchor);
1182+
break;
1183+
}
1184+
1185+
cv::morphologyEx(*src, *dst, op, *kernel);
11451186
} break;
11461187
case hashString("adaptiveThreshold", 17): {
11471188
auto src = args.asMatPtr(1);

cpp/FOCV_FunctionArguments.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,13 @@ bool FOCV_FunctionArguments::isMat(int index) {
9494
bool FOCV_FunctionArguments::isMatVector(int index) {
9595
return FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "mat_vector";
9696
}
97+
98+
bool FOCV_FunctionArguments::isPoint(int index) {
99+
return FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point";
100+
}
101+
102+
bool FOCV_FunctionArguments::isScalar(int index) {
103+
return FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "scalar";
104+
}
105+
106+

cpp/FOCV_FunctionArguments.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class FOCV_FunctionArguments {
5757
bool isObject(int index);
5858
bool isMat(int index);
5959
bool isMatVector(int index);
60+
bool isPoint(int index);
61+
bool isScalar(int index);
6062
};
6163

6264
#endif /* FOCV_FunctionArguments_hpp */

docs/pages/availablefunctions.md

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,14 +1758,28 @@ Blurs an image using a Gaussian filter.
17581758

17591759
```js
17601760
invoke(
1761-
name: 'GaussianBlur',
1762-
src: Mat,
1763-
dst: Mat,
1764-
ksize: Size,
1765-
sigmaX: number,
1766-
sigmaY: number,
1767-
borderType: BorderTypes
1768-
): void;
1761+
name: 'GaussianBlur',
1762+
src: Mat,
1763+
dst: Mat,
1764+
ksize: Size,
1765+
sigmaX: number
1766+
): void;
1767+
invoke(
1768+
name: 'GaussianBlur',
1769+
src: Mat,
1770+
dst: Mat,
1771+
ksize: Size,
1772+
sigmaX: number
1773+
): void;
1774+
invoke(
1775+
name: 'GaussianBlur',
1776+
src: Mat,
1777+
dst: Mat,
1778+
ksize: Size,
1779+
sigmaX: number,
1780+
sigmaY: number,
1781+
borderType: BorderTypes
1782+
): void;
17691783
```
17701784

17711785
### getGaborKernel
@@ -1831,11 +1845,12 @@ Returns a structuring element of the specified size and shape for morphological
18311845
- anchor Anchor position within the element. The default value means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted..
18321846

18331847
```js
1848+
invoke(name: 'getStructuringElement', shape: MorphShapes, ksize: Size): Mat;
18341849
invoke(
1835-
name: 'getGaussianKernel',
1836-
shape: MorphShapes,
1837-
ksize: Size,
1838-
anchor: Point
1850+
name: 'getStructuringElement',
1851+
shape: MorphShapes,
1852+
ksize: Size,
1853+
anchor: Point
18391854
): Mat;
18401855
```
18411856

@@ -1898,6 +1913,27 @@ Any of the operations can be done in-place. In case of multi-channel images, eac
18981913
- borderValue Border value in case of a constant border. The default value has a special meaning.
18991914

19001915
```js
1916+
invoke( name: 'morphologyEx', src: Mat, dst: Mat, op: MorphTypes, kernel: Mat): void;
1917+
invoke( name: 'morphologyEx', src: Mat, dst: Mat, op: MorphTypes, kernel: Mat, anchor: Point): void;
1918+
invoke(
1919+
name: 'morphologyEx',
1920+
src: Mat,
1921+
dst: Mat,
1922+
op: MorphTypes,
1923+
kernel: Mat,
1924+
anchor: Point,
1925+
iterations: number
1926+
): void;
1927+
invoke(
1928+
name: 'morphologyEx',
1929+
src: Mat,
1930+
dst: Mat,
1931+
op: MorphTypes,
1932+
kernel: Mat,
1933+
anchor: Point,
1934+
iterations: number,
1935+
borderType: BorderTypes
1936+
): void;
19011937
invoke(
19021938
name: 'morphologyEx',
19031939
src: Mat,

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ PODS:
936936
- React-Mapbuffer (0.74.4):
937937
- glog
938938
- React-debug
939-
- react-native-fast-opencv (0.2.4):
939+
- react-native-fast-opencv (0.2.7):
940940
- DoubleConversion
941941
- glog
942942
- hermes-engine
@@ -1594,7 +1594,7 @@ SPEC CHECKSUMS:
15941594
React-jsitracing: 4e9c99e73a6269b27b0d4cbab277dd90df3e5ac0
15951595
React-logger: fbfb50e2a2b1b46ee087f0a52739fadecc5e81a4
15961596
React-Mapbuffer: d39610dff659d8cf1fea485abae08bbf6f9c8279
1597-
react-native-fast-opencv: 52cb988f5dee40a599381c4617b8560977ed983c
1597+
react-native-fast-opencv: 8e853bb378f92221c4b47fe98fc9283aedcf95fb
15981598
react-native-image-picker: c3afe5472ef870d98a4b28415fc0b928161ee5f7
15991599
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
16001600
react-native-skia: 8da84ea9410504bf27f0db229539a43f6caabb6a

src/functions/ImageProcessing/ImageFiltering.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,20 @@ export type ImageFiltering = {
148148
* @param sigmaY Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width and ksize.height, respectively (see getGaussianKernel for details); to fully control the result regardless of possible future modifications of all this semantics, it is recommended to specify all of ksize, sigmaX, and sigmaY.
149149
* @param borderType pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.
150150
*/
151+
invoke(
152+
name: 'GaussianBlur',
153+
src: Mat,
154+
dst: Mat,
155+
ksize: Size,
156+
sigmaX: number
157+
): void;
158+
invoke(
159+
name: 'GaussianBlur',
160+
src: Mat,
161+
dst: Mat,
162+
ksize: Size,
163+
sigmaX: number
164+
): void;
151165
invoke(
152166
name: 'GaussianBlur',
153167
src: Mat,
@@ -198,6 +212,7 @@ export type ImageFiltering = {
198212
* @param ksize Size of the structuring element.
199213
* @param anchor Anchor position within the element. The default value means that the anchor is at the center. Note that only the shape of a cross-shaped element depends on the anchor position. In other cases the anchor just regulates how much the result of the morphological operation is shifted.
200214
*/
215+
invoke(name: 'getStructuringElement', shape: MorphShapes, ksize: Size): Mat;
201216
invoke(
202217
name: 'getStructuringElement',
203218
shape: MorphShapes,
@@ -256,6 +271,40 @@ export type ImageFiltering = {
256271
* @param borderType Pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.
257272
* @param borderValue Border value in case of a constant border. The default value has a special meaning.
258273
*/
274+
invoke(
275+
name: 'morphologyEx',
276+
src: Mat,
277+
dst: Mat,
278+
op: MorphTypes,
279+
kernel: Mat
280+
): void;
281+
invoke(
282+
name: 'morphologyEx',
283+
src: Mat,
284+
dst: Mat,
285+
op: MorphTypes,
286+
kernel: Mat,
287+
anchor: Point
288+
): void;
289+
invoke(
290+
name: 'morphologyEx',
291+
src: Mat,
292+
dst: Mat,
293+
op: MorphTypes,
294+
kernel: Mat,
295+
anchor: Point,
296+
iterations: number
297+
): void;
298+
invoke(
299+
name: 'morphologyEx',
300+
src: Mat,
301+
dst: Mat,
302+
op: MorphTypes,
303+
kernel: Mat,
304+
anchor: Point,
305+
iterations: number,
306+
borderType: BorderTypes
307+
): void;
259308
invoke(
260309
name: 'morphologyEx',
261310
src: Mat,

0 commit comments

Comments
 (0)