簡體   English   中英

如何從openCV與triangulatePoints()獲得良好的坐標

[英]how obtain good coordinate with triangulatePoints() from openCV

所以我有一點,左圖為x:1168px,y:1140px,右圖為x:1062px,y:1167px。 我在程序中得到的實際坐標是:120.91、4.94059,-175.609(x,y和z以毫米為單位)。 X和Y似乎是正確的,但Z卻不正確,這個點離我的相機大約1米。

現在我有以下代碼:

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的新手)感謝您的幫助。

您在行上沒有犯錯:“ CvMat _pointImg2 = cvMat(1,1,CV_64FC2,pointImg1_a);”

正確的應該是:“ CvMat _pointImg2 = cvMat(1,1,CV_64FC2, pointImg2_a );”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM