Skip to content

Commit c5669db

Browse files
fix: correctly transform bounding boxes
1 parent b3d71b6 commit c5669db

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ export default function ObjectDetectionTask({
8080
}
8181
try {
8282
if (!detRof) return;
83-
const orientation = frame.orientation;
84-
// "up"/"down" = landscape orientations where buffer axes are swapped vs screen
85-
const swapAxes = orientation === 'up' || orientation === 'down';
86-
const screenW = swapAxes ? frame.height : frame.width;
87-
const screenH = swapAxes ? frame.width : frame.height;
83+
// C++ always does CW rotation, so output space is always frameH × frameW
84+
const screenW = frame.height;
85+
const screenH = frame.width;
8886
const result = detRof(frame, cameraPositionSync.getDirty(), 0.5);
8987
if (result) {
9088
scheduleOnRN(updateDetections, {

packages/react-native-executorch/common/rnexecutorch/utils/FrameTransform.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ void transformBbox(float &x1, float &y1, float &x2, float &y2,
3434
x1 = nx1; y1 = ny1;
3535
x2 = nx2; y2 = ny2;
3636
} else if (orient.orientation == "left") {
37-
// CCW: new_x = y, new_y = w - x
38-
float nx1 = y1, ny1 = w - x2;
39-
float nx2 = y2, ny2 = w - x1;
37+
// CW: new_x = h - y, new_y = x
38+
float nx1 = h - y2, ny1 = x1;
39+
float nx2 = h - y1, ny2 = x2;
4040
x1 = nx1; y1 = ny1;
4141
x2 = nx2; y2 = ny2;
4242
} else {

packages/react-native-executorch/common/rnexecutorch/utils/FrameTransform.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ void transformPoints(std::array<P, 4> &points,
7171
nx = h - y;
7272
ny = x;
7373
} else if (orient.orientation == "left") {
74-
// CCW: new_x = y, new_y = w - x
75-
nx = y;
76-
ny = w - x;
74+
// CW: new_x = h - y, new_y = x
75+
nx = h - y;
76+
ny = x;
7777
} else if (orient.orientation == "right") {
7878
// CW: new_x = h - y, new_y = x
7979
nx = h - y;

0 commit comments

Comments
 (0)