Skip to content

test: raise coverage of ImageMultiview, ImageRegionFeatures and ImageLineFeatures - #220

Merged
petercorke merged 4 commits into
mainfrom
test/image-coverage-features
Nov 22, 2026
Merged

petercorke merged 4 commits into
mainfrom
test/image-coverage-features

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

First of three changes to lift coverage of the Image*.py modules. This one covers the three smallest, least-covered modules:

Module Before After
ImageMultiview.py 14% 99%
ImageRegionFeatures.py 47% 95%
ImageLineFeatures.py 55% 95%

The tests check results against known answers:

  • tests/test_image_multiview.py replaces the empty TODO stubs. The stereo pair is a random texture shifted by 8 pixels, so stereo_simple, stereo_BM and stereo_SGBM must recover a disparity of 8, and a ZNCC of 1. DSI_refine is given exact parabolas, so it must return the sub-pixel peak (3.3). rectify_homographies is given the fundamental matrix of a pure horizontal translation and must put corresponding points on one row.
  • tests/test_image_line_features_hough.py draws one horizontal and one vertical line, so lines must find (theta, rho) = (pi/2, 50) and (0, 30), lines_p must find the end points, and the accumulator peak must sit on the longest line.
  • tests/test_image_region_features_extra.py builds an MSERFeature by hand, because OpenCV 5 finds far fewer MSERs than OpenCV 4 on the same image (Issue 54). It tests indexing, printing and the OCR word filtering.

Four bugs found while writing these are recorded as strict xfail tests, not fixed here, so whoever fixes one has to remove its marker:

  1. stereo_simple returns images 2*hw larger than its inputs, though its docstring says they are the same size.
  2. stereo_simple with an integer drange raises ValueError, because the slice right_arr[:, :-0] is empty.
  3. Indexing an MSERFeature with an int, msers[0], gives an object whose len() is 2, not 1.
  4. str() of an MSERFeature with no regions raises IndexError.

Also seen, not changed: stereo_simple on a uint8 image pads with NaN, which numpy turns into 0 with a RuntimeWarning, so the border is treated as black. The tests use float32 images for that reason.

Testing

pytest tests: 1689 passed, 33 skipped, 5 xfailed. black, ruff check and mypy report no issues. Nothing is mocked except pytesseract in the tests of the OCR word filtering (the real one runs too, where tesseract is installed), and the matches object given to rectify_homographies, which is a stand-in holding point arrays. Not run: CI 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

…LineFeatures

ImageMultiview 14% to 99%, ImageRegionFeatures 47% to 95%, ImageLineFeatures
55% to 95%. The stereo tests use a synthetic pair with a known shift, the line
tests use drawn lines with known (theta, rho), and the MSER tests build the
feature object by hand because OpenCV 5 finds far fewer MSERs than OpenCV 4.

Four bugs are recorded as strict xfail tests: stereo_simple returns outputs
larger than its inputs, stereo_simple fails with an integer drange, indexing an
MSERFeature with an int gives len 2, and str() of an empty MSERFeature raises.

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 72 complexity · 0 duplication

Metric Results
Complexity 72
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 and others added 3 commits November 22, 2026 19:52
…test

OpenCV 4 finds the whole of a flat image as two regions, OpenCV 5 finds none.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@petercorke
petercorke merged commit c8bbfce into main Nov 22, 2026
32 checks passed
@petercorke
petercorke deleted the test/image-coverage-features branch November 22, 2026 10:54
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