【问题标题】:OpenCV 3.0 Linkage error with SURF, using visual studio 2015OpenCV 3.0 与 SURF 的链接错误,使用 Visual Studio 2015
【发布时间】:2016-02-29 17:49:37
【问题描述】:

我正在尝试使用 SURF 实现特征匹配,但我不断收到这个致命错误,所有头文件都已包含,以及库和路径已定义。这是我的代码以及错误的屏幕截图。我知道这个问题已经被问过很多次,人们已经回答说应该包含我已经包含的 xfeaatures2d 库。

#include "opencv2\opencv_modules.hpp"
#include <stdio.h>
#include "opencv2\core\core.hpp"
#include"opencv2\highgui\include\opencv2\highgui\highgui.hpp"
#include"opencv2\imgcodecs.hpp"
#include "opencv2\features2d\features2d.hpp"
#include "opencv2\highgui.hpp"
#include "opencv2\xfeatures2d\include\opencv2\xfeatures2d\nonfree.hpp"
#include "opencv2\xfeatures2d\include\opencv2\xfeatures2d.hpp"
#include "opencv2\videoio.hpp"
#include "opencv2\nonfree.hpp"
#include "opencv2\xfeatures2d.hpp"
using namespace cv;

void readme();

int main(int argc, char** argv)
{

if (argc != 3)
{
    readme(); return -1;
}
Mat img_1,img_2;
img_1 = imread("DSC_0112.jpg", IMREAD_GRAYSCALE);
img_2 = imread("DSC_0112.jpg", IMREAD_GRAYSCALE);

if (!img_1.data || !img_2.data)
{
    printf(" --(!) Error reading images \n"); return -1;
}

//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
Ptr<xfeatures2d::SURF> surf = xfeatures2d::SURF::create(minHessian);
std::vector<KeyPoint> keypoints_1,keypoints_2;

surf->detect(img_1, keypoints_1);
surf->detect(img_2, keypoints_2);

//-- Step 2: Calculate descriptors (feature vectors)

Mat descriptors_1, descriptors_2;

surf->compute(img_1, keypoints_1, descriptors_1);
surf->compute(img_2, keypoints_2, descriptors_2);

//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match(descriptors_1, descriptors_2, matches);

double max_dist = 0; double min_dist = 100;

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

printf("-- Max dist : %f \n", max_dist);
printf("-- Min dist : %f \n", min_dist);

//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist,
//-- or a small arbitary value ( 0.02 ) in the event that min_dist is very
//-- small)
//-- PS.- radiusMatch can also be used here.
std::vector<DMatch> good_matches;

for (int i = 0; i < descriptors_1.rows; i++)
{
    if (matches[i].distance <= max(2 * min_dist, 0.02))
    {
        good_matches.push_back(matches[i]);
    }
}

//-- Draw only "good" matches
Mat img_matches;
drawMatches(img_1, keypoints_1, img_2, keypoints_2,good_matches,         img_matches, Scalar::all(-1), Scalar::all(-1), 
    std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS);

//-- Show detected matches
imshow("Good Matches", img_matches);

for (int i = 0; i < (int)good_matches.size(); i++)
{
    printf("-- Good Match [%d] Keypoint 1: %d  -- Keypoint 2: %d  \n", i,    good_matches[i].queryIdx, good_matches[i].trainIdx);
}

waitKey(0);

return 0;
}


void readme()
{
   printf(" Usage: ./SURF_FlannMatcher <img1> <img2>\n");
}

【问题讨论】:

  • SIFT 和 SURF 已移至 opencv_contrib repo,请参见下面的链接
  • 我已经包含了这些,我还包含了图片的链接,可以看看。
  • "unresolved externals" - 意思是,你忘了链接 lib,opencv_xfeatures2d310.lib
  • 不是所有的库都包含在 opencv_world310d 中吗?

标签: c++ opencv surf


【解决方案1】:

-错误截图没有出现。

如果您使用 contrib 模块,我认为您需要按照 Github 页面上的说明为自己编译构建。

Opencv Contrib Source

【讨论】:

  • 它现在可见,我已经包含了链接。对不起!!
猜你喜欢
  • 1970-01-01
  • 2015-07-15
  • 2016-03-21
  • 1970-01-01
  • 2013-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-27
相关资源
最近更新 更多