Skip to content

Commit a38bbe8

Browse files
Merge pull request #10 from martinbooth/AdditionalTypingAndFeatures
Additional typing and features
2 parents a6384b8 + 855c0df commit a38bbe8

File tree

5 files changed

+171
-19
lines changed

5 files changed

+171
-19
lines changed

cpp/FOCV_Function.cpp

+63-10
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,16 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
10801080

10811081
return FOCV_JsiObject::wrap(runtime, "mat", id);
10821082
} break;
1083+
case hashString("getStructuringElement", 21): {
1084+
auto shape = args.asNumber(1);
1085+
auto ksize = args.asSizePtr(2);
1086+
auto anchor = args.asPointPtr(3);
1087+
1088+
cv::Mat result = cv::getStructuringElement(shape, *ksize, *anchor);
1089+
std::string id = FOCV_Storage::save(result);
1090+
1091+
return FOCV_JsiObject::wrap(runtime, "mat", id);
1092+
} break;
10831093
case hashString("Laplacian", 9): {
10841094
auto src = args.asMatPtr(1);
10851095
auto dst = args.asMatPtr(2);
@@ -1098,6 +1108,12 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
10981108

10991109
cv::medianBlur(*src, *dst, ksize);
11001110
} break;
1111+
case hashString("morphologyDefaultBorderValue", 28): {
1112+
auto scalar = cv::morphologyDefaultBorderValue();
1113+
std::string id = FOCV_Storage::save(scalar);
1114+
1115+
return FOCV_JsiObject::wrap(runtime, "scalar", id);
1116+
} break;
11011117
case hashString("morphologyEx", 12): {
11021118
auto src = args.asMatPtr(1);
11031119
auto dst = args.asMatPtr(2);
@@ -1135,6 +1151,19 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
11351151

11361152
cv::integral(*src, *dst);
11371153
} break;
1154+
case hashString("Sobel", 5): {
1155+
auto src = args.asMatPtr(1);
1156+
auto dst = args.asMatPtr(2);
1157+
auto ddepth = args.asNumber(3);
1158+
auto dx = args.asNumber(4);
1159+
auto dy = args.asNumber(5);
1160+
auto ksize = args.asNumber(6);
1161+
auto scale = args.asNumber(7);
1162+
auto delta = args.asNumber(8);
1163+
auto borderType = args.asNumber(9);
1164+
1165+
cv::Sobel(*src, *dst, ddepth, dx, dy, ksize, scale, delta, borderType);
1166+
} break;
11381167
case hashString("threshold", 9): {
11391168
auto src = args.asMatPtr(1);
11401169
auto dst = args.asMatPtr(2);
@@ -1154,16 +1183,36 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
11541183
cv::matchTemplate(*image, *templ, *result, method, *mask);
11551184
} break;
11561185
case hashString("approxPolyDP", 12): {
1157-
auto approxCurve = args.asMatPtr(2);
11581186
auto epsilon = args.asNumber(3);
11591187
auto closed = args.asBool(4);
1160-
1188+
11611189
if(args.isMat(1)) {
1162-
auto curve = args.asMatPtr(1);
1163-
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1190+
auto curve = args.asMatPtr(1);
1191+
if (args.isMat(2)) {
1192+
auto approxCurve = args.asMatPtr(2);
1193+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1194+
} else {
1195+
auto approxCurve = args.asPointVectorPtr(2);
1196+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1197+
}
1198+
} else if (args.isMatVector(1)) {
1199+
auto curve = args.asMatVectorPtr(1);
1200+
if (args.isMat(2)) {
1201+
auto approxCurve = args.asMatPtr(2);
1202+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1203+
} else {
1204+
auto approxCurve = args.asPointVectorPtr(2);
1205+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1206+
}
11641207
} else {
1165-
auto curve = args.asMatVectorPtr(1);
1166-
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1208+
auto curve = args.asPointVectorPtr(1);
1209+
if (args.isMat(2)) {
1210+
auto approxCurve = args.asMatPtr(2);
1211+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1212+
} else {
1213+
auto approxCurve = args.asPointVectorPtr(2);
1214+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1215+
}
11671216
}
11681217
} break;
11691218
case hashString("arcLength", 9): {
@@ -1173,10 +1222,14 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
11731222
auto curve = args.asMatPtr(1);
11741223
auto result = cv::arcLength(*curve, closed);
11751224
value.setProperty(runtime, "value", jsi::Value(result));
1225+
} else if(args.isMatVector(1)) {
1226+
auto curve = args.asMatVectorPtr(1);
1227+
auto result = cv::arcLength(*curve, closed);
1228+
value.setProperty(runtime, "value", jsi::Value(result));
11761229
} else {
1177-
auto curve = args.asMatVectorPtr(1);
1178-
auto result = cv::arcLength(*curve, closed);
1179-
value.setProperty(runtime, "value", jsi::Value(result));
1230+
auto curve = args.asPointVectorPtr(1);
1231+
auto result = cv::arcLength(*curve, closed);
1232+
value.setProperty(runtime, "value", jsi::Value(result));
11801233
}
11811234
} break;
11821235
case hashString("boundingRect", 12): {
@@ -1292,4 +1345,4 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
12921345
}
12931346

