Skip to content

Commit 9c03fd1

Browse files
feat: find contours with hierarchy
1 parent 4a8a64a commit 9c03fd1

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

cpp/FOCV_Function.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,21 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
13961396
cv::findContours(*src, *dst, mode, method);
13971397
}
13981398
} break;
1399+
case hashString("findContoursWithHierarchy", 25): {
1400+
auto src = args.asMatPtr(1);
1401+
auto hierarchy = args.asMatPtr(3);
1402+
auto mode = args.asNumber(4);
1403+
auto method = args.asNumber(5);
1404+
1405+
if (args.isMatVector(2)) {
1406+
auto dst = args.asMatVectorPtr(2);
1407+
cv::findContours(*src, *dst, *hierarchy, mode, method);
1408+
} else {
1409+
auto dst = args.asPointVectorOfVectorsPtr(2);
1410+
cv::findContours(*src, *dst, *hierarchy, mode, method);
1411+
}
1412+
1413+
} break;
13991414
case hashString("fitLine", 7): {
14001415
auto points = args.asMatPtr(1);
14011416
auto line = args.asMatPtr(2);

docs/pages/availablefunctions.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,27 @@ invoke(
23642364
): void;
23652365
```
23662366

2367+
### findContoursWithHierarchy
2368+
2369+
Finds contours in a binary image
2370+
2371+
- 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).
2372+
- contours Detected contours. Each contour is stored as a vector of points
2373+
- hierarchy output vector, containing information about the image topology. It has as many elements as the number of contours.
2374+
- mode Contour retrieval mode, @see RetrievalModes
2375+
- method Contour approximation method, @see ContourApproximationModes
2376+
2377+
```js
2378+
invoke(
2379+
name: 'findContoursWithHierarchy',
2380+
image: Mat,
2381+
contours: MatVector | PointVectorOfVectors,
2382+
hierarchy: Mat,
2383+
mode: RetrievalModes,
2384+
method: ContourApproximationModes
2385+
): void;
2386+
```
2387+
23672388
### fitLine
23682389

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

src/functions/ImageProcessing/Shape.ts

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