Skip to content

Commit dfe6b2f

Browse files
feat: new functions
1 parent 564b937 commit dfe6b2f

22 files changed

+1905
-1668
lines changed

cpp/FOCV_Function.cpp

Lines changed: 594 additions & 47 deletions
Large diffs are not rendered by default.

cpp/FOCV_Object.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ jsi::Object FOCV_Object::create(jsi::Runtime& runtime, const jsi::Value* argumen
8686
object = cv::Scalar(a);
8787
}
8888
} break;
89+
case hashString("rotated_rect", 11): {
90+
int x = arguments[1].asNumber();
91+
int y = arguments[2].asNumber();
92+
int width = arguments[3].asNumber();
93+
int height = arguments[4].asNumber();
94+
int angle = arguments[5].asNumber();
95+
96+
object = cv::RotatedRect(cv::Point(x,y), cv::Size(width, height), angle);
97+
} break;
8998
}
9099

91100
std::string id = FOCV_Storage::save(object);
@@ -189,6 +198,15 @@ jsi::Object FOCV_Object::convertToJSI(jsi::Runtime& runtime, const jsi::Value* a
189198
value.setProperty(runtime, "c", jsi::Value(scalar.val[2]));
190199
value.setProperty(runtime, "d", jsi::Value(scalar.val[3]));
191200
} break;
201+
case hashString("rotated_rect", 11): {
202+
cv::RotatedRect rect = FOCV_Storage::get<cv::RotatedRect>(id);
203+
204+
value.setProperty(runtime, "centerX", jsi::Value(rect.center.x));
205+
value.setProperty(runtime, "centerY", jsi::Value(rect.center.y));
206+
value.setProperty(runtime, "width", jsi::Value(rect.size.width));
207+
value.setProperty(runtime, "height", jsi::Value(rect.size.height));
208+
value.setProperty(runtime, "angle", jsi::Value(rect.angle));
209+
} break;
192210
}
193211

194212
return value;

