Skip to content

Accept single-point arrays in HomographyTransformation. - #339

Closed
cpruijsen wants to merge 1 commit into
tryolabs:masterfrom
cpruijsen:fix/issue-316
Closed

cpruijsen wants to merge 1 commit into
tryolabs:masterfrom
cpruijsen:fix/issue-316

Conversation

@cpruijsen

Copy link
Copy Markdown

HomographyTransformation.rel_to_abs / abs_to_rel accept a 1D point of shape (2,), reshape it to (1, 2) for the existing matrix multiply and w=0 guard, and return (2,), so the two CoordinatesTransformation implementations agree. (n_points, 2) behaviour is unchanged.

Fixes #316.

HomographyTransformation.rel_to_abs / abs_to_rel previously only accepted (n_points, 2). A single point of shape (2,), which FixedCamera.adjust_frame passes as the paste origin and which TranslationTransformation already accepted, raised:

ValueError: all the input arrays must have same number of dimensions...

That is the default MotionEstimator() path in the docs example on the issue. Reporter @Dentikka reproduced on Norfair 2.2.0 / Python 3.11; the same hstack failure reproduces on current master with FixedCamera + identity homography and with live MotionEstimator().

What I chose and the alternative

Translation already accepted (2,). The ABC should be interchangeable, and the crashing caller is the default homography estimator. Returning (1, 2) from Homography without also squeezing in FixedCamera would make the existing [::-1] a no-op (it would reverse the point axis of size 1, not x/y).

Alternative: only reshape the corner to (1, 2) in FixedCamera.adjust_frame.

Can switch to the caller-only reshape if Homography stays strictly (n, 2).

FixedCamera still only pastes a rectangle (no perspective warp). That limitation is unchanged and already documented.

Test plan

  • pytest tests/test_camera_motion.py tests/test_drawing.py: 1D vs 2D homography equivalence, multi-point regression, FixedCamera + identity homography, FixedCamera + translation
  • Tests fail with the source change reverted (same ValueError as FixedCamera crashes with an inappropriate point array shape #316) and pass with it restored
  • pytest tests/: 30 passed
  • Optional: run demos/camera_motion with --fixed-camera-scale and default homography; confirm it no longer crashes (frame is still pasted as a rectangle)

FixedCamera and other callers pass a (2,) corner into rel_to_abs; TranslationTransformation already handled that shape via broadcasting, but HomographyTransformation only accepted (n_points, 2) and crashed.
@cpruijsen

Copy link
Copy Markdown
Author

Closing this one so it does not sit in the queue.

@cpruijsen cpruijsen closed this Oct 1, 2026
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.

FixedCamera crashes with an inappropriate point array shape

1 participant