Skip to content

feat: additional fields in gaussianBlur, getStructuringElement and mo… #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 52 additions & 11 deletions cpp/FOCV_Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,10 +1058,21 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
auto dst = args.asMatPtr(2);
auto ksize = args.asSizePtr(3);
auto sigmaX = args.asNumber(4);
auto sigmaY = args.asNumber(5);
auto borderType = args.asNumber(6);

cv::GaussianBlur(*src, *dst, *ksize, sigmaX, sigmaY, borderType);
if(args.isNumber(5)) {
auto sigmaY = args.asNumber(5);

if(args.isNumber(6)) {
auto borderType = args.asNumber(6);
cv::GaussianBlur(*src, *dst, *ksize, sigmaX, sigmaY, borderType);
break;
}

cv::GaussianBlur(*src, *dst, *ksize, sigmaX, sigmaY);
break;
}

cv::GaussianBlur(*src, *dst, *ksize, sigmaX);
} break;
case hashString("getGaborKernel", 14): {
auto ksize = args.asSizePtr(1);
Expand Down Expand Up @@ -1098,12 +1109,19 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
return FOCV_JsiObject::wrap(runtime, "mat", id);
} break;
case hashString("getStructuringElement", 21): {
std::string id;

auto shape = args.asNumber(1);
auto ksize = args.asSizePtr(2);
auto anchor = args.asPointPtr(3);

cv::Mat result = cv::getStructuringElement(shape, *ksize, *anchor);
std::string id = FOCV_Storage::save(result);
if (args.isPoint(3)) {
auto anchor = args.asPointPtr(3);
cv::Mat result = cv::getStructuringElement(shape, *ksize, *anchor);
id = FOCV_Storage::save(result);
} else {
cv::Mat result = cv::getStructuringElement(shape, *ksize);
id = FOCV_Storage::save(result);
}

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

cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations, borderType, *borderValue);
if(args.isPoint(5)) {
auto anchor = args.asPointPtr(5);

if(args.isNumber(6)) {
auto iterations = args.asNumber(6);

if(args.isNumber(7)) {
auto borderType = args.asNumber(7);

if(args.isScalar(8)) {
auto borderValue = args.asScalarPtr(8);
cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations, borderType, *borderValue);
break;
}

cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations, borderType);
break;
}

cv::morphologyEx(*src, *dst, op, *kernel, *anchor, iterations);
break;
}

cv::morphologyEx(*src, *dst, op, *kernel, *anchor);
break;
}

