Skip to content

Commit 390d38c

Browse files
feat: handle most common cases
1 parent b0457c8 commit 390d38c

File tree

21 files changed

+1563
-23
lines changed

21 files changed

+1563
-23
lines changed

apps/computer-vision/app/vision_camera/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default function VisionCameraScreen() {
181181
outputs={frameOutput ? [frameOutput] : []}
182182
isActive={isFocused}
183183
format={format}
184-
orientationSource="device"
184+
orientationSource="interface"
185185
/>
186186

187187
{/* Layout sentinel — measures the full-screen area for bbox/canvas sizing */}

apps/computer-vision/components/vision_camera/tasks/ObjectDetectionTask.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
2-
import { StyleSheet, Text, View } from 'react-native';
2+
import { Platform, StyleSheet, Text, View } from 'react-native';
33
import { Frame, useFrameOutput } from 'react-native-vision-camera';
44
import { scheduleOnRN } from 'react-native-worklets';
55
import {
@@ -79,14 +79,16 @@ export default function ObjectDetectionTask({
7979
}
8080
try {
8181
if (!detRof) return;
82-
const iw = frame.width;
83-
const ih = frame.height;
82+
const orientation = frame.orientation;
83+
const swapAxes = orientation === 'left' || orientation === 'right';
84+
const screenW = swapAxes ? frame.height : frame.width;
85+
const screenH = swapAxes ? frame.width : frame.height;
8486
const result = detRof(frame, 0.5);
8587
if (result) {
8688
scheduleOnRN(updateDetections, {
8789
results: result,
88-
imageWidth: iw,
89-
imageHeight: ih,
90+
imageWidth: screenW,
91+
imageHeight: screenH,
9092
});
9193
}
9294
} catch {
@@ -114,7 +116,10 @@ export default function ObjectDetectionTask({
114116
<View
115117
style={[
116118
StyleSheet.absoluteFill,
117-
cameraPosition === 'front' && { transform: [{ scaleX: -1 }] },
119+
// TODO: remove when VisionCamera fixes front camera orientation reporting on iOS
120+
// https://github.com/mrousavy/react-native-vision-camera/issues/124
121+
Platform.OS === 'ios' &&
122+
cameraPosition === 'front' && { transform: [{ scaleX: -1 }] },
118123
]}
119124
pointerEvents="none"
120125
>
@@ -141,7 +146,8 @@ export default function ObjectDetectionTask({
141146
style={[
142147
styles.bboxLabel,
143148
{ backgroundColor: labelColorBg(det.label) },
144-
cameraPosition === 'front' && { transform: [{ scaleX: -1 }] },
149+
Platform.OS === 'ios' &&
150+
cameraPosition === 'front' && { transform: [{ scaleX: -1 }] },
145151
]}
146152
>
147153
<Text style={styles.bboxLabelText}>

apps/computer-vision/components/vision_camera/tasks/SegmentationTask.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useCallback, useEffect, useRef, useState } from 'react';
2-
import { StyleSheet, View } from 'react-native';
2+
import { Platform, StyleSheet, View } from 'react-native';
33
import { Frame, useFrameOutput } from 'react-native-vision-camera';
44
import { scheduleOnRN } from 'react-native-worklets';
55
import {
@@ -138,7 +138,6 @@ export default function SegmentationTask({
138138

139139
const frameOutput = useFrameOutput({
140140
pixelFormat: 'rgb',
141-
enablePhysicalBufferRotation: true,
142141
dropFramesWhileBusy: true,
143142
onFrame: useCallback(
144143
(frame: Frame) => {
@@ -194,7 +193,10 @@ export default function SegmentationTask({
194193
<View
195194
style={[
196195
StyleSheet.absoluteFill,
197-
cameraPosition === 'front' && { transform: [{ scaleX: -1 }] },
196+
// TODO: remove when VisionCamera fixes front camera orientation reporting on iOS
197+
// https://github.com/mrousavy/react-native-vision-camera/issues/124
198+
Platform.OS === 'ios' &&
199+
cameraPosition === 'front' && { transform: [{ scaleX: -1 }] },
198200
]}
199201
pointerEvents="none"
200202
>

apps/computer-vision/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"react-native-screens": "~4.16.0",
3939
"react-native-svg": "15.15.3",
4040
"react-native-svg-transformer": "^1.5.3",
41-
"react-native-vision-camera": "5.0.0-beta.7",
41+
"react-native-vision-camera": "5.0.0-beta.6",
4242
"react-native-worklets": "0.7.4"
4343
},
4444
"devDependencies": {

0 commit comments

Comments
 (0)