Repository navigation
resolve #11855 - #12908
Merged
Merged
resolve #11855#12908
Conversation
Member
|
Please add test for this patch (code from answers doesn't expect empty entries). |
Contributor
Author
|
@alalek #include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
using namespace cv;
using namespace std;
int main()
{
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 0, 1, 1, 1);
Mat sources = (Mat_<uchar>(2, 3) << 1, 1, 1, 0,0,0);
cout << sources << "\n";
cout << targets << "\n";
cout << "SOURCES TARGETS\n";
for (int i = 0; i < sources.rows; i++)
for (int j = 0; j < targets.rows; j++)
cout << i << " -> " << j << " = " << norm(sources.row(i), targets.row(j), NORM_HAMMING) << "\n";
cout << "TARGETS SOURCES\n";
for (int i = 0; i < targets.rows; i++)
for (int j = 0; j < sources.rows; j++)
cout << i << " -> " << j << " = " << norm(targets.row(i), sources.row(j), NORM_HAMMING) << "\n";
Ptr<BFMatcher> bf = BFMatcher::create(NORM_HAMMING, true);
vector<vector<DMatch>> match;
cout << "Match with crosscheck TRUE\n";
bf->knnMatch(sources, targets, match, 1);
for (auto m : match)
if(m.size() > 0)
cout << m[0].queryIdx << " -> " << m[0].trainIdx << " = " << m[0].distance << "\n";
Ptr<BFMatcher> bf2 = BFMatcher::create(NORM_HAMMING, false);
cout << "Match with crosscheck FALSE \n";
match.clear();
bf2->knnMatch(sources, targets, match, 1);
for (auto m : match)
cout << m[0].queryIdx << " -> " << m[0].trainIdx << " = " << m[0].distance << "\n";
return 0;
}import numpy
import cv2
targets = numpy.array([[1, 1, 0], [1, 1, 1]], dtype=numpy.uint8)
sources = numpy.array([[1, 1, 1], [0, 0, 0]], dtype=numpy.uint8)
for si, source in enumerate(sources):
for ti, target in enumerate(targets):
print('%d -> %d: %d' % (si, ti, cv2.norm(source, target, cv2.NORM_HAMMING)))
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.knnMatch(sources, targets, k=1)
print('-- crosscheck=True')
for match in matches:
if match:
print('%d -> %d: %f' % (match[0].queryIdx, match[0].trainIdx, match[0].distance))
bf_nocc = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=False)
matches_nocc = bf_nocc.knnMatch(sources, targets, k=1)
print('-- crosscheck=False')
for match in matches_nocc:
if match:
print('%d -> %d: %f' % (match[0].queryIdx, match[0].trainIdx, match[0].distance)) |
Member
|
Proposed code works without this patch. Added the simple test to this patch. |
opencv-pushbot
pushed a commit
that referenced
this pull request
Nov 16, 2018
Merged
savuor
pushed a commit
to nickyu-zhu/opencv
that referenced
this pull request
Oct 27, 2023
SavyaSanchi-Sharma
pushed a commit
to SavyaSanchi-Sharma/opencv
that referenced
this pull request
Jul 30, 2026
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.
Merge with extra: opencv/opencv_extra#543
resolves #11855