Skip to content

Feat/minor changes #78

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 4 commits into from
Mar 26, 2025
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
41 changes: 39 additions & 2 deletions cpp/FOCV_Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,16 +513,22 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
double min = 0;
double max = 0;

Point minLoc; Point maxLoc;

if (count > 2) {
auto mask = args.asMatPtr(2);

cv::minMaxIdx(*src, &min, &max, NULL, NULL, *mask);
cv::minMaxLoc(*src, &min, &max, &minLoc, &maxLoc, *mask);
} else {
cv::minMaxIdx(*src, &min, &max);
cv::minMaxLoc(*src, &min, &max, &minLoc, &maxLoc);
}

value.setProperty(runtime, "minVal", jsi::Value(min));
value.setProperty(runtime, "maxVal", jsi::Value(max));
value.setProperty(runtime, "minX", minLoc.x);
value.setProperty(runtime, "minY", minLoc.y);
value.setProperty(runtime, "maxX", maxLoc.x);
value.setProperty(runtime, "maxY", maxLoc.y);
} break;
case hashString("mulSpectrums", 12): {
auto a = args.asMatPtr(1);
Expand Down Expand Up @@ -590,6 +596,12 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum

cv::normalize(*src, *dst, alpha, normType);
} break;
case hashString("merge", 5): {
auto src = args.asMatVectorPtr(1);
auto dst = args.asMatPtr(2);

cv::merge(*src, *dst);
} break;
case hashString("patchNaNs", 9): {
auto alpha = args.asNumber(2);

Expand Down Expand Up @@ -654,6 +666,16 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum

cv::repeat(*src, ny, nx, *dst);
} break;
case hashString("resize", 6): {
auto src = args.asMatPtr(1);
auto dst = args.asMatPtr(2);
auto dsize = args.asSizePtr(3);
auto fx = args.asNumber(4);
auto fy = args.asNumber(5);
auto interpolation = args.asNumber(6);

cv::resize(*src, *dst, *dsize, fx, fy, interpolation);
} break;
case hashString("rotate", 6): {
auto src = args.asMatPtr(1);
auto dst = args.asMatPtr(2);
Expand Down Expand Up @@ -1386,6 +1408,21 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
cv::findContours(*src, *dst, mode, method);
}
} break;
case hashString("findContoursWithHierarchy", 25): {
auto src = args.asMatPtr(1);
auto hierarchy = args.asMatPtr(3);
auto mode = args.asNumber(4);
auto method = args.asNumber(5);

if (args.isMatVector(2)) {
auto dst = args.asMatVectorPtr(2);
cv::findContours(*src, *dst, *hierarchy, mode, method);
} else {
auto dst = args.asPointVectorOfVectorsPtr(2);
cv::findContours(*src, *dst, *hierarchy, mode, method);
}

} break;
case hashString("fitLine", 7): {
auto points = args.asMatPtr(1);
auto line = args.asMatPtr(2);
Expand Down
63 changes: 62 additions & 1 deletion docs/pages/availablefunctions.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,14 @@ invoke(
name: 'minMaxLoc',
src: Mat,
mask?: Mat
): { minVal: number; maxVal: number };
): {
minVal: number;
maxVal: number;
minX: number;
minY: number;
maxX: number;
maxY: number;
};
```

### mulSpectrums
Expand Down Expand Up @@ -882,6 +889,16 @@ invoke(
normType: NormTypes
): void;
```
### normalize

Merges several arrays to make a single multi-channel array

- channels input vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
- dst output array of the same size and the same depth as mv[0]; The number of channels will be the total number of channels in the matrix array.

```js
invoke(name: 'merge', channels: MatVector, dst: Mat): void;
```

### patchNaNs

Expand Down Expand Up @@ -991,6 +1008,29 @@ Fills the output array with repeated copies of the input array
invoke(name: 'repeat', src: Mat, ny: number, nx: number, dst: Mat): void;
```

### resize

The function resize resizes the image src down to or up to the specified size. Note that the initial dst type or size are not taken into account. Instead, the size and type are derived from the `src`,`dsize`,`fx`, and `fy`.

- src input image.
- dst output image; it has the size dsize (when it is non-zero) or the size computed from src.size(), fx, and fy; the type of dst is the same as of src.
- dsize output image size
- fx scale factor along the horizontal axis
- fy scale factor along the vertical axis
- interpolation interpolation method, see #InterpolationFlags

```js
invoke(
name: 'resize',
src: Mat,
dst: Mat,
dsize: Size,
fx: number,
fy: number,
interpolation: InterpolationFlags
): void;
```

### rotate

Rotates matrix.
Expand Down Expand Up @@ -2341,6 +2381,27 @@ invoke(
): void;
```

