【问题标题】:Finding 3D coordinate of object查找对象的 3D 坐标
【发布时间】: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


    【解决方案1】:

    x,y 图像点仅确定从相机中心穿过图像点的光线。它具有无限数量的可能 z,当您将图像点与逆矩阵相乘时,您将得到一个射线或线的方程。使用单个相机从单个图像点获取 3D 是不可能的。当然,除非你做出一些强有力的假设,比如物体的形状或大小,或者使用额外的知识,比如单眼线索。此类线索的示例包括模糊/聚焦、亮度/阴影、纹理大小、附近其他物体的熟悉大小等。

    另一个例子 - 如果您知道物体所在平面的方程,您可以将该平面与射线相交并到达一个唯一的 3D 点。还有一个例子,比如说,你在手机中使用加速度计,它会为你提供相机相对于重力矢量的角度。您还知道手持手机的大致高度(离地 1.5m)。您可以轻松地将地面上的 3D 点计算为光线与已知平面的交点,见下文。该公式给出了图像中心点的 Z。对于其他点,您必须添加由偏离中心像素形成的额外角度。这将允许您完全恢复地平面的 3D。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-08
      • 2020-09-14
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 2016-06-16
      • 2010-12-17
      相关资源
      最近更新 更多