簡體   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