12941347
return value;
1295-
}
1348+
}

docs/pages/availablefunctions.md

+57-2
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,23 @@ invoke(
17931793
): Mat;
17941794
```
17951795

1796+
### getStructuringElement
1797+
1798+
Returns a structuring element of the specified size and shape for morphological operations.
1799+
1800+
- shape Element shape that could be one of MorphShapes
1801+
- ksize Size of the structuring element.
1802+
- 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..
1803+
1804+
```js
1805+
invoke(
1806+
name: 'getGaussianKernel',
1807+
shape: MorphShapes,
1808+
ksize: Size,
1809+
anchor: Point
1810+
): Mat;
1811+
```
1812+
17961813
### Laplacian
17971814
Calculates the Laplacian of an image.
17981815
- name Function name.
@@ -1829,6 +1846,14 @@ The function smoothes an image using the median filter with the 𝚔𝚜𝚒𝚣
18291846
invoke(name: 'medianBlur', src: Mat, dst: Mat, ksize: number): void;
18301847
```
18311848

1849+
### morphologyDefaultBorderValue
1850+
1851+
@returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.
1852+
1853+
```js
1854+
invoke(name: 'morphologyDefaultBorderValue'): Scalar;
1855+
```
1856+
18321857
### morphologyEx
18331858
Performs advanced morphological transformations.
18341859
The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as basic operations.
@@ -1915,6 +1940,36 @@ Calculates the integral of an image
19151940
invoke(name: 'integral', src: Mat, sum: Mat): void;
19161941
```
19171942

1943+
### Sobel
1944+
1945+
Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
1946+
1947+
- name Function name.
1948+
- src input image.
1949+
- dst output image of the same size and the same number of channels as src .
1950+
- ddepth output image depth, see combinations; in the case of 8-bit input images it will result in truncated derivatives.
1951+
- dx order of the derivative x.
1952+
- dy order of the derivative y.
1953+
- ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
1954+
- scale scale factor for the computed derivative values; by default, no scaling is applied (see getDerivKernels for details).
1955+
- delta delta value that is added to the results prior to storing them in dst.
1956+
- borderType Pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.
1957+
1958+
```js
1959+
invoke(
1960+
name: 'Sobel',
1961+
src: Mat,
1962+
dst: Mat,
1963+
ddepth: number,
1964+
dx: number,
1965+
dy: number,
1966+
ksize: 1 | 3 | 5 | 7,
1967+
scale: number,
1968+
delta: number,
1969+
borderType: Exclude<BorderTypes, BorderTypes.BORDER_WRAP>
1970+
): void;
1971+
```
1972+
19181973
### threshold
19191974
Applies a fixed-level threshold to each array element
19201975
- name Function name.
@@ -1971,7 +2026,7 @@ Approximates a polygonal curve(s) with the specified precision
19712026
```js
19722027
invoke(
19732028
name: 'approxPolyDP',
1974-
curve: Mat | MatVector,
2029+
curve: Mat | MatVector | PointVector,
19752030
approxCurve: Mat,
19762031
epsilon: number,
19772032
closed: boolean
@@ -1987,7 +2042,7 @@ Calculates a contour perimeter or a curve length.
19872042
```js
19882043
invoke(
19892044
name: 'arcLength',
1990-
curve: Mat | MatVector,
2045+
curve: Mat | MatVector | PointVector,
19912046
closed: boolean
19922047
): { value: number };
19932048
```

src/constants/ImageProcessing.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ export enum LineSegmentDetectorModes {
6767
}
6868

6969
export enum MorphShapes {
70-
MORPH_RECT = 'MORPH_RECT',
71-
MORPH_CROSS = 'MORPH_CROSS',
72-
MORPH_ELLIPSE = 'MORPH_ELLIPSE',
70+
MORPH_RECT = 0,
71+
MORPH_CROSS = 1,
72+
MORPH_ELLIPSE = 2,
7373
}
7474

7575
export enum MorphTypes {

src/functions/ImageProcessing/ImageFiltering.ts

+45-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BorderTypes } from '../../constants/Core';
22
import type { DataTypes } from '../../constants/DataTypes';
3-
import type { MorphTypes } from '../../constants/ImageProcessing';
3+
import type { MorphShapes, MorphTypes } from '../../constants/ImageProcessing';
44
import type { Mat, Point, Scalar, Size } from '../../objects/Objects';
55

66
export type ImageFiltering = {
@@ -192,6 +192,19 @@ export type ImageFiltering = {
192192
ktype: DataTypes.CV_32F | DataTypes.CV_64F
193193
): Mat;
194194

195+
/**
196+
* Returns a structuring element of the specified size and shape for morphological operations.
197+
* @param shape Element shape that could be one of MorphShapes
198+
* @param ksize Size of the structuring element.
199+
* @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.
200+
*/
201+
invoke(
202+
name: 'getStructuringElement',
203+
shape: MorphShapes,
204+
ksize: Size,
205+
anchor: Point
206+
): Mat;
207+
195208
/**
196209
* Calculates the Laplacian of an image.
197210
* @param name Function name.
@@ -224,6 +237,11 @@ export type ImageFiltering = {
224237
*/
225238
invoke(name: 'medianBlur', src: Mat, dst: Mat, ksize: number): void;
226239

240+
/**
241+
* returns "magic" border value for erosion and dilation. It is automatically transformed to Scalar::all(-DBL_MAX) for dilation.
242+
*/
243+
invoke(name: 'morphologyDefaultBorderValue'): Scalar;
244+
227245
/**
228246
* Performs advanced morphological transformations.
229247
* The function cv::morphologyEx can perform advanced morphological transformations using an erosion and dilation as basic operations.
@@ -249,4 +267,30 @@ export type ImageFiltering = {
249267
borderType: BorderTypes,
250268
borderValue: Scalar
251269
): void;
270+
271+
/**
272+
* Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
273+
* @param name Function name.
274+
* @param src input image.
275+
* @param dst output image of the same size and the same number of channels as src .
276+
* @param ddepth output image depth, see combinations; in the case of 8-bit input images it will result in truncated derivatives.
277+
* @param dx order of the derivative x.
278+
* @param dy order of the derivative y.
279+
* @param ksize size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
280+
* @param scale scale factor for the computed derivative values; by default, no scaling is applied (see getDerivKernels for details).
281+
* @param delta delta value that is added to the results prior to storing them in dst.
282+
* @param borderType Pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.
283+
*/
284+
invoke(
285+
name: 'Sobel',
286+
src: Mat,
287+
dst: Mat,
288+
ddepth: number,
289+
dx: number,
290+
dy: number,
291+
ksize: 1 | 3 | 5 | 7,
292+
scale: number,
293+
delta: number,
294+
borderType: Exclude<BorderTypes, BorderTypes.BORDER_WRAP>
295+
): void;
252296
};

src/functions/ImageProcessing/Shape.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export type Shape = {
2323
*/
2424
invoke(
2525
name: 'approxPolyDP',
26-
curve: Mat | MatVector,
27-
approxCurve: Mat,
26+
curve: Mat | MatVector | PointVector,
27+
approxCurve: Mat | PointVector,
2828
epsilon: number,
2929
closed: boolean
3030
): void;
@@ -37,7 +37,7 @@ export type Shape = {
3737
*/
3838
invoke(
3939
name: 'arcLength',
40-
curve: Mat | MatVector,
40+
curve: Mat | MatVector | PointVector,
4141
closed: boolean
4242
): { value: number };
4343

0 commit comments

Comments
 (0)