Skip to content

Commit f9a63bf

Browse files
committed
feat: update arcLength and approxPolyDP to accept PointVector typed contours/curves
1 parent a6384b8 commit f9a63bf

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

cpp/FOCV_Function.cpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,16 +1154,36 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
11541154
cv::matchTemplate(*image, *templ, *result, method, *mask);
11551155
} break;
11561156
case hashString("approxPolyDP", 12): {
1157-
auto approxCurve = args.asMatPtr(2);
11581157
auto epsilon = args.asNumber(3);
11591158
auto closed = args.asBool(4);
1160-
1159+
11611160
if(args.isMat(1)) {
1162-
auto curve = args.asMatPtr(1);
1163-
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1161+
auto curve = args.asMatPtr(1);
1162+
if (args.isMat(2)) {
1163+
auto approxCurve = args.asMatPtr(2);
1164+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1165+
} else {
1166+
auto approxCurve = args.asPointVectorPtr(2);
1167+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1168+
}
1169+
} else if (args.isMatVector(1)) {
1170+
auto curve = args.asMatVectorPtr(1);
1171+
if (args.isMat(2)) {
1172+
auto approxCurve = args.asMatPtr(2);
1173+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1174+
} else {
1175+
auto approxCurve = args.asPointVectorPtr(2);
1176+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1177+
}
11641178
} else {
1165-
auto curve = args.asMatVectorPtr(1);
1166-
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1179+
auto curve = args.asPointVectorPtr(1);
1180+
if (args.isMat(2)) {
1181+
auto approxCurve = args.asMatPtr(2);
1182+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1183+
} else {
1184+
auto approxCurve = args.asPointVectorPtr(2);
1185+
cv::approxPolyDP(*curve, *approxCurve, epsilon, closed);
1186+
}
11671187
}
11681188
} break;
11691189
case hashString("arcLength", 9): {
@@ -1173,10 +1193,14 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
11731193
auto curve = args.asMatPtr(1);
11741194
auto result = cv::arcLength(*curve, closed);
11751195
value.setProperty(runtime, "value", jsi::Value(result));
1196+
} else if(args.isMatVector(1)) {
1197+
auto curve = args.asMatVectorPtr(1);
1198+
auto result = cv::arcLength(*curve, closed);
1199+
value.setProperty(runtime, "value", jsi::Value(result));
11761200
} else {
1177-
auto curve = args.asMatVectorPtr(1);
1178-
auto result = cv::arcLength(*curve, closed);
1179-
value.setProperty(runtime, "value", jsi::Value(result));
1201+
auto curve = args.asPointVectorPtr(1);
1202+
auto result = cv::arcLength(*curve, closed);
1203+
value.setProperty(runtime, "value", jsi::Value(result));
11801204
}
11811205
} break;
11821206
case hashString("boundingRect", 12): {
@@ -1292,4 +1316,4 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
12921316
}
12931317

12941318
return value;
1295-
}
1319+
}

docs/pages/availablefunctions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ Approximates a polygonal curve(s) with the specified precision
19711971
```js
19721972
invoke(
19731973
name: 'approxPolyDP',
1974-
curve: Mat | MatVector,
1974+
curve: Mat | MatVector | PointVector,
19751975
approxCurve: Mat,
19761976
epsilon: number,
19771977
closed: boolean
@@ -1987,7 +1987,7 @@ Calculates a contour perimeter or a curve length.
19871987
```js
19881988
invoke(
19891989
name: 'arcLength',
1990-
curve: Mat | MatVector,
1990+
curve: Mat | MatVector | PointVector,
19911991
closed: boolean
19921992
): { value: number };
19931993
```

src/functions/ImageProcessing/Shape.ts

Lines changed: 3 additions & 3 deletions
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)