Skip to content

feat(features2d): implement BFMatcher, DMatch and drawing utilities (#75)#77

Merged
kalwalt merged 2 commits into
feat/feature-matching-infrastructurefrom
feat/feature-matching-infrastructure-75-bfmatcher
Jun 17, 2026
Merged

feat(features2d): implement BFMatcher, DMatch and drawing utilities (#75)#77
kalwalt merged 2 commits into
feat/feature-matching-infrastructurefrom
feat/feature-matching-infrastructure-75-bfmatcher

Conversation

@kalwalt

@kalwalt kalwalt commented Jun 11, 2026

Copy link
Copy Markdown
Member

PR Summary

Detailed Description

This PR implements the core brute-force descriptor matching and visual correspondence drawing infrastructure for purecv in the new modules:

  1. src/features2d/matcher.rs:
    • DMatch structure for match representation matching OpenCV fields (query_idx, train_idx, train_img_idx, distance).
    • DescriptorMatcher<T> trait to define standard matcher behavior.
    • BFMatcher<T> supporting NormHamming (binary like ORB) and NormL2 (float).
    • Support for cross-check mutual consistency matching.
    • Support for parallel matching using rayon under the parallel feature gate.
    • filter_matches helper implementing Lowe's ratio test.
  2. src/features2d/draw.rs:
    • draw_keypoints and draw_matches functions written in pure Rust (100% WebAssembly compatible, no external graphics dependencies).
    • Integer-only Bresenham's line and Midpoint circle drawing algorithms.
    • Support for pseudo-random line/circle colors and optional hiding of unmatched keypoints.
  3. examples/match_features.rs:
    • An example loading, splitting, and matching ORB features on the stitched graf.png image.
    • Saves the visual output showing multi-colored match lines over a grayscale background.

Review Checklist

  • Code follows project style guidelines.
  • LGPL license headers are present on all new .rs files.
  • All functions are generic, safe, and return Result<T, PureCvError>.
  • No unsafe blocks are introduced.
  • Rayon parallelism is feature-gated under #[cfg(feature = "parallel")].
  • Standard formatting (cargo fmt) and linting (cargo clippy) pass with zero warnings.

Risk Assessment

  • Risk Level: Low.
  • Size: Moderate (~1000 LOC, including extensive test coverage and visual example).
  • Impact: Adds isolated new matching modules without touching existing core/imgproc logic.
  • Mitigation: All new code has 100% unit test coverage.

Test Coverage

  • Coverage: Implemented comprehensive tests in src/features2d/tests.rs for:
    • Hamming & L2 metrics validation.
    • KNN matching and Lowe's ratio filtering.
    • Cross-check mutual matching.
    • Coordinate clipping and primitive circle/line drawing boundaries.
  • Status: 318/318 tests successfully passing.

Visual Aids

Here is the output from cargo run --example match_features:

graf_matches

Review Automation

  • All pre-commit check scripts (formatting, clippy, unit tests) completed successfully.

@kalwalt kalwalt changed the base branch from dev to feat/feature-matching-infrastructure June 11, 2026 19:12
@kalwalt kalwalt self-assigned this Jun 11, 2026
@kalwalt kalwalt added enhancement New feature or request rust-code rust Pull requests that update rust code tests features2D-module labels Jun 11, 2026
@kalwalt kalwalt linked an issue Jun 15, 2026 that may be closed by this pull request
@kalwalt kalwalt merged commit 6855276 into feat/feature-matching-infrastructure Jun 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request features2D-module rust Pull requests that update rust code rust-code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement BFMatcher and DMatch for feature correspondence

1 participant