cv::morphologyEx(*src, *dst, op, *kernel);
} break;
case hashString("adaptiveThreshold", 17): {
auto src = args.asMatPtr(1);
Expand Down
10 changes: 10 additions & 0 deletions cpp/FOCV_FunctionArguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,13 @@ bool FOCV_FunctionArguments::isMat(int index) {
bool FOCV_FunctionArguments::isMatVector(int index) {
return FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "mat_vector";
}

bool FOCV_FunctionArguments::isPoint(int index) {
return FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "point";
}

bool FOCV_FunctionArguments::isScalar(int index) {
return FOCV_JsiObject::type_from_wrap(*this->runtime, arguments[index]) == "scalar";
}


2 changes: 2 additions & 0 deletions cpp/FOCV_FunctionArguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class FOCV_FunctionArguments {
bool isObject(int index);
bool isMat(int index);
bool isMatVector(int index);
bool isPoint(int index);
bool isScalar(int index);
};

#endif /* FOCV_FunctionArguments_hpp */
60 changes: 48 additions & 12 deletions docs/pages/availablefunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -1758,14 +1758,28 @@ Blurs an image using a Gaussian filter.

```js
invoke(
name: 'GaussianBlur',
src: Mat,
dst: Mat,
ksize: Size,
sigmaX: number,
sigmaY: number,
borderType: BorderTypes
): void;
name: 'GaussianBlur',
src: Mat,
dst: Mat,
ksize: Size,
sigmaX: number
): void;
invoke(
name: 'GaussianBlur',
src: Mat,
dst: Mat,
ksize: Size,
sigmaX: number
): void;
invoke(
name: 'GaussianBlur',
src: Mat,
dst: Mat,
ksize: Size,
sigmaX: number,
sigmaY: number,
borderType: BorderTypes
): void;
```

### getGaborKernel
Expand Down Expand Up @@ -1831,11 +1845,12 @@ Returns a structuring element of the specified size and shape for morphological
- 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..

```js
invoke(name: 'getStructuringElement', shape: MorphShapes, ksize: Size): Mat;
invoke(
name: 'getGaussianKernel',
shape: MorphShapes,
ksize: Size,
anchor: Point
name: 'getStructuringElement',
shape: MorphShapes,
ksize: Size,
anchor: Point
): Mat;
```

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

```js
invoke( name: 'morphologyEx', src: Mat, dst: Mat, op: MorphTypes, kernel: Mat): void;
invoke( name: 'morphologyEx', src: Mat, dst: Mat, op: MorphTypes, kernel: Mat, anchor: Point): void;
invoke(
name: 'morphologyEx',
src: Mat,
dst: Mat,
op: MorphTypes,
kernel: Mat,
anchor: Point,
iterations: number
): void;
invoke(
name: 'morphologyEx',
src: Mat,
dst: Mat,
op: MorphTypes,
kernel: Mat,
anchor: Point,
iterations: number,
borderType: BorderTypes
): void;
invoke(
name: 'morphologyEx',
src: Mat,
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ PODS:
- React-Mapbuffer (0.74.4):
- glog
- React-debug
- react-native-fast-opencv (0.2.4):
- react-native-fast-opencv (0.2.7):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1594,7 +1594,7 @@ SPEC CHECKSUMS:
React-jsitracing: 4e9c99e73a6269b27b0d4cbab277dd90df3e5ac0
React-logger: fbfb50e2a2b1b46ee087f0a52739fadecc5e81a4
React-Mapbuffer: d39610dff659d8cf1fea485abae08bbf6f9c8279
react-native-fast-opencv: 52cb988f5dee40a599381c4617b8560977ed983c
react-native-fast-opencv: 8e853bb378f92221c4b47fe98fc9283aedcf95fb
react-native-image-picker: c3afe5472ef870d98a4b28415fc0b928161ee5f7
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
react-native-skia: 8da84ea9410504bf27f0db229539a43f6caabb6a
Expand Down
49 changes: 49 additions & 0 deletions src/functions/ImageProcessing/ImageFiltering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ export type ImageFiltering = {
* @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.
* @param borderType pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.
*/
invoke(
name: 'GaussianBlur',
src: Mat,
dst: Mat,
ksize: Size,
sigmaX: number
): void;
invoke(
name: 'GaussianBlur',
src: Mat,
dst: Mat,
ksize: Size,
sigmaX: number
): void;
invoke(
name: 'GaussianBlur',
src: Mat,
Expand Down Expand Up @@ -198,6 +212,7 @@ export type ImageFiltering = {
* @param ksize Size of the structuring element.
* @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.
*/
invoke(name: 'getStructuringElement', shape: MorphShapes, ksize: Size): Mat;
invoke(
name: 'getStructuringElement',
shape: MorphShapes,
Expand Down Expand Up @@ -256,6 +271,40 @@ export type ImageFiltering = {
* @param borderType Pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.
* @param borderValue Border value in case of a constant border. The default value has a special meaning.
*/
invoke(
name: 'morphologyEx',
src: Mat,
dst: Mat,
op: MorphTypes,
kernel: Mat
): void;
invoke(
name: 'morphologyEx',
src: Mat,
dst: Mat,
op: MorphTypes,
kernel: Mat,
anchor: Point
): void;
invoke(
name: 'morphologyEx',
src: Mat,
dst: Mat,
op: MorphTypes,
kernel: Mat,
anchor: Point,
iterations: number
): void;
invoke(
name: 'morphologyEx',
src: Mat,
dst: Mat,
op: MorphTypes,
kernel: Mat,
anchor: Point,
iterations: number,
borderType: BorderTypes
): void;
invoke(
name: 'morphologyEx',
src: Mat,
Expand Down
Loading