Skip to content

fix: Fix coordinate system conversions#3918

Open
JimPatterson wants to merge 1 commit into
mrousavy:mainfrom
JimPatterson:android_conv_fix
Open

fix: Fix coordinate system conversions#3918
JimPatterson wants to merge 1 commit into
mrousavy:mainfrom
JimPatterson:android_conv_fix

Conversation

@JimPatterson
Copy link
Copy Markdown

This addresses the android side of #3871. This has been tested on a real android device using the code in #3878 and it works correctly for all orientations. But I don't have a mac or an iPhone and can't test iOS.

This was coded by an AI agent. It said:

convertFramePointToCameraPoint and convertCameraPointToFramePoint on Android were using sensorToBufferTransformMatrix directly without accounting for the frame's orientation. That matrix handles sensor crop/zoom but carries no rotation — rotation is separate metadata in rotationDegrees. As a result, passing oriented-space coordinates (as returned by ML analyzers) produced silently wrong camera coordinates for any non-upright frame.

The fix mirrors iOS's FrameCoordinateSystemConverter: before applying the inverted sensor matrix, un-rotate the input point from oriented space to raw buffer space; when converting the other direction, apply the forward rotation to the buffer-space result. The same fix is applied to HybridDepthFrame.

The two coordinate harness tests are updated to match the corrected API:

  • The round-trip test now passes the oriented-space center (h/2, w/2) for rotated frames rather than the raw buffer center (w/2, h/2), since convertFramePointToCameraPoint now expects oriented coordinates.
  • The oriented-rectangle test is redesigned as a true round-trip check (oriented → camera → oriented) instead of comparing two paths that diverge after the API change.

This was coded by an AI agent.  It said:

`convertFramePointToCameraPoint` and `convertCameraPointToFramePoint`
on Android were using `sensorToBufferTransformMatrix` directly without
accounting for the frame's orientation. That matrix handles sensor
crop/zoom but carries no rotation — rotation is separate metadata in
`rotationDegrees`. As a result, passing oriented-space coordinates
(as returned by ML analyzers) produced silently wrong camera coordinates
for any non-upright frame.

The fix mirrors iOS's `FrameCoordinateSystemConverter`: before applying
the inverted sensor matrix, un-rotate the input point from oriented space
to raw buffer space; when converting the other direction, apply the
forward rotation to the buffer-space result. The same fix is applied to
`HybridDepthFrame`.

The two coordinate harness tests are updated to match the corrected API:
- The round-trip test now passes the oriented-space center
  `(h/2, w/2)` for rotated frames rather than the raw buffer center
  `(w/2, h/2)`, since `convertFramePointToCameraPoint` now expects
  oriented coordinates.
- The oriented-rectangle test is redesigned as a true round-trip check
  (oriented → camera → oriented) instead of comparing two paths that
  diverge after the API change.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

Someone is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant