Skip to content

fix: catch cv2.error in points2F(), not just F/mask=None - #101

Open
petercorke wants to merge 1 commit into
mainfrom
fix/points2f-cv2-error-degenerate-points
Open

fix: catch cv2.error in points2F(), not just F/mask=None#101
petercorke wants to merge 1 commit into
mainfrom
fix/points2f-cv2-error-degenerate-points

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

  • `points2F()` already handles `cv2.findFundamentalMat()` returning `(None, None)` on degenerate point configurations, converting it to a descriptive `ValueError`. But OpenCV doesn't always fail that cleanly -- on some inputs it raises a raw C++ assertion instead (`Assertion failed: 0 <= _rowRange.start && ... in function 'Mat'`), which isn't caught anywhere.
  • Catches `cv2.error` alongside the existing `None` check and re-raises as the same `ValueError`, since it's the same underlying cause (degenerate points), just surfaced differently by OpenCV.
  • Found via RVC3-python's `visodom.py` example, a temporal visual-odometry loop that already wraps `estimate(cam.points2F, ...)` in `try/except ValueError` specifically to skip degenerate frames -- the raw `cv2.error` was slipping past that except clause and crashing the whole run at frame 149 of 251.

Test plan

  • `pytest tests/ -k "points2F or Camera or camera"` -- 27 passed, 1 skipped
  • Ran RVC3-python's `visodom.py` end to end against the bridge dataset (251 frames) -- previously crashed hard at frame 149, now cleanly skips it and completes all 251 frames

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

cv2.findFundamentalMat() doesn't always fail cleanly on degenerate
point configurations -- sometimes it raises a raw C++ assertion
(a Mat rowRange error) instead of returning (None, None). Both are
the same underlying condition (points too degenerate to estimate F),
so catch cv2.error alongside the existing None-check and re-raise as
the same descriptive ValueError.

Surfaced by RVC3-python's visodom.py example, which already expects
and catches ValueError from points2F() to skip degenerate frames in
a temporal-matching loop -- the raw cv2.error was slipping past that
except clause uncaught.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@petercorke
petercorke force-pushed the fix/points2f-cv2-error-degenerate-points branch from a4b3e41 to c4197cb Compare August 17, 2026 23:35
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