Repository navigation
fix: stop the Hough accumulator looping forever with OpenCV 5.1 - #224
Merged
Merged
Conversation
OpenCV 4 and 5.0 return None from cv2.HoughLines when it finds no lines, and accumulator() relied on that to stop raising the threshold. OpenCV 5.1 returns an empty array, so the loop never ended. lines() and lines_p() now treat an empty array like None as well. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 8 |
| Duplication | 0 |
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.
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.
Summary
Hough.accumulator()never returns with OpenCV 5.1. It raises the threshold untilcv2.HoughLinesreturnsNone, which OpenCV 4 and 5.0 do when no lines are found. OpenCV 5.1 returns an empty array instead, so the loop runs forever.accumulator(),lines()andlines_p()now treat an empty array the same asNone.lines()andlines_p()already returned the right empty shape by accident; they are changed so all three read the same way.I found it because a new test of
accumulator()(PR 220) timed out on every OpenCV 5 job. I confirmed it in a throwaway virtual environment withopencv-contrib-python==5.1.0.95: the released 2.4.1 code times out inaccumulator(), and with this change the Hough tests pass.Testing
tests/test_image_line_features.pygets three tests that wrapcv2.HoughLinesandcv2.HoughLinesPso that "no lines" is an empty array, as in OpenCV 5.1; the accumulator test fails with "the loop did not terminate" without the fix, instead of hanging.pytest tests/test_image_line_features.py: 9 passed. The Hough tests of PR 220 (27 tests in all) also pass against real OpenCV 5.1 with this change. Not run: the whole suite on Windows or OpenCV 4 (CI will).This change was written with AI assistance (Claude Code) and the diff has been read by the maintainer.
🤖 Generated with Claude Code