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;
}
量不足
即。 – ScarletAmaranth
那行代碼提到了幾個我們不知道它們是如何聲明的變量。一行代碼不會給你任何有用的幫助。 – karlphillip