2011-11-25 287 views
0

我试图缝合一些图像来制作一种全景图。我使用的是OpenCV,因此首先要做的是检测关键点和描述符,而不是匹配它们。要做到这一点,我下面这个教程:http://opencv.itseez.com/doc/user_guide/ug_features2d.html 但是调试过程中出现了一个std ::例外相对bad_alloc的这一行:OpenCV匹配器 - std :: bad_alloc异常

matcher.match(descriptors1, descriptors2, matches); 

有人能帮助我吗?因为我剪下了&粘贴的教程,并没有编译错误。

谢谢。 摹

完整代码:


Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE); 
Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE); 
if(img1.empty() || img2.empty()) 
{ 
    printf("Can't read one of the images\n"); 
    return -1; 
} 

// detecting keypoints 
SurfFeatureDetector detector(400); 
vector<KeyPoint> keypoints1, keypoints2; 
detector.detect(img1, keypoints1); 
detector.detect(img2, keypoints2); 

// computing descriptors 
SurfDescriptorExtractor extractor; 
Mat descriptors1, descriptors2; 
extractor.compute(img1, keypoints1, descriptors1); 
extractor.compute(img2, keypoints2, descriptors2); 

// matching descriptors 
BruteForceMatcher<L2<float> > matcher; 
vector<DMatch> matches; 
matcher.match(descriptors1, descriptors2, matches); 

// drawing the results 
namedWindow("matches", 1); 
Mat img_matches; 
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches); 
imshow("matches", img_matches); 
waitKey(0); 

更新:

如果我运行此代码,我得到一个:

运行时检查失败# 2 - 围绕变量“keypoints1”堆栈已损坏。

代码:

#include "opencv\cv.h" 
    #include "opencv\highgui.h" 

    using namespace cv; 
    using namespace std; 

    int main() 
    { 
     Mat img1 = imread("Chessboard1.jpg", CV_LOAD_IMAGE_GRAYSCALE); 
     Mat img2 = imread("Chessboard3.jpg", CV_LOAD_IMAGE_GRAYSCALE); 
     if(img1.empty() || img2.empty()) 
     { 
      printf("Can't read one of the images\n"); 
      return -1; 
     } 

     FastFeatureDetector detector(50); 
     vector<KeyPoint> keypoints1; 
     detector.detect(img1, keypoints1); 

     return 0; 
    } 
+1

量不足

即。 – ScarletAmaranth

+0

那行代码提到了几个我们不知道它们是如何声明的变量。一行代码不会给你任何有用的帮助。 – karlphillip

回答

1

你需要确保下面的“附加依赖项”下的属性 - >连接器 - >输入指的是与调试器支持正确的OpenCV的库。的

C:\OpenCV2.2\lib\opencv_calib3d220d.lib 
C:\OpenCV2.2\lib\opencv_core220d.lib 
C:\OpenCV2.2\lib\opencv_features2d220d.lib 
C:\OpenCV2.2\lib\opencv_highgui220d.lib 
C:\OpenCV2.2\lib\opencv_imgproc220d.lib 

代替信息精细先生的

C:\OpenCV2.2\lib\opencv_calib3d220.lib 
C:\OpenCV2.2\lib\opencv_core220.lib 
C:\OpenCV2.2\lib\opencv_features2d220.lib 
C:\OpenCV2.2\lib\opencv_highgui220.lib 
C:\OpenCV2.2\lib\opencv_imgproc220.lib