FlannBasedMatcher correct declaration
Is there something fundamentally wrong with this code (see EDIT)
// 2 images are previously loaded in objectImg and sceneImg //
cv::Ptr<cv::BRISK> ptrBrisk = cv::BRISK::create();
ptrBrisk->detect(objectImg, objectKeypoints);
ptrBrisk->compute(objectImg,objectKeypoints,objectDescriptors);
ptrBrisk->detect(sceneImg, sceneKeypoints);
ptrBrisk->compute(sceneImg,sceneKeypoints,sceneDescriptors);
int k =2;
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( objectDescriptors, sceneDescriptors, matches );
On execution, the last line (matcher.match) fails: " Unsupported format or combination of formats (type = 0) in cv::flann:buildIndex_ "
I tried to use:
std::vector< DMatch > matches;
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("FlannBased");
matcher->match( objectDescriptors, sceneDescriptors, matches );
But it fails at execution, same error message.
EDIT : I added some code and it now works, but (look after code):
cv::Ptr<cv::BRISK> ptrBrisk = cv::BRISK::create();
ptrBrisk->detect(objectImg, objectKeypoints);
ptrBrisk->compute(objectImg,objectKeypoints,objectDescriptors);
ptrBrisk->detect(sceneImg, sceneKeypoints);
ptrBrisk->compute(sceneImg,sceneKeypoints,sceneDescriptors);
if(objectDescriptors.type() != CV_32F)
{
cv::Mat temp;
objectDescriptors.convertTo(temp, CV_32F);
objectDescriptors = temp;
}
if(sceneDescriptors.type() != CV_32F)
{
cv::Mat temp;
sceneDescriptors.convertTo(temp, CV_32F);
sceneDescriptors = temp;
}
int k =2;
std::vector< DMatch > matches;
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("FlannBased");
matcher->match( objectDescriptors, sceneDescriptors, matches );
Isn't using a float version of the descriptors defeating the purpose of using binary descriptors, aka speed? I will try test it with a BFMatcher and keep it updated here!
I´m not exactly sure about this, but I believe that the descriptors from BRISK are integer which should be compared by Hamming Distance, when FlannMatcher expects floating point descriptors which are compared with L1/L2 distance.
Hmm you got it right! That's what I was doing when you were commenting. I will try to make it work with a BFMatcher with Hamming
Maybe the attribution that you doing within the "ifs" is not really copying the data from the temporary matrix which you created, just giving the reference, and the object points to unallocated memory after the "temp" variable is released. Note that type = 0 corresponds to unsigned integer , which is the constant equivalent to CV_8U (at least, in my platform) .
And yes, Converting binary descriptors to CV_32F is kind of wasteful, since it discards the potential advantages of the binary representation.