pythonopencvcomputer-visionlinear-algebracamera-calibration

Camera pose estimation using opencv's solvePnP


I have a grayscale camera for which I have already calculated intrinsic parameters with standard methods of calibrations. I have then position this camera in a particular stationary setup and put a plate with 8 marker points in front of the camera. I have calculated the camera pose with respect to the coordinate system of those markers using the formula:

cameraPosition = -np.matrix(rotM).T * np.matrix(tvec), where rotM is the rotational matrix and tvec is the translation vector obtained with opencv's cv.solvePnP

I wanted to check, how accurate the calculated camera pose is, but have stumbled into a problem, which is, that I do not know, to what physical point does the cameraPosition vector points to.

I firstly thought that it points to the center of the image plane, but now I've read that it points to the center of projection point.

Which is it? And if it's indeed the center of projection, how could I calculate, where that is located in my camera (using a certain camera settings)?

Thanks


Solution

  • -np.matrix(rotM).T * np.matrix(tvec) is the reverse operation from converting a point (xw yw zw) in the world coordinates into camera coordinates, when that point is (0,0,0) in camera system.

    [R R R tx][xw]
    [R R R ty][yw]
    [R R R tz][zw]
    [0 0 0 1 ][1 ]
    

    is Xc = rotM@Xw + tvec (Xw=[xw,yw,zw], tvec=[tx,ty,tz], rotM=R)

    So reverse operation is Xw = RotM⁻¹@(Xc-tvec) aka Xw = RotM.T@(Xc-tvec), since, for a rotation matrix, inverse and transpose are the same.

    If Xc=[0,0,0], that is Xw=-rotM.T@tvec

    So, indeed, that points to the center of projection (origin of camera coordinates system), expressed in the world coordinates. It tells you where the camera is in your world coordinates (the one you used to position physical points in the 3D world)

    To end up in the center of the image, that takes a projection (canonical projection matrix, times intrisinc matrix), that would lead to [cx,cy], the position of the camera direction in the image (usually the middle of the image, but not necessarily). But the only point in the world that you cannot project happens to be the center of the projection. So to get that, you need first to add something (anything) to Zc

    So, I do not know how to you intend to use that "center of projection expressed in world coordinates" to check your projection. Maybe to verify that, in your world coordinates, that point indeed to where the physical camera is? (in reality, not exactly: that is the center of projection. It is a virtual point created by lens. But, well, it should be not far from a point "inside" the camera, at a focal distance from the lens.