0

在 Visual Studio 2010 中运行时,下面的代码给了我以下错误:Run-Time Check Failure #2 - Stack around the variable 'keypoints' was corrupted.

#include<iostream>
#include<fstream>
#include<cv.h>
#include<highgui.h>
#include<opencv2/nonfree/features2d.hpp>
using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
    Mat image = imread("C:/IMAGE.JPG");

    SiftFeatureDetector detector;
    vector<KeyPoint> keypoints;

    detector.detect(image, keypoints);

    return 0;
}

知道我做错了什么吗?

4

2 回答 2

1

这段代码:

Mat image = imread("C:/IMAGE.JPG");

可能会失败。image在将其作为参数传递给其他函数之前,您需要确保已成功加载:

if (!image.data )
{
    cout <<  "Could not load image" << endl ;
    return -1;
}

如果imread()失败并且该文件存在于该位置,您可能需要使用另一个斜杠并将其转义:

Mat image = imread("C:\\IMAGE.JPG");

如果图像加载成功并且崩溃仍然存在,请尝试将图像加载为灰度:

Mat image = imread("C:\\IMAGE.JPG", 0);
于 2012-09-14T04:04:26.467 回答
0

原来我需要OpenCV使用 Visual Studio 2010 编译库,而不仅仅是链接到预编译dll的 s 等。现在一切都很好。

于 2012-10-05T09:03:49.803 回答