Skip to content

Commit 7488857

Browse files
fix: rotation issue
1 parent 5b7b6bb commit 7488857

File tree

2 files changed

+11
-1
lines changed
  • apps/computer-vision/app/vision_camera
  • packages/react-native-executorch/common/rnexecutorch/models

2 files changed

+11
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ export default function VisionCameraScreen() {
377377
outputs={[frameOutput]}
378378
isActive={true}
379379
format={format}
380+
orientationSource="interface"
380381
/>
381382

382383
<View

packages/react-native-executorch/common/rnexecutorch/models/VisionModel.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,16 @@ using namespace facebook;
1111
cv::Mat VisionModel::extractFromFrame(jsi::Runtime &runtime,
1212
const jsi::Value &frameData) const {
1313
auto frameObj = frameData.asObject(runtime);
14-
return ::rnexecutorch::utils::extractFrame(runtime, frameObj);
14+
cv::Mat frame = ::rnexecutorch::utils::extractFrame(runtime, frameObj);
15+
16+
// Camera sensors natively deliver frames in landscape orientation.
17+
// Rotate 90° CW so all models receive upright portrait frames.
18+
if (frame.cols > frame.rows) {
19+
cv::Mat upright;
20+
cv::rotate(frame, upright, cv::ROTATE_90_CLOCKWISE);
21+
return upright;
22+
}
23+
return frame;
1524
}
1625

1726
cv::Mat VisionModel::extractFromPixels(const JSTensorViewIn &tensorView) const {

0 commit comments

Comments
 (0)