Ask Your Question

yangyangcv's profile - activity

2017-06-03 07:14:54 -0600 received badge  Famous Question (source)
2015-02-25 03:14:57 -0600 received badge  Notable Question (source)
2014-06-10 10:52:16 -0600 received badge  Student (source)
2014-05-06 10:25:22 -0600 received badge  Popular Question (source)
2013-03-30 19:30:37 -0600 commented question How to match ORB descriptors with flann LSH?

@sammy: i see that post. but the method there doesn't work for me :(

2013-03-29 07:44:48 -0600 commented question How to match ORB descriptors with flann LSH?

thanks for the quick response Steven. i just edited my post. I think the error is with flann matcher. The BFMatcher works fine for me.

2013-03-29 07:32:54 -0600 received badge  Editor (source)
2013-03-29 07:31:37 -0600 asked a question How to match ORB descriptors with flann LSH?

I want to match ORB descriptors extracted from two images with the code below:

#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"

int main(int argc, char** argv)

{
    cv::Mat img1 = cv::imread("rgb0.jpg", CV_LOAD_IMAGE_GRAYSCALE);//CV_LOAD_IMAGE_GRAYSCALE
    cv::Mat img2 = cv::imread("rgb1.jpg", CV_LOAD_IMAGE_GRAYSCALE);//CV_LOAD_IMAGE_COLOR
    if(img1.empty() || img2.empty())
    {
        std::cout<<"Can't read one of the images"<<std::endl;
        return -1;
    }

    cv::Ptr<cv::FeatureDetector> detector = cv::FeatureDetector::create("ORB");
    cv::Ptr<cv::DescriptorExtractor> descriptor = cv::DescriptorExtractor::create("ORB" );

    std::vector<cv::KeyPoint> keypoints1, keypoints2;
    detector->detect(img1, keypoints1);
    std::cout<<"find "<<keypoints1.size()<<" keypoints in img1"<<std::endl;
    detector->detect(img2, keypoints2);
    std::cout<<"find "<<keypoints2.size()<<" keypoints in img2"<<std::endl;

    cv::Mat descriptors1, descriptors2;
    descriptor->compute(img1, keypoints1, descriptors1);
    descriptor->compute(img2, keypoints2, descriptors2);

    cv::Ptr<cv::DescriptorMatcher> matcher_;
    //matcher_ = new cv::BFMatcher(cv::NORM_HAMMING);//this works correctly
    matcher_ = new cv::FlannBasedMatcher(new cv::flann::LshIndexParams(5, 24, 2));
    //matcher_ = new cv::FlannBasedMatcher();
    std::vector<cv::DMatch> matches;
    matcher_->match(descriptors1, descriptors2, matches);
    std::cout<<"Find "<<matches.size()<<" matches"<<std::endl;
    cv::namedWindow("matches", 1);
    cv::Mat img_matches;
    cv::drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
    cv::imshow("matches", img_matches);
    cv::waitKey(0);

    return 0;
}

but there is compile error saying: terminate called after throwing an instance of 'cvflann::anyimpl::bad_any_cast'. In this post i see that people say this is a bug and the fix is given. However, the fix does not work for me. In fact, the fix is a small modification about lsh_index.h, but according to my understanding, this file is not used at all. "opencv2/features2d/features2d.hpp" includes "opencv2/flann/miniflann.hpp", but i see no inclusion about lsh_index.h in that file.

btw, i'm using opencv2.4.2