【发布时间】:2014-07-22 22:17:52
【问题描述】:
我在网上和 SO 上到处搜索这个答案,但我找不到我的问题的答案,所以我把它贴在这里。
我正在尝试使用 solvePnP 函数通过获取 rvecs 和 tvecs 来查找两个图像之间的相对相机位姿。我这里是这两个图像的链接. refernce image ,query image. 我已经检测并匹配了关键点,并将它们存储在矢量 Point3f(参考图像的二维坐标+深度)和矢量 Point2f(环境中查询图像的二维坐标)中。我已经有了相机的相机内在函数和失真矩阵。这是我使用的代码sn-ps。
drawMatches(fin,keypoints_1,fin1,keypoints_2,good_matches,Img_matches,Scalar::all(-1),vector<char>(),DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
imshow("mm",img_matches);
vector<Point2f> obj;
vector<Point2f> scene;
vector<Point3f> obj1;
for( int i = 0; i <good_matches.size(); i++ )
{
obj.push_back( keypoints_1[ good_matches[i].queryIdx ].pt);
scene.push_back( keypoints_2[ good_matches[i].trainIdx ].pt );}
for( int i = 0; i < obj.size(); i++ )
{raw=depth.at<unsigned char>(int(obj[i].x),int(obj[i].y));
distan=(raw*1798)/255;//this is just to get the actual distance of a point in a depth image
obj1.push_back(Point3f(int(obj[i].x),int(obj[i].y),distan));}//transfering to a Point3f vector.
Mat H = findHomography( obj, scene, CV_RANSAC );
solvePnP(obj1,scene,intrinsics,distortion,rvec,tvec);
注意:向量 obj1 中的点比通常的 4 对多。这会产生问题吗?
我遇到的问题是运行时错误:
test.exe 中 0x75dc812f (KernelBase.dll) 处未处理的异常:Microsoft C++ 异常:内存位置 0x0015b800 处的 cv::Exception。
我从之前校准的 xml 配置文件中获得了相机矩阵
更新:我发现内在函数和失真矩阵没有正确加载。我一直在浪费时间查看对象和场景矩阵。我使用断点检查了矩阵值它们显示 0 列和行。我认为矩阵在校准期间没有正确存储,我检查了 xml 文件;但它们有数据。这是我用来将矩阵传输到程序中的一段代码。
Mat intrinsics;
Mat distortion;
FileStorage fsIntrinsic("intrinsics.xml", FileStorage::READ);
fsIntrinsic["intrinsics"] >> intrinsics;
FileStorage fsDistortion("distortion.xml", FileStorage::READ);
fsDistortion["distortion"] >> distortion;
if(!fsInrinsic.isOpened())
return -1;
if(!fsDistortion.isOpened())
return -1;
fsIntrinsic.release();
fsDistortion.release();
谁能帮帮我。我所知道的一切似乎都是正确的,在这里,在这段代码中。我应该在代码中包含其他内容以使其工作吗?
【问题讨论】:
标签: opencv image-processing runtime-error kinect