Skip to content

Commit d45d4bf

Browse files
Merge pull request #8 from thomas-coldwell/@thomas/camera-passthrough
feat: Camera Passthrough
2 parents 400db07 + a3b8cf9 commit d45d4bf

13 files changed

+1857
-1261
lines changed

cpp/FOCV_Function.cpp

Lines changed: 1237 additions & 1233 deletions
Large diffs are not rendered by default.

cpp/react-native-fast-opencv.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,34 @@ jsi::Value OpenCVPlugin::get(jsi::Runtime& runtime, const jsi::PropNameID& propN
4141

4242
if (propName == "frameBufferToMat") {
4343
return jsi::Function::createFromHostFunction(
44-
runtime, jsi::PropNameID::forAscii(runtime, "frameBufferToMat"), 1,
44+
runtime, jsi::PropNameID::forAscii(runtime, "frameBufferToMat"), 4,
4545
[=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments,
4646
size_t count) -> jsi::Object {
47+
double rows = arguments[0].asNumber();
48+
double cols = arguments[1].asNumber();
49+
int channels = arguments[2].asNumber();
50+
jsi::Object input = arguments[3].asObject(runtime);
51+
52+
int type = -1;
53+
if (channels == 1) {
54+
type = CV_8U;
55+
}
56+
if (channels == 3) {
57+
type = CV_8UC3;
58+
}
59+
if (channels == 4) {
60+
type = CV_8UC4;
61+
}
62+
63+
if (channels == -1) {
64+
throw std::runtime_error("Fast OpenCV Error: Invalid channel count passed to frameBufferToMat!");
65+
}
4766

48-
jsi::Object input = arguments[2].asObject(runtime);
4967
TypedArrayBase inputBuffer = getTypedArray(runtime, std::move(input));
5068
auto vec = inputBuffer.toVector(runtime);
5169

52-
cv::Mat mat(arguments[0].asNumber(), arguments[1].asNumber(), CV_8UC3, vec.data());
70+
cv::Mat mat(rows, cols, type);
71+
memcpy(mat.data, vec.data(), (int)rows * (int)cols * channels);
5372
auto id = FOCV_Storage::save(mat);
5473

5574
return FOCV_JsiObject::wrap(runtime, "mat", id);

example/ios/Podfile.lock

Lines changed: 35 additions & 3 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.0):
939+
- react-native-fast-opencv (0.2.4):
940940
- DoubleConversion
941941
- glog
942942
- hermes-engine
@@ -979,6 +979,8 @@ PODS:
979979
- ReactCommon/turbomodule/bridging
980980
- ReactCommon/turbomodule/core
981981
- Yoga
982+
- react-native-safe-area-context (4.11.0):
983+
- React-Core
982984
- react-native-skia (1.3.11):
983985
- DoubleConversion
984986
- glog
@@ -1300,6 +1302,28 @@ PODS:
13001302
- ReactCommon/turbomodule/bridging
13011303
- ReactCommon/turbomodule/core
13021304
- Yoga
1305+
- RNScreens (3.34.0):
1306+
- DoubleConversion
1307+
- glog
1308+
- hermes-engine
1309+
- RCT-Folly (= 2024.01.01.00)
1310+
- RCTRequired
1311+
- RCTTypeSafety
1312+
- React-Codegen
1313+
- React-Core
1314+
- React-debug
1315+
- React-Fabric
1316+
- React-featureflags
1317+
- React-graphics
1318+
- React-ImageManager
1319+
- React-NativeModulesApple
1320+
- React-RCTFabric
1321+
- React-RCTImage
1322+
- React-rendererdebug
1323+
- React-utils
1324+
- ReactCommon/turbomodule/bridging
1325+
- ReactCommon/turbomodule/core
1326+
- Yoga
13031327
- SocketRocket (0.7.0)
13041328
- vision-camera-resize-plugin (3.1.0):
13051329
- DoubleConversion
@@ -1372,6 +1396,7 @@ DEPENDENCIES:
13721396
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
13731397
- react-native-fast-opencv (from `../..`)
13741398
- react-native-image-picker (from `../node_modules/react-native-image-picker`)
1399+
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
13751400
- "react-native-skia (from `../node_modules/@shopify/react-native-skia`)"
13761401
- react-native-worklets-core (from `../node_modules/react-native-worklets-core`)
13771402
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
@@ -1398,6 +1423,7 @@ DEPENDENCIES:
13981423
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
13991424
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
14001425
- RNReanimated (from `../node_modules/react-native-reanimated`)
1426+
- RNScreens (from `../node_modules/react-native-screens`)
14011427
- vision-camera-resize-plugin (from `../node_modules/vision-camera-resize-plugin`)
14021428
- VisionCamera (from `../node_modules/react-native-vision-camera`)
14031429
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
@@ -1473,6 +1499,8 @@ EXTERNAL SOURCES:
14731499
:path: "../.."
14741500
react-native-image-picker:
14751501
:path: "../node_modules/react-native-image-picker"
1502+
react-native-safe-area-context:
1503+
:path: "../node_modules/react-native-safe-area-context"
14761504
react-native-skia:
14771505
:path: "../node_modules/@shopify/react-native-skia"
14781506
react-native-worklets-core:
@@ -1525,6 +1553,8 @@ EXTERNAL SOURCES:
15251553
:path: "../node_modules/react-native/ReactCommon"
15261554
RNReanimated:
15271555
:path: "../node_modules/react-native-reanimated"
1556+
RNScreens:
1557+
:path: "../node_modules/react-native-screens"
15281558
vision-camera-resize-plugin:
15291559
:path: "../node_modules/vision-camera-resize-plugin"
15301560
VisionCamera:
@@ -1564,8 +1594,9 @@ SPEC CHECKSUMS:
15641594
React-jsitracing: 4e9c99e73a6269b27b0d4cbab277dd90df3e5ac0
15651595
React-logger: fbfb50e2a2b1b46ee087f0a52739fadecc5e81a4
15661596
React-Mapbuffer: d39610dff659d8cf1fea485abae08bbf6f9c8279
1567-
react-native-fast-opencv: d143740f4a4f50a0946a00fbc7e8069ea5427695
1597+
react-native-fast-opencv: 52cb988f5dee40a599381c4617b8560977ed983c
15681598
react-native-image-picker: c3afe5472ef870d98a4b28415fc0b928161ee5f7
1599+
react-native-safe-area-context: 851c62c48dce80ccaa5637b6aa5991a1bc36eca9
15691600
react-native-skia: 8da84ea9410504bf27f0db229539a43f6caabb6a
15701601
react-native-worklets-core: f51430dd07bf5343d4918d28a4bb00fe8f98b982
15711602
React-nativeconfig: 2be4363c2c4ac2b42419577774e83e4e4fd2af9f
@@ -1592,10 +1623,11 @@ SPEC CHECKSUMS:
15921623
React-utils: e8b0eac797c81c574b24f6515fec4015599b643c
15931624
ReactCommon: eebffb37a90138c6db6eb8b2d952e7e5c6bc083c
15941625
RNReanimated: 45553a3ae29a75a76269595f8554d07d4090e392
1626+
RNScreens: aa943ad421c3ced3ef5a47ede02b0cbfc43a012e
15951627
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
15961628
vision-camera-resize-plugin: 4306d5df9bce0e603bbe6ab04337f21a606f4ad1
15971629
VisionCamera: 057aff621f7801b7d99a00d157fa39244bbd4fd2
1598-
Yoga: 6259f968a4fdf516d76a4432dead624d71aa0fb1
1630+
Yoga: 0efb3e1bd40ba59b009f01badea863281101de78
15991631

16001632
PODFILE CHECKSUM: ded8a41f26047703e900afe99b8a72ca375b02ca
16011633

example/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@
1010
"build:ios": "react-native build-ios --scheme FastOpencvExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\""
1111
},
1212
"dependencies": {
13+
"@react-navigation/native": "^6.1.18",
14+
"@react-navigation/native-stack": "^6.11.0",
1315
"@shopify/react-native-skia": "^1.3.10",
1416
"react": "18.2.0",
1517
"react-native": "0.74.4",
1618
"react-native-image-picker": "^7.1.2",
1719
"react-native-reanimated": "^3.14.0",
20+
"react-native-safe-area-context": "^4.11.0",
21+
"react-native-screens": "^3.34.0",
1822
"react-native-vision-camera": "^4.5.2",
1923
"react-native-worklets-core": "^1.3.3",
2024
"vision-camera-resize-plugin": "^3.1.0"

example/src/App.tsx

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1-
import { ImageExample } from './ImageExample';
2-
import { VisionCameraExample } from './VisionCameraExample';
1+
import { ImageExample } from './examples/ImageExample';
2+
import { Route, type StackParamList } from './types';
3+
import { CameraRealtimeDetection } from './examples/CameraRealtimeDetection';
4+
import { NavigationContainer } from '@react-navigation/native';
5+
import { createNativeStackNavigator } from '@react-navigation/native-stack';
6+
import { Home } from './home/Home';
7+
import { CameraPassthrough } from './examples/CameraPassthrough';
38

4-
export default function App() {
5-
const camera = false;
6-
7-
if (camera) {
8-
return <VisionCameraExample />;
9-
}
9+
const Stack = createNativeStackNavigator<StackParamList>();
1010

11-
return <ImageExample />;
11+
export default function App() {
12+
return (
13+
<NavigationContainer>
14+
<Stack.Navigator>
15+
<Stack.Screen
16+
name={Route.Home}
17+
component={Home}
18+
options={{ title: 'Examples' }}
19+
/>
20+
<Stack.Screen name={Route.ImageBlur} component={ImageExample} />
21+
<Stack.Screen
22+
name={Route.CameraPassthrough}
23+
component={CameraPassthrough}
24+
/>
25+
<Stack.Screen
26+
name={Route.CameraRealtimeDetection}
27+
component={CameraRealtimeDetection}
28+
/>
29+
</Stack.Navigator>
30+
</NavigationContainer>
31+
);
1232
}

0 commit comments

Comments
 (0)