2014-06-09 4 views
2

그래서 왼쪽 이미지에는 x : 1168px, y : 1140px, 오른쪽 이미지에는 x : 1062px, y : 1167px가 있습니다. 내 프로그램에서 얻은 실제 좌표는 120.91, 4.94059, -175.609 (x, y 및 z)입니다. X와 Y는 정확하지만 Z가 아닌 것 같습니다. 요점은 카메라에서 1 미터 떨어진 지점입니다.openCV에서 triangulatePoints()와 좋은 좌표를 얻는 방법

는 지금이 코드가 있습니다

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의 새로운 기능입니다.) 도움을 주셔서 감사합니다.

답변

1

줄에 실수가 없습니까? "CvMat _pointImg2 = cvMat (1,1, CV_64FC2, pointImg1_a);"

정확해야 "CvMat _pointImg2 cvMat = (1,1, CV_64FC2, pointImg2_a);"