Skip to content

fix: stop the Hough accumulator looping forever with OpenCV 5.1 - #224

Merged
petercorke merged 1 commit into
mainfrom
bug/hough-accumulator-empty-array
Nov 22, 2026
Merged

petercorke merged 1 commit into
mainfrom
bug/hough-accumulator-empty-array

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Hough.accumulator() never returns with OpenCV 5.1. It raises the threshold until cv2.HoughLines returns None, 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() and lines_p() now treat an empty array the same as None. lines() and lines_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 with opencv-contrib-python==5.1.0.95: the released 2.4.1 code times out in accumulator(), and with this change the Hough tests pass.

Testing

tests/test_image_line_features.py gets three tests that wrap cv2.HoughLines and cv2.HoughLinesP so 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

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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · 0 duplication

Metric Results
Complexity 8
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.

@petercorke
petercorke merged commit 8e38010 into main Nov 22, 2026
34 checks passed
@petercorke
petercorke deleted the bug/hough-accumulator-empty-array branch November 22, 2026 10:33
@github-actions github-actions Bot mentioned this pull request Nov 22, 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.

1 participant