diff --git a/cpp/FOCV_Function.cpp b/cpp/FOCV_Function.cpp index d5b1d0f..456be2d 100644 --- a/cpp/FOCV_Function.cpp +++ b/cpp/FOCV_Function.cpp @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/docs/pages/availablefunctions.md b/docs/pages/availablefunctions.md index 264bd7a..a864b9e 100644 --- a/docs/pages/availablefunctions.md +++ b/docs/pages/availablefunctions.md @@ -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 @@ -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 @@ -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. @@ -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. diff --git a/src/functions/Core.ts b/src/functions/Core.ts index 3a2ae27..7020c53 100644 --- a/src/functions/Core.ts +++ b/src/functions/Core.ts @@ -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, @@ -19,6 +20,7 @@ import type { PointVector, Rect, Scalar, + Size, } from '../objects/Objects'; export type Core = { @@ -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 @@ -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. @@ -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. diff --git a/src/functions/ImageProcessing/Shape.ts b/src/functions/ImageProcessing/Shape.ts index 94528a0..4e27ff5 100644 --- a/src/functions/ImageProcessing/Shape.ts +++ b/src/functions/ImageProcessing/Shape.ts @@ -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.