Opencv:运行时错误在SIFT实现



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

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:Usersvpworkocvopencvmodulesfeatures2dsrcsift.cpp line 1681
Opencv Error: Assertion failed <0< =roi.x && <roi.width && roi.x+roi.width etc...c:Usersvpworkocvopencvmodulescoresrcmatrix.cpp line 303

源代码可在github下载。有人可以帮助解决什么是错误,使程序可以运行在我的结束。我不知道是什么问题!

鼠标按上后出现错误吗?

你能通过输出点1和点2的位置来检查ROI是否被正确选择吗?

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

下面的鼠标回调函数在main()函数?

我现在无法测试代码。为了理解原理和使用OpenCV跟踪功能,我建议您从2D图像开始。请参考Features2D + Homography查找已知对象

我测试了代码。这里有一个问题:当ROI的新位置的值大于您的网络摄像头的分辨率时,可能会导致错误。因此,我修改newPoint()函数如下所示,它可以正常工作

void newPoints(vector<double> diff, Point cen, double rad)
{
printf("rad = %lftcen=(%d, %d)n",rad, cen.x, cen.y);
printf("%f %f %f %fn",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);
}

最新更新