繁体   English   中英

OpenCV 3.0 与 SURF 的链接错误,使用 Visual Studio 2015

[英]OpenCV 3.0 Linkage error with SURF, using visual studio 2015

我正在尝试使用 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");
}

-错误截图没有出现。

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

Opencv贡献源

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM