Skip to content

Commit 159dff3

Browse files
Merge pull request #78 from lukaszkurantdev/feat/minor-changes
Feat/minor changes
2 parents 6a4c8cb + c971162 commit 159dff3

File tree

4 files changed

+158
-4
lines changed

4 files changed

+158
-4
lines changed

cpp/FOCV_Function.cpp

+39-2
Original file line numberDiff line numberDiff line change
@@ -513,16 +513,22 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
513513
double min = 0;
514514
double max = 0;
515515

516+
Point minLoc; Point maxLoc;
517+
516518
if (count > 2) {
517519
auto mask = args.asMatPtr(2);
518520

519-
cv::minMaxIdx(*src, &min, &max, NULL, NULL, *mask);
521+
cv::minMaxLoc(*src, &min, &max, &minLoc, &maxLoc, *mask);
520522
} else {
521-
cv::minMaxIdx(*src, &min, &max);
523+
cv::minMaxLoc(*src, &min, &max, &minLoc, &maxLoc);
522524
}
523525

524526
value.setProperty(runtime, "minVal", jsi::Value(min));
525527
value.setProperty(runtime, "maxVal", jsi::Value(max));
528+
value.setProperty(runtime, "minX", minLoc.x);
529+
value.setProperty(runtime, "minY", minLoc.y);
530+
value.setProperty(runtime, "maxX", maxLoc.x);
531+
value.setProperty(runtime, "maxY", maxLoc.y);
526532
} break;
527533
case hashString("mulSpectrums", 12): {
528534
auto a = args.asMatPtr(1);
@@ -590,6 +596,12 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
590596

591597
cv::normalize(*src, *dst, alpha, normType);
592598
} break;
599+
case hashString("merge", 5): {
600+
auto src = args.asMatVectorPtr(1);
601+
auto dst = args.asMatPtr(2);
602+
603+
cv::merge(*src, *dst);
604+
} break;
593605
case hashString("patchNaNs", 9): {
594606
auto alpha = args.asNumber(2);
595607

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

655667
cv::repeat(*src, ny, nx, *dst);
656668
} break;
669+
case hashString("resize", 6): {
670+
auto src = args.asMatPtr(1);
671+
auto dst = args.asMatPtr(2);
672+
auto dsize = args.asSizePtr(3);
673+
auto fx = args.asNumber(4);
674+
auto fy = args.asNumber(5);
675+
auto interpolation = args.asNumber(6);
676+
677+
cv::resize(*src, *dst, *dsize, fx, fy, interpolation);
678+
} break;
657679
case hashString("rotate", 6): {
658680
auto src = args.asMatPtr(1);
659681
auto dst = args.asMatPtr(2);
@@ -1386,6 +1408,21 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
13861408
cv::findContours(*src, *dst, mode, method);
13871409
}
13881410
} break;
1411+
case hashString("findContoursWithHierarchy", 25): {
1412+
auto src = args.asMatPtr(1);
1413+
auto hierarchy = args.asMatPtr(3);
1414+
auto mode = args.asNumber(4);
1415+
auto method = args.asNumber(5);
1416+
1417+
if (args.isMatVector(2)) {
1418+
auto dst = args.asMatVectorPtr(2);
1419+
cv::findContours(*src, *dst, *hierarchy, mode, method);
1420+
} else {
1421+
auto dst = args.asPointVectorOfVectorsPtr(2);
1422+
cv::findContours(*src, *dst, *hierarchy, mode, method);
1423+
}
1424+
1425+
} break;
13891426
case hashString("fitLine", 7): {
13901427
auto points = args.asMatPtr(1);
13911428
auto line = args.asMatPtr(2);

docs/pages/availablefunctions.md

+62-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,14 @@ invoke(
778778
name: 'minMaxLoc',
779779
src: Mat,
780780
mask?: Mat
781-
): { minVal: number; maxVal: number };
781+
): {
782+
minVal: number;
783+
maxVal: number;
784+
minX: number;
785+
minY: number;
786+
maxX: number;
787+
maxY: number;
788+
};
782789
```
783790

784791
### mulSpectrums
@@ -882,6 +889,16 @@ invoke(
882889
normType: NormTypes
883890
): void;
884891
```
892+
### normalize
893+
894+
Merges several arrays to make a single multi-channel array
895+
896+
- channels input vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
897+
- 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.
898+
899+
```js
900+
invoke(name: 'merge', channels: MatVector, dst: Mat): void;
901+
```
885902

886903
### patchNaNs
887904

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

