首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从triangulatePoints()获得良好的openCV坐标

如何从triangulatePoints()获得良好的openCV坐标
EN

Stack Overflow用户
提问于 2014-06-09 21:15:17
回答 1查看 3.6K关注 0票数 2

所以我有一个点,x:1168 So,y:1140 So,x:1062 So,y:1167 So。我的程序的真正坐标是: 120.91,4.94059,-175.609 (x,y和z,mm)。X和Y似乎是正确的,但不是Z,这点离我的相机大约1米远。

现在我有个代码:

代码语言:javascript
复制
FileStorage fsI("intrinsics.yml", FileStorage::READ);
Mat matI1, matI2, matD1, matD2;
fsI["M1"] >> matI1;
fsI["M2"] >> matI2;
fsI["D1"] >> matD1;
fsI["D2"] >> matD2;

CvMat camInt1 = matI1, camInt2 = matI2, camDist1 = matD1, camDist2 = matD2;

FileStorage fs("extrinsics.yml", FileStorage::READ);
Mat mat1, mat2;
fs["P1"] >> mat1;
fs["P2"] >> mat2;

CvMat projMat1 = mat1, projMat2 = mat2;

double pointImg1_a[2] = { 1168, 1140};
Mat pointImg1 = Mat(2,1, CV_64FC1, pointImg1_a);
CvMat _pointImg1 = cvMat(1,1,CV_64FC2,pointImg1_a);
double pointImg2_a[2] = { 1062, 1167};
Mat pointImg2 = Mat(2,1, CV_64FC1, pointImg2_a);
CvMat _pointImg2 = cvMat(1,1,CV_64FC2,pointImg1_a);

cvUndistortPoints(&_pointImg1,&_pointImg1,&camInt1,&camDist1);
cvUndistortPoints(&_pointImg2,&_pointImg2,&camInt2,&camDist2);

Mat point4D = Mat(4,1, CV_64FC1);
cv::triangulatePoints(mat1, mat2, pointImg1, pointImg2, point4D);   

double w = point4D.at<double>(3,0);
double x = point4D.at<double>(0,0)/w;
double y = point4D.at<double>(1,0)/w;
double z = point4D.at<double>(2,0)/w;

cout << x << ", " << y << ", " << z << endl;

return 0;

我尝试不使用cvUndistortPoints()和其他坐标,结果有时是正确的,但并不总是正确的。我真的不知道这个错误是从哪里来的。(我也是openCV的新手)谢谢你的帮助。

EN

回答 1

Stack Overflow用户

发布于 2014-12-28 13:24:02

难道你没有错吗:"CvMat _pointImg2 = cvMat(1,1,CV_64FC2,pointImg1_a);“

正确的应该是:"CvMat _pointImg2 = cvMat(1,1,CV_64FC2,cvMat)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24129188

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档