Skip to content

fix: index and print MSER features correctly - #229

Merged
petercorke merged 3 commits into
mainfrom
bug/mser-feature
Nov 22, 2026
Merged

petercorke merged 3 commits into
mainfrom
bug/mser-feature

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Two bugs in MSERFeature, in ImageRegionFeatures.py:

  1. msers[0], indexing with an int, left the region's 2 × N point array in _points, where a list of arrays belongs. So the result had len() == 2 (the number of rows of that array, not one region), and str() of it printed "MSER features, 2 regions". It now wraps the array in a list, so len(msers[0]) == 1, and its bbox, points and str() describe that one region. Slices, lists and arrays of indices were already right.
  2. str() of an MSERFeature with no regions looked up the first bounding box and raised IndexError, which can happen on OpenCV 5 (see Issue 54). It now prints "MSER features, 0 regions".

I also corrected a comment that said the point arrays are N × 2, when they are 2 × N, as the points docstring says.

Found by the new MSER tests (PR 220), which recorded both as strict xfail tests. Those two tests are now ordinary tests, and the first also checks the bbox, points and str() of the single region.

Testing

tests/test_image_region_features_extra.py and tests/test_image_region_features.py: 25 passed and 1 skipped (a real-image test that skips when OpenCV finds no MSERs). mypy reports no issues. 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

msers[0] left the region's 2xN point array in _points where a list of arrays
belongs, so len(msers[0]) was 2 and str() called it "2 regions". It now wraps
the array in a list, so the result is one region.

str() of an MSERFeature with no regions looked up the first bounding box and
raised IndexError. It now prints "MSER features, 0 regions".

Also correct a comment that said the point arrays are Nx2, when they are 2xN.

The two xfail tests that recorded the bugs are now ordinary tests.

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 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.

@petercorke
petercorke merged commit 0d4d6c8 into main Nov 22, 2026
34 checks passed
@petercorke
petercorke deleted the bug/mser-feature branch November 22, 2026 13:00
@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