1011+
### resize
1012+
1013+
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`.
1014+
1015+
- src input image.
1016+
- 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.
1017+
- dsize output image size
1018+
- fx scale factor along the horizontal axis
1019+
- fy scale factor along the vertical axis
1020+
- interpolation interpolation method, see #InterpolationFlags
1021+
1022+
```js
1023+
invoke(
1024+
name: 'resize',
1025+
src: Mat,
1026+
dst: Mat,
1027+
dsize: Size,
1028+
fx: number,
1029+
fy: number,
1030+
interpolation: InterpolationFlags
1031+
): void;
1032+
```
1033+
9941034
### rotate
9951035

9961036
Rotates matrix.
@@ -2341,6 +2381,27 @@ invoke(
23412381
): void;
23422382
```
23432383

2384+
### findContoursWithHierarchy
2385+
2386+
Finds contours in a binary image
2387+
2388+
- 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).
2389+
- contours Detected contours. Each contour is stored as a vector of points
2390+
- hierarchy output vector, containing information about the image topology. It has as many elements as the number of contours.
2391+
- mode Contour retrieval mode, @see RetrievalModes
2392+
- method Contour approximation method, @see ContourApproximationModes
2393+
2394+
```js
2395+
invoke(
2396+
name: 'findContoursWithHierarchy',
2397+
image: Mat,
2398+
contours: MatVector | PointVectorOfVectors,
2399+
hierarchy: Mat,
2400+
mode: RetrievalModes,
2401+
method: ContourApproximationModes
2402+
): void;
2403+
```
2404+
23442405
### fitLine
23452406

23462407
Fits a line to a 2D or 3D point set.

src/functions/Core.ts

+40-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
SortFlags,
1212
} from '../constants/Core';
1313
import type { DataTypes } from '../constants/DataTypes';
14+
import type { InterpolationFlags } from '../constants/ImageTransform';
1415
import type {
1516
Mat,
1617
MatVector,
@@ -19,6 +20,7 @@ import type {
1920
PointVector,
2021
Rect,
2122
Scalar,
23+
Size,
2224
} from '../objects/Objects';
2325

2426
export type Core = {
@@ -621,7 +623,14 @@ export type Core = {
621623
name: 'minMaxLoc',
622624
src: Mat,
623625
mask?: Mat
624-
): { minVal: number; maxVal: number };
626+
): {
627+
minVal: number;
628+
maxVal: number;
629+
minX: number;
630+
minY: number;
631+
maxX: number;
632+
maxY: number;
633+
};
625634

626635
/**
627636
* Performs the per-element multiplication of two Fourier spectrums
@@ -710,6 +719,14 @@ export type Core = {
710719
normType: NormTypes
711720
): void;
712721

722+
/**
723+
* Merges several arrays to make a single multi-channel array.
724+
* @param name Function name.
725+
* @param channels input vector of matrices to be merged; all the matrices in mv must have the same size and the same depth.
726+
* @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.
727+
*/
728+
invoke(name: 'merge', channels: MatVector, dst: Mat): void;
729+
713730
/**
714731
* converts NaNs to the given number
715732
* @param name Function name.
@@ -797,6 +814,28 @@ export type Core = {
797814
*/
798815
invoke(name: 'repeat', src: Mat, ny: number, nx: number, dst: Mat): void;
799816

817+
/**
818+
* The function resize resizes the image src down to or up to the specified size. Note that the
819+
* initial dst type or size are not taken into account. Instead, the size and type are derived from
820+
* the `src`,`dsize`,`fx`, and `fy`.
821+
* @param name Function name.
822+
* @param src input image.
823+
* @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.
824+
* @param dsize output image size
825+
* @param fx scale factor along the horizontal axis
826+
* @param fy scale factor along the vertical axis
827+
* @param interpolation interpolation method, see #InterpolationFlags
828+
*/
829+
invoke(
830+
name: 'resize',
831+
src: Mat,
832+
dst: Mat,
833+
dsize: Size,
834+
fx: number,
835+
fy: number,
836+
interpolation: InterpolationFlags
837+
): void;
838+
800839
/**
801840
* Rotates matrix.
802841
* @param name Function name.

src/functions/ImageProcessing/Shape.ts

+17
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,23 @@ export type Shape = {
123123
method: ContourApproximationModes
124124
): void;
125125

126+
/**
127+
* Finds contours in a binary image
128+
* @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).
129+
* @param contours Detected contours. Each contour is stored as a vector of points
130+
* @param hierarchy output vector, containing information about the image topology. It has as many elements as the number of contours.
131+
* @param mode Contour retrieval mode, @see RetrievalModes
132+
* @param method Contour approximation method, @see ContourApproximationModes
133+
*/
134+
invoke(
135+
name: 'findContoursWithHierarchy',
136+
image: Mat,
137+
contours: MatVector | PointVectorOfVectors,
138+
hierarchy: Mat,
139+
mode: RetrievalModes,
140+
method: ContourApproximationModes
141+
): void;
142+
126143
/**
127144
* Fits a line to a 2D or 3D point set.
128145
* @param points Input vector of 2D or 3D points, stored in a Mat.

0 commit comments

Comments
 (0)