Skip to content

Commit 7f7c126

Browse files
docs: customized calculations
1 parent b9ae60b commit 7f7c126

File tree

6 files changed

+74
-8
lines changed

6 files changed

+74
-8
lines changed

docs/pages/customized.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
In special cases where you need maximum performance, you can easily create your own code in C++ and run it from within the JS code.
1+
# Customized calculations (C++)
2+
3+
> Only in advanced cases.
4+
5+
In special cases where you will need maximum performance or some functionality is missing from the library, you can easily create your own code in C++ and run it from JS code.
6+
7+
As the code can be written in C++, the solution will be fully cross-platform and does not need different implementations for iOS and Android.
8+
9+
In file `cpp/react-native-fast-opencv.cpp` find this lines:
10+
11+
```cpp
12+
/// ...
13+
} else if (propName == "clearBuffers") {
14+
return jsi::Function::createFromHostFunction(
15+
runtime, jsi::PropNameID::forAscii(runtime, "clearBuffers"), 1,
16+
[=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
17+
size_t count) -> jsi::Value {
18+
19+
FOCV_Storage::clear();
20+
return true;
21+
});
22+
}
23+
24+
return jsi::HostObject::get(runtime, propNameId);
25+
}
26+
// ...
27+
```
28+
29+
Add your own else check with your own customized name of function:
30+
31+
```cpp
32+
else if (propName == "customFunction") {
33+
return jsi::Function::createFromHostFunction(
34+
runtime, jsi::PropNameID::forAscii(runtime, "clearBuffers"), 1,
35+
[=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
36+
size_t count) -> jsi::Value {
37+
38+
// Params
39+
FOCV_FunctionArguments args(runtime, arguments);
40+
41+
// Example – first param is string
42+
auto param1 = args.asString(0);
43+
44+
// Second param is Mat
45+
auto functionName = args.asMatPtr(1);
46+
47+
// etc
48+
49+
// Calculations...
50+
// HERE OpenCV functions and API is available
51+
// Check how to get parameters from function
52+
// Examples in FOCV_Function.cpp
53+
54+
// return JSI data or just do something...
55+
});
56+
}
57+
```
58+
59+
Compile et voilà – you can use it in your JS code:
60+
61+
```js
62+
OpenCV.customFunction(params);
63+
```

docs/pages/examples/_meta.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"realtimedetection": "Real-time detection"
2+
"realtimedetection": "Real-time detection",
3+
"blur": "Blur image on separated thread"
34
}

docs/pages/examples/blur.md

Whitespace-only changes.

docs/pages/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Due to the size of the OpenCV library, this port currently only supports selecte
2828

2929
List of available functions are available [here](./availablefunctions.md).
3030

31+
---
3132

3233
### Credits
3334
Special thanks to:

docs/theme.config.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ const logo = () => {
1313
data-name="Path 16"
1414
d="M-7.119,4.2A8.289,8.289,0,0,1-10.981-5.12a8.289,8.289,0,0,1,8.006-6.143A8.289,8.289,0,0,1,5.032-5.12,8.289,8.289,0,0,1,1.17,4.2l-2.5-4.323A3.3,3.3,0,0,0,.211-3.828,3.3,3.3,0,0,0-2.975-6.272,3.3,3.3,0,0,0-6.16-3.828,3.3,3.3,0,0,0-4.623-.119Z"
1515
transform="translate(23.58 11.263)"
16-
fill="#fff"
16+
fill="#409ded"
1717
/>
1818
<path
1919
id="Path_17"
2020
data-name="Path 17"
2121
d="M4.145,15.467a8.289,8.289,0,1,1,8.289,0l-2.5-4.323a3.3,3.3,0,1,0-3.3,0Z"
2222
transform="translate(38.36 32.945) rotate(180)"
23-
fill="#fff"
23+
fill="#409ded"
2424
/>
2525
<path
2626
id="Path_18"
2727
data-name="Path 18"
2828
d="M4.145,15.468a8.289,8.289,0,1,1,8.289,0l-2.5-4.323a3.3,3.3,0,1,0-3.3,0Z"
2929
transform="translate(8.29 35.979) rotate(-119.998)"
30-
fill="#fff"
30+
fill="#409ded"
3131
/>
3232
</g>
3333
</svg>

example/src/ImageExample.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ export function ImageExample() {
7777
}
7878
};
7979

80-
const test2 = useRunOnJS((data: string) => {
81-
setB64(data);
80+
const [base64, setBase64] = useState<string>('');
81+
82+
const setImage = useRunOnJS((data: string) => {
83+
setBase64(data);
8284
}, []);
8385

8486
const worklet = useWorklet(
@@ -103,7 +105,7 @@ export function ImageExample() {
103105

104106
const result = OpenCV.toJSValue(dst);
105107

106-
test2(result.base64);
108+
setImage(result.base64);
107109
}
108110
},
109111
[]

0 commit comments

Comments
 (0)