【发布时间】:2015-08-25 17:15:05
【问题描述】:
我试图找到我知道他在图像中的坐标的 3D 坐标(在世界中)。所以在互联网上进行了一些研究后,我成功地找到了 X 和 Y 坐标。但我找不到Z
这是我在 openCV 中的程序
void drawAndCalcul3D(int x,int y,Mat& frame)
{
cv::Mat uvPoint = cv::Mat::ones(3,1,cv::DataType<double>::type);
uvPoint.at<double>(0,0) = x; //got this point using mouse callback
uvPoint.at<double>(1,0) = y;
std::vector<cv::Point2f> imagePoints;
std::vector<cv::Point3f> objectPoints;
cv::Mat rotationMatrix(3,3,cv::DataType<double>::type);
Mat cameraMatrix(3,3,DataType<double>::type);
setIdentity(cameraMatrix);
cameraMatrix.at<double>(0,0)=493.415; //my Camera matrix
cameraMatrix.at<double>(0,1)=0;
cameraMatrix.at<double>(0,2)=319.5;
cameraMatrix.at<double>(1,0)=0;
cameraMatrix.at<double>(1,1)=493.415;
cameraMatrix.at<double>(1,2)=179.5;
cameraMatrix.at<double>(2,0)=0;
cameraMatrix.at<double>(2,1)=0;
cameraMatrix.at<double>(2,2)=1;
// extrinsic parameters rvec and tvect : rotation and translation matrix
Mat rvec(3,1,cv::DataType<double>::type);
rvec.at<double>(0)=-0.1408;
rvec.at<double>(1)=3.011;
rvec.at<double>(2)=-0.171147;
//
cv::Mat tvec(3,1,cv::DataType<double>::type);
tvec.at<double>(0)=15.84;
tvec.at<double>(1)=-64.67;
tvec.at<double>(2)=274.584;
cv::Rodrigues(rvec,rotationMatrix);
//
cv::Mat tempMat, tempMat2;
double s;
tempMat = rotationMatrix.inv() * cameraMatrix.inv() * uvPoint;
tempMat2 = rotationMatrix.inv() * tvec;
s =tempMat2.at<double>(2,0); //12 represents the height Zconst
s /= tempMat.at<double>(2,0);
Mat exp=rotationMatrix.inv() * (s * cameraMatrix.inv() * uvPoint - tvec);
cv::putText(frame,intToString(exp.at<double>(0))+ " , " + intToString(exp.at<double>(1))+ " , " + intToString(exp.at<double>(2)),cv::Point(x,y+20),2,1,Scalar(0,255,0));
}
谁能知道我怎样才能找到物体的深度(Z)?
我使用与她相同的程序Computing x,y coordinate (3D) from image point 我不知道如何更改它以找到不恒定的 Z
【问题讨论】:
标签: opencv image-processing 3d camera-calibration