我一直在尝试从在线资源中进行SIFT / SURF,并想自己进行测试。
我首先尝试使用以下代码在没有非自由库的情况下:
int _tmain(int argc, _TCHAR* argv[])
{
Mat img = imread("c:\\car.jpg", 0);
Ptr<FeatureDetector> feature_detector = FeatureDetector::create("SIFT");
vector<KeyPoint> keypoints;
feature_detector->detect(img, keypoints);
Mat output;
drawKeypoints(img, keypoints, output, Scalar(255, 0, 0));
namedWindow("meh", CV_WINDOW_AUTOSIZE);
imshow("meh", output);
waitKey(0);
return 0;
feature_detector->detect(img, keypoints);
处中断int main(int argc, char** argv)
{
const Mat input = cv::imread("/tmp/image.jpg", 0); //Load as grayscale
SiftFeatureDetector detector;
vector<KeyPoint> keypoints;
detector.detect(input, keypoints);
// Add results to image and save.
Mat output;
drawKeypoints(input, keypoints, output);
imwrite("/tmp/SIFT_RESULT.jpg", output);
return 0;
}
detector.detect(input, keypoints);
Unhandled exception at 0x007f0900 in SIFT.exe: 0xC0000005: Access violation reading location 0x00000000.
My setup: Microsoft Visual C++ 2010, OpenCV 2.4.2, Windows XP. All libraries added and linked
最佳答案
使用彩色图像而不是灰度图像,它对我有用。
如果彩色图像也不起作用,也可以尝试跳过“const”。
const Mat input = cv::imread("/tmp/image.jpg");
https://stackoverflow.com/questions/13162074/