我正在尝试使用openCV2计算机视觉应用程序编程菜谱中的代码,在304中为暴力搜索器进行冲浪,但在执行代码时我不断收到此消息:
在surf matrix.exe中0x7530812f处的未处理异常:Microsoft C ++异常:内存位置0x002af6b4处的std :: bad_alloc ..“
我尝试使用谷歌搜索,但找不到答案,我已经检查了这本书的例子,但仍然找不到出错的地方。断点发生在以下声明中:matcher.match(descriptors1,descriptors2, matches);
我正在使用opencv 2.3。我已经包括了
在其他包含目录和库下:
...并将C:\OpenCV2.3\build\x86\vc9\lib
添加到其他库目录字段
以下是我的代码:
#include "cv.h"
#include "highgui.h"
int main(int argc, char* argv[]) {
std::vector<cv::KeyPoint> keypoints1, keypoints2;
cv::Mat image1=cv::imread("C:/Users/folder/44.jpg");
cv::Mat image2=cv::imread("C:/Users/folder/44.jpg");
cv::Mat featureImage=cv::imread("C:/Users/folder/44.jpg");
cvNamedWindow("MyJPG", CV_WINDOW_AUTOSIZE);
cv::imshow("MyJPG", image1);
cv::SurfFeatureDetector surf(2500);
surf.detect(image1, keypoints1);
// Draw the keypoints with scale and orientation information
cv::drawKeypoints(image1, // original image
keypoints1, // vector of keypoints
featureImage, // the resulting image
cv::Scalar(255, 255, 255), // color of the points
cv::DrawMatchesFlags::DRAW_OVER_OUTIMG); //flag
cv::imshow("Results", featureImage);
cv::imshow("MyJPG2", image2);
surf.detect(image2, keypoints2);
cv::drawKeypoints(image2, // original image keypoints2, // vector of
keypoints image2, // the resulting image
cv::Scalar(255,255,255), // color of the points
cv::DrawMatchesFlags::DRAW_OVER_OUTIMG); //flag
// Construction of the SURF descriptor extractor
cv::SurfDescriptorExtractor surfDesc1;
cv::SurfDescriptorExtractor surfDesc2; // Extraction of the SURF descriptors
cv::Mat descriptors1, descriptors2;
surfDesc1.compute(image1, keypoints1, descriptors1);
//printf("%s",surfDesc);
surfDesc2.compute(image2, keypoints2, descriptors2);
cvWaitKey(0); // Construction of the matcher
cv::BruteForceMatcher<cv::L2<float>> matcher; // Match the two image descriptors
std::vector<cv::DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
//cvReleaseImage( &image1 );
cvDestroyWindow("MyJPG");
return 0;
}