Opencv:SIFT实现中的运行时错误

时间:2013-04-17 06:27:54

标签: opencv implementation sift

我是Opencv2.3的入门级程序员,可以使用互联网上提供的代码和各种有用的资源。 Stack User User:Froyo在其网站website中实施了一个代码。当我尝试执行代码时,只要我拖动并在感兴趣的区域周围绘制一个边界框,程序就会退出。运行时错误是

Unhandled exception at 0x7509c41f (KernelBase.dll) in SIFT_Track.exe: Microsoft C++ exception: cv::Exception at memory location 0x0036f144..
Bad argument: <img is empty or has an incorrect type) in unknown function , file c:\Users\vp\work\ocv\opencv\modules\features2d\src\sift.cpp line 1681
Opencv Error: Assertion failed <0< =roi.x && <roi.width && roi.x+roi.width etc...c:\Users\vp\work\ocv\opencv\modules\core\src\matrix.cpp line 303

源代码可供下载github。有人可以帮助解决错误是什么,以便程序可以运行在我的最后。我不知道似乎是什么问题!

1 个答案:

答案 0 :(得分:1)

鼠标按钮启动后是否发生错误?

您是否可以通过输出point1和point2的位置来检查是否正确选择了ROI?

std::cout << "point1" << point1 << std::endl;

在main()函数中只显示鼠标回调函数?

我目前无法测试代码。为了理解原理并使用OpenCV进行跟踪功能,我建议您从2D图像开始。请参阅Features2D + Homography to find a known object

我测试了代码。问题在于:ROI的新位置在其值大于网络摄像头的分辨率时可能会导致错误。所以我将newPoint()函数修改为低于它并且它正常工作

void newPoints(vector<double> diff, Point cen, double rad)
{
printf("rad = %lf\tcen=(%d, %d)\n",rad, cen.x, cen.y);
printf("%f %f %f %f\n",diff[0], diff[1], diff[2], diff[3]);
point1.x = cen.x - rad - diff[0] >= 0 ? cen.x - rad - diff[0]:0;
point1.x = cen.x - rad - diff[0] <= img.cols ? cen.x - rad - diff[0]:img.cols;

point1.y = cen.y - rad - diff[1] >= 0 ? cen.y - rad - diff[1]:0;
point1.y = cen.y - rad - diff[1] <= img.rows ? cen.y - rad - diff[1]:img.rows;

point2.x = cen.x + rad + diff[2] >= 0 ? cen.x + rad + diff[2]:0;
point2.x = cen.x + rad + diff[2] <= img.cols ? cen.x + rad + diff[2]:img.cols;

point2.y = cen.y + rad + diff[3] >= 0 ? cen.y + rad + diff[3]:0;
point2.y = cen.y + rad + diff[3] <= img.rows ? cen.y + rad + diff[3]:img.rows;

printf("(%d, %d), (%d, %d)\n", point1.x, point1.y, point2.x, point2.y);
}