example/src/ImageExample.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function ImageExample() {
3131
const lowerBound = OpenCV.createObject(ObjectType.Vec3b, 0, 120, 120);
3232
const upperBound = OpenCV.createObject(ObjectType.Vec3b, 255, 255, 255);
3333

34-
OpenCV.invoke('inRange', dst, lowerBound, upperBound, dst);
34+
// OpenCV.invoke('inRange', dst, lowerBound, upperBound, dst);
3535

3636
const result = OpenCV.toJSValue(dst);
3737
setB64(result.base64);

example/src/VisionCameraExample.tsx

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,16 @@ export function VisionCameraExample() {
5353
OpenCV.invoke('cvtColor', src, dst, ColorConversionCodes.COLOR_BGR2RGB);
5454
OpenCV.invoke('cvtColor', dst, dst, ColorConversionCodes.COLOR_BGR2HSV);
5555

56-
const lowerBound = OpenCV.createObject(ObjectType.Vec3b, 37, 120, 120);
57-
const upperBound = OpenCV.createObject(ObjectType.Vec3b, 60, 255, 255);
56+
const lowerBound = OpenCV.frameBufferToMat(
57+
1,
58+
3,
59+
new Uint8Array([37, 120, 120])
60+
);
61+
const upperBound = OpenCV.frameBufferToMat(
62+
1,
63+
3,
64+
new Uint8Array([60, 255, 255])
65+
);
5866

5967
OpenCV.invoke('inRange', dst, lowerBound, upperBound, dst);
6068

@@ -64,21 +72,25 @@ export function VisionCameraExample() {
6472
const grayChannel = OpenCV.copyObjectFromVector(channels, 0);
6573
const rectangles: Rect[] = [];
6674

67-
const contours = OpenCV.invoke(
75+
const contours = OpenCV.createObject(ObjectType.MatVector);
76+
77+
OpenCV.invoke(
6878
'findContours',
6979
grayChannel,
80+
contours,
7081
RetrievalModes.RETR_TREE,
7182
ContourApproximationModes.CHAIN_APPROX_SIMPLE
7283
);
7384

74-
for (const contour of contours) {
75-
const { value: area } = OpenCV.invoke('contourArea', contour, false);
85+
// TO CHECK!
86+
// for (const contour of contours) {
87+
// const { value: area } = OpenCV.invoke('contourArea', contour, false);
7688

77-
if (area > 3000) {
78-
const rect = OpenCV.invoke('boundingRect', contour);
79-
rectangles.push(rect);
80-
}
81-
}
89+
// if (area > 3000) {
90+
// const rect = OpenCV.invoke('boundingRect', contour);
91+
// rectangles.push(rect);
92+
// }
93+
// }
8294

8395
frame.render();
8496

src/NativeFastOpencv.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { TurboModule } from 'react-native';
22
import { TurboModuleRegistry } from 'react-native';
33

4-
5-
6-
74
export interface Spec extends TurboModule {
85
multiply(a: number, b: number): Promise<number>;
96
}

src/constants/ImageProcessing.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ export enum MorphShapes {
7373
}
7474

7575
export enum MorphTypes {
76-
MORPH_ERODE = 'MORPH_ERODE',
77-
MORPH_DILATE = 'MORPH_DILATE',
78-
MORPH_OPEN = 'MORPH_OPEN',
79-
MORPH_CLOSE = 'MORPH_CLOSE',
80-
MORPH_GRADIENT = 'MORPH_GRADIENT',
81-
MORPH_TOPHAT = 'MORPH_TOPHAT',
82-
MORPH_BLACKHAT = 'MORPH_BLACKHAT',
83-
MORPH_HITMISS = 'MORPH_HITMISS',
76+
MORPH_ERODE = 0,
77+
MORPH_DILATE = 1,
78+
MORPH_OPEN = 2,
79+
MORPH_CLOSE = 3,
80+
MORPH_GRADIENT = 4,
81+
MORPH_TOPHAT = 5,
82+
MORPH_BLACKHAT = 6,
83+
MORPH_HITMISS = 7,
8484
}
8585

8686
export enum SpecialFilter {

src/functions/ColorConversion.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,30 @@ import type { Mat } from '../objects/Objects';
44
export type ColorConversion = {
55
/**
66
* Converts an image from one color space to another.
7+
* @param name Function name.
78
* @param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.
89
* @param dst output image of the same size and depth as src.
910
* @param code color space conversion code.
1011
* @param dstCn number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.
1112
*/
12-
cvtColor(
13+
invoke(
14+
name: 'cvtColor',
1315
src: Mat,
1416
dst: Mat,
1517
code: ColorConversionCodes,
1618
dstCn?: number
1719
): void;
20+
1821
/**
1922
* Converts an image from one color space to another where the source image is stored in two planes. This function only supports YUV420 to RGB conversion as of now.
23+
* @param name Function name.
2024
* @param src1 8-bit image (CV_8U) of the Y plane.
2125
* @param src2 image containing interleaved U/V plane.
2226
* @param dst output image.
2327
* @param code Specifies the type of conversion
2428
*/
25-
cvtColorTwoPlane(
29+
invoke(
30+
name: 'cvtColorTwoPlane',
2631
src1: Mat,
2732
src2: Mat,
2833
dst: Mat,
@@ -36,36 +41,36 @@ export type ColorConversion = {
3641
| ColorConversionCodes.COLOR_YUV2BGRA_NV21
3742
| ColorConversionCodes.COLOR_YUV2RGBA_NV21
3843
): void;
44+
3945
/**
4046
* main function for all demosaicing processes
47+
* @param name Function name.
4148
* @param src input image: 8-bit unsigned or 16-bit unsigned.
4249
* @param dst output image of the same size and depth as src.
4350
* @param code Color space conversion code (see the description below).
4451
* @param dstCn number of channels in the destination image
4552
*/
46-
demosaicing(
53+
invoke(
54+
name: 'demosaicing',
4755
src: Mat,
4856
dst: Mat,
49-
code: //Demosaicing using bilinear interpolation
50-
| ColorConversionCodes.COLOR_BayerBG2BGR
57+
code:
58+
| ColorConversionCodes.COLOR_BayerBG2BGR
5159
| ColorConversionCodes.COLOR_BayerGB2BGR
5260
| ColorConversionCodes.COLOR_BayerRG2BGR
5361
| ColorConversionCodes.COLOR_BayerGR2BGR
5462
| ColorConversionCodes.COLOR_BayerBG2GRAY
5563
| ColorConversionCodes.COLOR_BayerGB2GRAY
5664
| ColorConversionCodes.COLOR_BayerRG2GRAY
5765
| ColorConversionCodes.COLOR_BayerGR2GRAY
58-
// Demosaicing using Variable Number of Gradients.
5966
| ColorConversionCodes.COLOR_BayerBG2BGR_VNG
6067
| ColorConversionCodes.COLOR_BayerGB2BGR_VNG
6168
| ColorConversionCodes.COLOR_BayerRG2BGR_VNG
6269
| ColorConversionCodes.COLOR_BayerGR2BGR_VNG
63-
// Edge-Aware Demosaicing.
6470
| ColorConversionCodes.COLOR_BayerBG2BGR_EA
6571
| ColorConversionCodes.COLOR_BayerGB2BGR_EA
6672
| ColorConversionCodes.COLOR_BayerRG2BGR_EA
6773
| ColorConversionCodes.COLOR_BayerGR2BGR_EA
68-
// Demosaicing with alpha channel
6974
| ColorConversionCodes.COLOR_BayerBG2BGRA
7075
| ColorConversionCodes.COLOR_BayerGB2BGRA
7176
| ColorConversionCodes.COLOR_BayerRG2BGRA

0 commit comments

Comments
 (0)