2016-02-29 35 views
0

[錯誤圖像] 1我想實現使用SURF的功能匹配,但我不斷收到這個致命錯誤,所有頭文件已包括,以及庫和路徑已被定義。這裏是我的代碼和錯誤的屏幕截圖。我知道這個問題已經被多次詢問,並且人們已經回答說應該包括我已經包含的xfeaatures2d庫。OpenCV 3.0與SURF的聯繫錯誤,使用視覺工作室2015

#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"); 
} 
+0

SIFT和SURF已移至opencv_contrib回購,見下文 – berak

+0

僅供參考https://www.nuget.org/packages/opencvcontrib/ –

+0

我已經包括那些環節,我也包括鏈接圖像,可以看看。 –

回答

0

-錯誤截圖未顯示。

如果您使用的是contrib模塊,我相信您需要按照Github頁面上的說明爲自己編譯一個版本。

Opencv Contrib Source

+0

它現在可見,我已經包含鏈接。對於那個很抱歉 !! –