Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

BFMatcher crosscheck

Hey guys,

Ive got a problem with the crosscheck feature in the BFMatcher. Im trying to use this on android, but somehow the matcher seems to do crap. It produces lots of good results, but sometimes it returns queryIdx' and trainIdx' that are far away from the number of Matches. Basically I declare the matcher to use crosscheck and I also use knnMatch with k=1. After they got matched, I log the indices. Lots of them are correct, but not all.

BFMatcher matcher(NORM_HAMMING,true);
matcher.knnMatch(queryDescriptors, trainDescriptors, matches, 1);

for (unsigned int i=0; i<matches.size(); i++){

        LOGE("query Idx:%d, trainIdx:%d", matches[i][0].queryIdx, matches[i][0].trainIdx);

           /* circle(*frame,queryPoints[matches[i][0].queryIdx].pt, 1, Scalar(255,255,0,255));
            line(*frame,queryPoints[matches[i][0].queryIdx].pt, trainPoints[matches[i][0].trainIdx].pt, Scalar(255,255,255,255));
            circle(*frame,trainPoints[matches[i][0].trainIdx].pt, 1, Scalar(255,0,0,255));*/
    }

BFMatcher crosscheck

Hey guys,

Ive got a problem with the crosscheck feature in the BFMatcher. Im trying to use this on android, but somehow the matcher seems to do crap. It produces lots of good results, but sometimes it returns queryIdx' and trainIdx' that are far away from the number of Matches. Basically I declare the matcher to use crosscheck and I also use knnMatch with k=1. After they got matched, I log the indices. Lots of them are correct, but not all.

BFMatcher matcher(NORM_HAMMING,true);
matcher.knnMatch(queryDescriptors, trainDescriptors, matches, 1);

for (unsigned int i=0; i<matches.size(); i++){

        LOGE("query Idx:%d, trainIdx:%d", matches[i][0].queryIdx, matches[i][0].trainIdx);

           /* circle(*frame,queryPoints[matches[i][0].queryIdx].pt, 1, Scalar(255,255,0,255));
            line(*frame,queryPoints[matches[i][0].queryIdx].pt, trainPoints[matches[i][0].trainIdx].pt, Scalar(255,255,255,255));
            circle(*frame,trainPoints[matches[i][0].trainIdx].pt, 1, Scalar(255,0,0,255));*/
    }

edit:

Ok, I solved it on my own. I debugged the code on android and in the end its pretty obvious. The problem is that the matcher creates an entry in std::vector<std::vector<dmatch>> matches, but if the match is invalid, it does not fill this entry. So obviously this entry is empty and if you access it, there is crap in it. So a simple check if that entry is empty solves everything.

for (unsigned int i=0; i<matches.size(); i++){="" if="" (!matches[i].empty())="" loge("query="" idx:%d,="" trainidx:%d",="" matches[i][0].queryidx,="" matches[i][0].trainidx);<="" p="">

}

BFMatcher crosscheck

Hey guys,

Ive got a problem with the crosscheck feature in the BFMatcher. Im trying to use this on android, but somehow the matcher seems to do crap. It produces lots of good results, but sometimes it returns queryIdx' and trainIdx' that are far away from the number of Matches. Basically I declare the matcher to use crosscheck and I also use knnMatch with k=1. After they got matched, I log the indices. Lots of them are correct, but not all.

BFMatcher matcher(NORM_HAMMING,true);
matcher.knnMatch(queryDescriptors, trainDescriptors, matches, 1);

for (unsigned int i=0; i<matches.size(); i++){

        LOGE("query Idx:%d, trainIdx:%d", matches[i][0].queryIdx, matches[i][0].trainIdx);

           /* circle(*frame,queryPoints[matches[i][0].queryIdx].pt, 1, Scalar(255,255,0,255));
            line(*frame,queryPoints[matches[i][0].queryIdx].pt, trainPoints[matches[i][0].trainIdx].pt, Scalar(255,255,255,255));
            circle(*frame,trainPoints[matches[i][0].trainIdx].pt, 1, Scalar(255,0,0,255));*/
    }

edit:

Ok, I solved it on my own. I debugged the code on android and in the end its pretty obvious. The problem is that the matcher creates an entry in std::vector<std::vector<dmatch>> matches, but if the match is invalid, it does not fill this entry. So obviously this entry is empty and if you access it, there is crap in it. So a simple check if that entry is empty solves everything.

for (unsigned int i=0; i<matches.size(); i++){="" if="" (!matches[i].empty())="" loge("query="" idx:%d,="" trainidx:%d",="" matches[i][0].queryidx,="" matches[i][0].trainidx);<="" p="">

i++){
        if (!matches[i].empty())
        LOGE("query Idx:%d, trainIdx:%d", matches[i][0].queryIdx, matches[i][0].trainIdx);

}