Skip to content

Commit 1574683

Browse files
Merge pull request #23 from lukaszkurantdev/feat/floodfill-function
feat: floodfill function support
2 parents 0e7e6a3 + e681f9a commit 1574683

File tree

4 files changed

+69
-3
lines changed

4 files changed

+69
-3
lines changed

cpp/FOCV_Function.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,19 @@ jsi::Object FOCV_Function::invoke(jsi::Runtime& runtime, const jsi::Value* argum
356356

357357
cv::flip(*src, *dst, flipCode);
358358
} break;
359+
case hashString("floodFill", 9): {
360+
auto src = args.asMatPtr(1);
361+
auto mask = args.asMatPtr(2);
362+
auto seedPoint = args.asPointPtr(3);
363+
auto newVal = args.asScalarPtr(4);
364+
auto rect = args.asRectPtr(5);
365+
auto loDiff = args.asScalarPtr(6);
366+
auto upDiff = args.asScalarPtr(7);
367+
auto flags = args.asNumber(8);
368+
369+
int area = floodFill(*src, *mask, *seedPoint, *newVal, &(*rect), *loDiff, *upDiff, flags);
370+
value.setProperty(runtime, "value", area);
371+
} break;
359372
case hashString("gemm", 4): {
360373
auto src1 = args.asMatPtr(1);
361374
auto src2 = args.asMatPtr(2);

docs/pages/availablefunctions.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,33 @@ Flips a 2D array around vertical, horizontal, or both axes
486486
invoke(name: 'flip', src: Mat, dst: Mat, flipCode: number): void;
487487
```
488488

489+
### floodFill
490+
491+
Fills a connected component with the given color. The function cv::floodFill fills a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. Use these functions to either mark a connected component with the specified color in-place, or build a mask and then extract the contour, or copy the region to another image, and so on.
492+
493+
- image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the #FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See the details below.
494+
- mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller than image. Since this is both an input and output parameter, you must take responsibility of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags as described below. Additionally, the function fills the border of the mask with ones to simplify internal processing. It is therefore possible to use the same mask in multiple calls to the function to make sure the filled areas do not overlap.
495+
- seedPoint Starting point.
496+
- newVal New value of the repainted domain pixels.
497+
- rect Optional output parameter set by the function to the minimum bounding rectangle of the repainted domain.
498+
- loDiff Maximal lower brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component.
499+
- upDiff Maximal upper brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component.
500+
- flags Operation flags. The first 8 bits contain a connectivity value. The default value of 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest neighbours and fill the mask with a value of 255. The following additional options occupy higher bits and therefore may be further combined with the connectivity and mask fill values using bit-wise or (|), see #FloodFillFlags.
501+
502+
```js
503+
invoke(
504+
name: 'floodFill',
505+
image: Mat,
506+
mask: Mat,
507+
seedPoint: Point,
508+
newVal: Scalar,
509+
rect: Rect,
510+
loDiff: Scalar,
511+
upDiff: Scalar,
512+
flags: FloodFillFlags | number
513+
): { value: number };
514+
```
515+
489516
### gemm
490517

491518
Performs generalized matrix multiplication

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ PODS:
936936
- React-Mapbuffer (0.74.4):
937937
- glog
938938
- React-debug
939-
- react-native-fast-opencv (0.2.7):
939+
- react-native-fast-opencv (0.2.9):
940940
- DoubleConversion
941941
- glog
942942
- hermes-engine
@@ -1594,7 +1594,7 @@ SPEC CHECKSUMS:
15941594
React-jsitracing: 4e9c99e73a6269b27b0d4cbab277dd90df3e5ac0
15951595
React-logger: fbfb50e2a2b1b46ee087f0a52739fadecc5e81a4
15961596
React-Mapbuffer: d39610dff659d8cf1fea485abae08bbf6f9c8279
1597-
react-native-fast-opencv: 8e853bb378f92221c4b47fe98fc9283aedcf95fb
1597+
react-native-fast-opencv: dd72ca1a7a247326ffd83daa46a9c17487c3948b
15981598
react-native-image-picker: c3afe5472ef870d98a4b28415fc0b928161ee5f7
15991599
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
16001600
react-native-skia: 8da84ea9410504bf27f0db229539a43f6caabb6a

src/functions/ImageProcessing/Misc.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import type {
22
AdaptiveThresholdTypes,
33
DistanceTransformMasks,
44
DistanceTypes,
5+
FloodFillFlags,
56
ThresholdTypes,
67
} from '../../constants/ImageProcessing';
7-
import type { Mat } from '../../objects/Objects';
8+
import type { Mat, Point, Rect, Scalar } from '../../objects/Objects';
89

910
export type Misc = {
1011
/**
@@ -47,6 +48,31 @@ export type Misc = {
4748
maskSize: DistanceTransformMasks
4849
): void;
4950

51+
/** @Fills a connected component with the given color.
52+
* The function cv::floodFill fills a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels.
53+
* Use these functions to either mark a connected component with the specified color in-place, or build a mask and then extract the contour, or copy the region to another image, and so on.
54+
* @param name Function name.
55+
* @param image Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the #FLOODFILL_MASK_ONLY flag is set in the second variant of the function. See the details below.
56+
* @param mask Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller than image. Since this is both an input and output parameter, you must take responsibility of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in flags as described below. Additionally, the function fills the border of the mask with ones to simplify internal processing. It is therefore possible to use the same mask in multiple calls to the function to make sure the filled areas do not overlap.
57+
* @param seedPoint Starting point.
58+
* @param newVal New value of the repainted domain pixels.
59+
* @param rect Optional output parameter set by the function to the minimum bounding rectangle of the repainted domain.
60+
* @param loDiff Maximal lower brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component.
61+
* @param upDiff Maximal upper brightness/color difference between the currently observed pixel and one of its neighbors belonging to the component, or a seed pixel being added to the component.
62+
* @param flags Operation flags. The first 8 bits contain a connectivity value. The default value of 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill the mask (the default value is 1). For example, 4 | ( 255 \<\< 8 ) will consider 4 nearest neighbours and fill the mask with a value of 255. The following additional options occupy higher bits and therefore may be further combined with the connectivity and mask fill values using bit-wise or (|), see #FloodFillFlags.
63+
**/
64+
invoke(
65+
name: 'floodFill',
66+
image: Mat,
67+
mask: Mat,
68+
seedPoint: Point,
69+
newVal: Scalar,
70+
rect: Rect,
71+
loDiff: Scalar,
72+
upDiff: Scalar,
73+
flags: FloodFillFlags | number
74+
): { value: number };
75+
5076
/**
5177
* Calculates the integral of an image
5278
* @param name Function name.

0 commit comments

Comments
 (0)