Search code examples
c++opencvflann

OpenCV C++ Flann IndexParams and SearchParams error


Opencv 3.2 C++. I am creating a method that can take any set of keypoint descriptors and use any of the matching algorithms as specified by the user. When I try to build my code I get the following errors.

  1. cv::flann::IndexParams::~IndexParams(), referenced from:
  2. cv::flann::SearchParams::SearchParams(int, float, bool), referenced from:
  3. cv::flann::KDTreeIndexParams::KDTreeIndexParams(int), referenced from:
  4. clang: error: linker command failed with exit code 1 (use -v to see invocation)

UPDATE - When I run the standard Flann tutorial found on OpenCV website in sublime it executes with no errors. This leads me to believe that the issue is with Xcode but am still not 100% sure on this.

I am using xcode and am still figuring out the interface and there is no specific like stated as to cause the error. My code is as follows;`

std::tuple<std::vector< DMatch >,Mat> matchFeatures(std::vector<KeyPoint> kp1, Mat desc1, std::vector<KeyPoint> 
kp2, Mat desc2, String keypointsMatcher){
    std::vector< DMatch > matches;
    vector<vector< DMatch >> knnMatches;
    double max_dist = 0, min_dist = 100;
    Mat homography;

    if(keypointsMatcher == "bruteForce"){
        BFMatcher matcher;
        matcher.match(desc1, desc2, matches);
    }
    else if( keypointsMatcher == "flann" ){
        if(desc1.type()!=CV_32F) {
            desc1.convertTo(desc1, CV_32F);
        }
        if(desc2.type()!=CV_32F) {
            desc2.convertTo(desc1, CV_32F);
        }

        FlannBasedMatcher matcher;
        matcher.match( desc1, desc2, matches );
   }
    //-Run Knn Flann based matcher. Will create a vector of vectors (vector<vector< DMatch >>)
    else if (keypointsMatcher == "knn"){
        if(desc1.type()!=CV_32F) {
            desc1.convertTo(desc1, CV_32F);
        }
        if(desc2.type()!=CV_32F) {
            desc2.convertTo(desc1, CV_32F);
        }

        FlannBasedMatcher matcher;
        matcher.knnMatch(desc1, desc2, knnMatches, 2);
     }

    //-- Quick calculation of max and min distances between keypoints
    for( int i = 0; i < desc1.rows; i++ ){
        double dist = matches[i].distance;
        if( dist < min_dist ) min_dist = dist;
        if( dist > max_dist ) max_dist = dist;
    }


    return{matches,homography};

}`

Any help is appreciated!


Solution

  • I discovered the issue was do to the header files. In OpenCV it seems that Flann has its own framework outside of:

     #include <opencv2/features2d.hpp> 
     #include <opencv2/xfeatures2d.hpp> 
    

    To solve simply add this following header and accurately link the .hpp file.

    #include <opencv2/flann.hpp>