fix(cmc): prevent cv2.resize crash on tiny downscaled images#488
Open
pranaysb wants to merge 4 commits into
Open
fix(cmc): prevent cv2.resize crash on tiny downscaled images#488pranaysb wants to merge 4 commits into
pranaysb wants to merge 4 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a robustness bug in the Camera Motion Compensation (
CMC) module where providing a very small frame or bounding box crop would cause an unhandled crash.When
img_worimg_hwas smaller than thedownscalefactor (default2), the dimension evaluated to0. Passing(0, 0)intocv2.resizetriggered an unhandled OpenCV C++ assertion error (cv2.error).This PR:
max(1, img_w // self.downscale)) across_estimate_feature_affine,_estimate_sparse_optflow, and_estimate_eccto ensure valid dimensions.try/except cv2.errorblock to cleanly catch a secondary native crash that occurs whenSIFTis asked to process an image smaller than 3x3 pixels.Related Issue(s): Fixes #487
Type of Change
Testing
Test details:
Added
test_cmc_downscale_zero_dimensionparameterized over all CMC methods (sparseOptFlow,orb,sift,ecc) to assert that feeding a1x1image to the estimator gracefully returns the identity matrix instead of crashing.uv run pytest tests/→ 855 passed, 2 skipped, 0 failures.Checklist
Additional Context
See the linked issue #487 for full tracebacks and a reproduction script demonstrating the


cv2.error.Attached is a screenshot demonstrating the fix in action on this branch. As shown, the reproduction script now executes successfully without throwing the cv2.error exception, and the newly added unit tests successfully pass for all four CMC estimation methods
After resolving this in new branch:-