### findContoursWithHierarchy

Finds contours in a binary image

- image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1s. Zero pixels remain 0s, so the image is treated as binary . You can use compare, inRange, threshold , adaptiveThreshold, Canny, and others to create a binary image out of a grayscale or color one. If mode equals to RETR_CCOMP or RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).
- contours Detected contours. Each contour is stored as a vector of points
- hierarchy output vector, containing information about the image topology. It has as many elements as the number of contours.
- mode Contour retrieval mode, @see RetrievalModes
- method Contour approximation method, @see ContourApproximationModes

```js
invoke(
name: 'findContoursWithHierarchy',
image: Mat,
contours: MatVector | PointVectorOfVectors,
hierarchy: Mat,
mode: RetrievalModes,
method: ContourApproximationModes
): void;
```

### fitLine

Fits a line to a 2D or 3D point set.
Expand Down
41 changes: 40 additions & 1 deletion src/functions/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
SortFlags,
} from '../constants/Core';
import type { DataTypes } from '../constants/DataTypes';
import type { InterpolationFlags } from '../constants/ImageTransform';
import type {
Mat,
MatVector,
Expand All @@ -19,6 +20,7 @@ import type {
PointVector,
Rect,
Scalar,
Size,
} from '../objects/Objects';

export type Core = {
Expand Down Expand Up @@ -621,7 +623,14 @@ export type Core = {
name: 'minMaxLoc',
src: Mat,
mask?: Mat
): { minVal: number; maxVal: number };
): {
minVal: number;
maxVal: number;
minX: number;
minY: number;
maxX: number;
maxY: number;
};

/**
* Performs the per-element multiplication of two Fourier spectrums
Expand Down Expand Up @@ -710,6 +719,14 @@ export type Core = {
normType: NormTypes
): void;

/**
* Merges several arrays to make a single multi-channel array.
* @param name Function name.
* @param channels input vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
* @param dst output array of the same size and the same depth as mv[0]; The number of channels will be the total number of channels in the matrix array.
*/
invoke(name: 'merge', channels: MatVector, dst: Mat): void;

/**
* converts NaNs to the given number
* @param name Function name.
Expand Down Expand Up @@ -797,6 +814,28 @@ export type Core = {
*/
invoke(name: 'repeat', src: Mat, ny: number, nx: number, dst: Mat): void;

/**
* The function resize resizes the image src down to or up to the specified size. Note that the
* initial dst type or size are not taken into account. Instead, the size and type are derived from
* the `src`,`dsize`,`fx`, and `fy`.
* @param name Function name.
* @param src input image.
* @param dst output image; it has the size dsize (when it is non-zero) or the size computed from src.size(), fx, and fy; the type of dst is the same as of src.
* @param dsize output image size
* @param fx scale factor along the horizontal axis
* @param fy scale factor along the vertical axis
* @param interpolation interpolation method, see #InterpolationFlags
*/
invoke(
name: 'resize',
src: Mat,
dst: Mat,
dsize: Size,
fx: number,
fy: number,
interpolation: InterpolationFlags
): void;

/**
* Rotates matrix.
* @param name Function name.
Expand Down
17 changes: 17 additions & 0 deletions src/functions/ImageProcessing/Shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ export type Shape = {
method: ContourApproximationModes
): void;

/**
* Finds contours in a binary image
* @param image Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero pixels remain 0's, so the image is treated as binary . You can use compare, inRange, threshold , adaptiveThreshold, Canny, and others to create a binary image out of a grayscale or color one. If mode equals to RETR_CCOMP or RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).
* @param contours Detected contours. Each contour is stored as a vector of points
* @param hierarchy output vector, containing information about the image topology. It has as many elements as the number of contours.
* @param mode Contour retrieval mode, @see RetrievalModes
* @param method Contour approximation method, @see ContourApproximationModes
*/
invoke(
name: 'findContoursWithHierarchy',
image: Mat,
contours: MatVector | PointVectorOfVectors,
hierarchy: Mat,
mode: RetrievalModes,
method: ContourApproximationModes
): void;

/**
* Fits a line to a 2D or 3D point set.
* @param points Input vector of 2D or 3D points, stored in a Mat.
Expand Down
Loading