Ask Your Question
1

@file SURF_FlannMatcher and OpenCV 3.0.0 do not link

asked 2016-01-18 10:34:47 -0600

ForestMan gravatar image

Hi I am relatively new to OpenCV. I program C++ in Vis Studio 2013 and use Cuda 6.5. I found FlannMatcher algorithm as presented on OpenCV as a good tool for parts of what I need to do. It took me 3 days to find out how to correct the program found on opencv.org so I could compile it under 3.0.0. Thanks to all of you who contribute with good answers to many peoples questions. Why isn't this good example updated? Now I can compile it, but the linker do not work. One 'specialist' advised to recompile opencv using the additions from opencv_contrib-master. I started this process going through the tutorial on opencv.org. I have come to the part where I shall install Numpy under Python. According to opencv.org I will need this to be able to read the documentation. It crashes all the time and I receive many different error messages that I find many others do as well.

Is there a simpler way to recompile opencv so the new Flannmatcher can link? or do anyone have the binaries needed so I do not need to recompile myself? I would appreciate all the help I can get here!

The changes in the program is that extractor and detector have become pointers and minHessian is double.

Ptr<SURF> detector = SURF::create(minHessian);
    std::vector<KeyPoint> keypts;
    Mat desc;
    //detector->detectAndCompute(img_1, noArray(), keypts, desc);

    std::vector<KeyPoint> keypoints_1, keypoints_2;
    detector->detectAndCompute(img_1, noArray(), keypoints_1, desc);
    detector->detectAndCompute(img_2, noArray(), keypoints_2, desc);

//SurfDescriptorExtractor extractor;
Ptr<SurfFeatureDetector>  extractor = SurfFeatureDetector::create(minHessian);
Mat descriptors_1, descriptors_2;
extractor->compute(img_1, keypoints_1, descriptors_1);
extractor->compute(img_2, keypoints_2, descriptors_2);

Listing of the new code

 // ConsoleApplication1.cpp : Defines the entry point for the console application.
//

/**
* @file SURF_FlannMatcher
* @brief SURF detector + descriptor + FLANN Matcher
* @author A. Huaman
*/
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning (disable : 4996)
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <stdio.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/features2d.hpp"
//#include "D:\OpenCV\sources\modules\features2d\include\opencv2/features2d.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "D:\OpenCV\opencv_contrib-master\modules\xfeatures2d\include\opencv2/xfeatures2d.hpp"
#include "D:\OpenCV\opencv_contrib-master\modules\xfeatures2d\include\opencv2\xfeatures2d\nonfree.hpp"

using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;

void readme();

/* * @function main * @brief Main function */ int main(int argc, char* argv) { if (argc != 3) { readme(); return -1; }

Mat img_1 = imread(argv[1], IMREAD_GRAYSCALE);
Mat img_2 = imread(argv[2], IMREAD_GRAYSCALE);

if (!img_1.data || !img_2.data)
{
    std::cout << " --(!) Error reading images " << std::endl; return -1;
}

using namespace cv::xfeatures2d;

//Ptr<SIFT> sift = SIFT::create(...);
//-- Step 1: Detect the keypoints using SURF Detector
//int minHessian = 400;
double minHessian = 400.0;

//SurfFeatureDetector detector(minHessian);
//Ptr<SurfFeatureDetector> detector = SurfFeatureDetector::create(minHessian, 4, 3, 0, 0);

Ptr<SURF> detector = SURF::create(minHessian);
std::vector<KeyPoint> keypts;
Mat desc;
//detector->detectAndCompute(img_1, noArray(), keypts, desc);

std::vector<KeyPoint> keypoints_1, keypoints_2;
detector->detectAndCompute(img_1, noArray(), keypoints_1, desc);
detector->detectAndCompute(img_2, noArray(), keypoints_2, desc);


//detector->detect ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-01-25 08:13:57 -0600

dpwicaksa gravatar image

I've also experiencing problem when i used ORB with FlannBasedMatcher on OpenCV3, the problem is, Mat type used in Flann. Maybe you can try add this before declaring your FlannBasedMatcher

if(descriptor.type()!=CV_32F)
descriptor.convertTo(descriptor, CV_32F);

it solved my problem

edit flag offensive delete link more

Comments

For binary descriptors like ORB, you have to use FLANN and LSH index. Converting to float number should produce some distance errors.

Some links:

Eduardo gravatar imageEduardo ( 2016-01-25 09:42:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-18 10:34:47 -0600

Seen: 395 times

Last updated: Jan 25 '16