Strange behaviour of cv::BFMatcher to match descriptors from custom ASIF (based on vlFeat)

asked 2015-09-18 03:10:16 -0500

Dear all, I am trying to implement my own ASIFT descriptor from the SIFT implementation of VLFEAT. The problem is when I try to perform the matching with the BFMatcher. This matcher perform the matching of all the query descriptors with the two first descriptors of the train image.

A peace of the code that I am using is the next:

    char * sourceImage ="D:/Procesing/DatasetFavorable/SanSegundo/IMG_7209.jpg";// argv[1];
char * sourceImageTrain ="D:/Procesing/DatasetFavorable/Welding/IMG_0328.JPG";// argv[1];

Mat img = cv::imread(sourceImage, CV_RGB2GRAY);
if(! img.data )
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}

std::vector< cv::KeyPoint > keys ;
std::vector< std::vector< int > > descs;
MyASiftDetector detector;

detector.computeAsift(img,keys,descs);//return 4404 tiepoints + desc for train image

//Convert std::vector< std::vector< int > > to cv::Mat
cv::Mat descMat(descs.size(), descs.at(0).size(), CV_32F);
for(int i=0; i<descMat.rows; ++i)
     for(int j=0; j<descMat.cols; ++j){
        descMat.at<int>(i, j) = descs[i][j];
     }

Mat imgTrain = cv::imread(sourceImageTrain, CV_RGB2GRAY);

if(! imgTrain.data )
{
    cout <<  "Could not open or find the image" << std::endl ;
    return -1;
}

vector< KeyPoint > keysTrain ;
vector< vector< int > > descsTrain;

detector.computeAsift(imgTrain,keysTrain,descsTrain); //return 6640 tiepoints + desc for train image

//Convert std::vector< std::vector< int > > to cv::Mat
cv::Mat descMatTrain(descsTrain.size(), descsTrain.at(0).size(), CV_32F);
for(int i=0; i<descMatTrain.rows; ++i)
     for(int j=0; j<descMatTrain.cols; ++j){
         descMatTrain.at<int>(i, j) = descsTrain[i][j];
     }

std::vector<std::vector<cv::DMatch>> matches;

cv::BFMatcher matcher(cv::NORM_L2);
//use BruteForceMatcher
matcher.knnMatch(descMat,descMatTrain,
matches,2); match all query descriptors with the two first train descriptors.

//std::vector<cv::DMatch> matchesFLANN;
//cv::FlannBasedMatcher matcher;
//matcher.match( descMat, descMatTrain, matchesFLANN);

It is really strange because, for example, the FLANN matcher works fine with the same imput.

In the next link you can find two files with the information fo the tie points and the information of the tie points and the descriptor (128 int values) in the format:

https://mega.nz/#!4pRDQZob!SO3-t3I1rq...

tiepoint info 1 descriptor tie point 1 tiepoint info 2 descriptor tie point 2 tiepoint info 3 descriptor tie point 3 ...

thanks for your help

edit retag flag offensive close merge delete

Comments

if your desc Mat is CV_32F, you must not use descMat.at<int>(i, j) = descs[i][j]; but descMat.at<float>(i, j) = descs[i][j];

also, i wonder, if std::vector< std::vector< int > > is the correct container to hold ASIFT descriptors. shouldn't they be float, too ?

berak gravatar imageberak ( 2015-09-18 03:12:25 -0500 )edit

ok... changing that it works properly. Thanks

Luisloez89 gravatar imageLuisloez89 ( 2015-09-18 06:49:46 -0500 )edit