Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Opencv:SIFT实现中的运行时错误_Opencv_Implementation_Sift - Fatal编程技术网

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

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

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

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
源代码可供下载。谁能帮我解决一下错误,这样程序就可以在我这边运行了。我不知道是什么问题

该错误是否发生在按下鼠标按钮之后

您是否可以通过仅输出点1和点2的位置来检查ROI是否被正确选择

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