GPU Accelerated Feature Matching
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 899
- PR merge metrics
- No merged PRs in 30d
Description
I am wondering if it's possible to carry out FLANN or BRUTEFORCE using cv2.cuda.
My research indicates it's possible but attempting to alter matching.py with the following fails:
def match_brute_force(
f1: np.ndarray,
f2: np.ndarray,
config: Dict[str, Any],
maskij: Optional[np.ndarray] = None,
) -> List[Tuple[int, int]]:
"""
Brute force matching and Lowe's ratio filtering using CUDA and Stream.
Args:
f1: feature descriptors of the first image
f2: feature descriptors of the second image
config: config parameters
maskij: optional boolean mask of len(i descriptors) x len(j descriptors)
"""
assert f1.dtype.type == f2.dtype.type
if f1.dtype.type == np.uint8:
matcher_type = "BruteForce-Hamming"
else:
matcher_type = "BruteForce"
matcher = cv2.cuda.DescriptorMatcher.createBFMatcher
matcher.add([f2])
stream = cv2.cuda_Stream()
matches = matcher.knnMatchConvert(f1, k=2, stream=stream)
stream.waitForCompletion()
ratio = config["lowes_ratio"]
good_matches = []
for match in matches:
if match and len(match) == 2:
m, n = match
if m.distance < ratio * n.distance:
good_matches.append(m)
return _convert_matches_to_vector(good_matches)
with the error:
AttributeError: module 'cv2.cuda' has no attribute 'DescriptorMatcher.createBFMatcher'
OpenCV.org: CUDA Descriptor Matcher
says that:
createBFMatcher()
[static Ptrcuda::DescriptorMatcher cv::cuda::DescriptorMatcher::createBFMatcher | (| int | normType = cv::NORM_L2 | )]
For each descriptor in the first set, this matcher finds the closest descriptor in the second set by trying each one. This descriptor matcher supports masking permissible matches of descriptor sets.Parameters
normType | One of NORM_L1, NORM_L2, NORM_HAMMING. L1 and L2 norms are preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and BRIEF).
Any ideas?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review matching.py and the linked OpenCV CUDA DescriptorMatcher documentation first. Determine whether FLANN or brute-force matching can be integrated through the available cv2.cuda API, including the shown error path and existing mask and ratio requirements. Done means a supported GPU matcher works for the requested mode and preserves the expected returned matches.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- opencv, python
- Domain
- computer-vision, performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100