从世界坐标到摄像机坐标

时间:2020-03-18 13:25:37

标签: camera

我在世界坐标中有一个3D点,(-140,-500,0),其中z是向上矢量,x是深度,y是水平 现在我想将此点转换为相机坐标 我知道我需要计算旋转矩阵和平移 我有俯仰和偏航以及相机位置
我想知道我是否正确计算了相机坐标中的点

    //ax, ay and az are the position of the point in the real world 
    //cx, cy and cz are the position of the camera 
    //67.362312316894531 is pitch 
    //89.7135009765625 is roll 
    //0.033716827630996704 is yaw 
    double x = ax - cx; 
    double y = ay -cy;
    double z = az - cz;
    double cosx = cos(67.362312316894531);
    double sinx = sin(67.362312316894531);
    double cosy = cos(89.7135009765625);
    double siny = sin(89.7135009765625);
    double cosz = cos(0.033716827630996704);
    double sinz = sin(0.033716827630996704);
    dx = cosy * (sinz * y + cosz * x) - siny * z;
    dy = sinx * (cosy * z + siny * (sinz * y + cosz * x)) + cosx * (cosz * y - sinz * x);
    dz = cosx * (cosy * z + siny * (sinz * y + cosz * x)) - sinx * (cosz * y - sinz * x);

我知道另一种方法是计算旋转矩阵

    //where yp is pitch, thet is roll and k is yaw 
    double rotxm[9] = { 1,0,0,0,cos(yp),-sin(yp),0,sin(yp),cos(yp) };
    double rotym[9] = { cos(thet),0,sin(thet),0,1,0,-sin(thet),0,cos(thet) };
    double rotzm[9] = { cos(k),-sin(k),0,sin(k),cos(k),0,0,0,1};
    cv::Mat rotx = Mat{ 3,3,CV_64F,rotxm };
    cv::Mat roty = Mat{ 3,3,CV_64F,rotym };
    cv::Mat rotz = Mat{ 3,3,CV_64F,rotzm };
    cv::Mat rotationm = rotz * roty * rotx;

我的问题是这两种方法正确吗?或至少是其中的一个。.我如何确定

0 个答案:

没有答案