How to determine world coordinates of a camera?

后端 未结 2 1724
别那么骄傲
别那么骄傲 2021-01-31 12:33

I have a rectangular target of known dimensions and location on a wall, and a mobile camera on a robot. As the robot is driving around the room, I need to locate the target and

2条回答
  •  醉酒成梦
    2021-01-31 13:12

    You get the translation and rotation vectors from solvePnP, which are telling where is the object in camera's coordinates. You need to get an inverse transform.

    The transform camera -> object can be written as a matrix [R T;0 1] for homogeneous coordinates. The inverse of this matrix would be, using it's special properties, [R^t -R^t*T;0 1] where R^t is R transposed. You can get R matrix from Rodrigues transform. This way You get the translation vector and rotation matrix for transformation object->camera coordiantes.

    If You know where the object lays in the world coordinates You can use the world->object transform * object->camera transform matrix to extract cameras translation and pose.

    The pose is described either by single vector or by the R matrix, You surely will find it in Your book. If it's "Learning OpenCV" You will find it on pages 401 - 402 :)

    Looking at Your code, You need to do something like this

        cv::Mat R;
        cv::Rodrigues(rotation_vector, R);
    
        cv::Mat cameraRotationVector;
    
        cv::Rodrigues(R.t(),cameraRotationVector);
    
        cv::Mat cameraTranslationVector = -R.t()*translation_vector;
    

    cameraTranslationVector contains camera coordinates. cameraRotationVector contains camera pose.

提交回复
热议问题