Opencv:SIFT实现中的运行时错误
我是一名Opencv2.3的入门级程序员,经常使用互联网上的代码和各种有用的资源。Stack用户在其网站中实现了一个代码。当我尝试执行代码时,只要我在感兴趣的区域周围拖动并绘制边界框,程序就会退出。运行时错误为Opencv:SIFT实现中的运行时错误,opencv,implementation,sift,Opencv,Implementation,Sift,我是一名Opencv2.3的入门级程序员,经常使用互联网上的代码和各种有用的资源。Stack用户在其网站中实现了一个代码。当我尝试执行代码时,只要我在感兴趣的区域周围拖动并绘制边界框,程序就会退出。运行时错误为 Unhandled exception at 0x7509c41f (KernelBase.dll) in SIFT_Track.exe: Microsoft C++ exception: cv::Exception at memory location 0x0036f144.. Bad
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
std::cout << "point1" << point1 << std::endl;
感谢您的回复。代码给出了五次迭代的point1[535189]值,然后退出,给出了错误错误参数:我测试了代码。问题是:当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);
}