c++ - OpenCV Matcher - std::bad_alloc 异常

标签 c++ image-processing opencv

我正在尝试将一些图像拼接在一起以制作一种全景图。我正在使用 OpenCV,所以首先要做的是检测关键点和描述符而不是匹配它们。为此,我遵循本教程:http://opencv.itseez.com/doc/user_guide/ug_features2d.html 但是在调试期间,我得到了一个与这一行相关的 std::bad_alloc 异常:

matcher.match(descriptors1, descriptors2, matches);

有人可以帮我吗?因为我剪切并粘贴了教程并且没有编译错误。

谢谢。 G

完整代码:


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);

更新:

如果我运行这段代码,我会得到:

Run-Time Check Failure #2 - Stack around the variable 'keypoints1' was corrupted.

代码:

    #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;
    }

最佳答案

您需要确保 Properties->Linker->Input 下的以下“附加依赖项”指的是具有调试器支持的正确 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

关于c++ - OpenCV Matcher - std::bad_alloc 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8270231/

相关文章:

image-processing - 如何将 DynamicImage 转换为 Base64?

c - 让 opencv 工作(段错误)

c++ - 按引用和按值传递时的 gcc 程序集

c++ - 制作通用链表将下一个指针放在结构的开头

javascript - 是否可以增加 WordPress 的最大上传大小?

c++ - 自动分离已相乘的两个图像

c++ - 带 mask 的 OpenCV 和 cvAvgSdv (roi)

opencv - 与 OpenCV 3.0 链接时出现“未解析的外部符号”错误

c++ - 模板类成员函数的显式特化

c++ - 找不到 -lSDL 的库