gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:47:30 25 4
gpt4 key购买 nike

我是 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 .有人可以帮助解决错误,以便程序可以在我这边运行。我不知道问题出在哪里!

最佳答案

错误是否发生在鼠标按钮松开之后?

能否仅通过输出point1和point2的位置来检查ROI是否选择正确?

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

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

我目前无法测试代码。为了理解原理和使用OpenCV进行跟踪特征,我建议你从二维图像开始。请引用Features2D + Homography to find a known object

我测试了代码。问题在于:当 ROI 的值大于网络摄像头的分辨率时,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);
}

关于Opencv:SIFT 实现中的运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16053056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com