feat(features2d): implement keypoint types and shared utilities#68
Open
kalwalt wants to merge 1 commit into
Open
feat(features2d): implement keypoint types and shared utilities#68kalwalt wants to merge 1 commit into
kalwalt wants to merge 1 commit into
Conversation
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.
PR Summary
feat(features2d): implement keypoint types and shared utilitiesfeatures2dfeat/issue-57-keypointstargetingfeat/m5-features2d-moduleDetailed Description
This PR implements complete and robust
KeyPointproperties, custom constructors, circle-circle overlap (IoU) math, coordinate converters, and mathematical selection/sorting utilities, directly resolving Issue #57.All mathematical kernels and conversion logic are ported from original OpenCV C++ source (
modules/core/src/types.cpp) to guarantee 100% behavioral parity:KeyPoint::overlapCircle-Circle IoU:-1.0..=1.0of cosine variables before computing.acos()to eliminate domain errors resulting from floating-point imprecision.min_radius^2 / max_radius^2.convert_to_points: Efficient conversion from&[KeyPoint]toVec<Point2f>.convert_to_points_masked: Validates indices against boundaries and negative integers, returning safeResult<Vec<Point2f>, PureCvError>.convert_from_points: Maps&[Point2f]toVec<KeyPoint>utilizing OpenCV default conventions where the orientation parameter (angle) defaults strictly to-1.0.sort_by_response: high-performanceNaN-safe sorting usingpartial_cmp().unwrap_or(Ordering::Equal)in either ascending or descending order.retain_best: Extracted topNstrongest response keypoints efficiently.Review Checklist
General
cargo fmt --checkpasses).Code Quality
serdeand other potential dependencies were avoided to keep the crate lightweight).Point2fimplementsCopyand is passed directly without redundant.clone()).Testing
src/features2d/tests.rswith 8 new robust unit tests.Risk Assessment
Test Coverage
src/features2d/keypoint.rstest_keypoint_defaulttest_keypoint_newtest_keypoint_convert_to_pointstest_keypoint_convert_to_points_maskedtest_keypoint_convert_from_pointstest_keypoint_sort_by_responsetest_keypoint_retain_besttest_keypoint_overlapVisual Aids
Circular Overlap Cases:
graph TD A[Overlap Types] --> B[No Overlap: dist >= r1 + r2] A --> C[Partial Overlap: dist < r1 + r2] A --> D[Full Enclosure: dist + min_r <= max_r] B --> B1[Returns 0.0] C --> C1[Calculates intersection area using segment/triangle math] D --> D1[Returns ratio min_r^2 / max_r^2]Size Recommendations
At only 315 lines of highly cohesive changes, this PR is at a perfect size for review. No splitting is recommended or needed.
Review Automation
cargo clippy --all-targets --all-featureswas executed and is 100% clean with zero warnings on the implemented code.cargo fmt --checksucceeds.cargo testruns and passes successfully.