Search code examples
pythoncomputer-visioncamera-calibration

Finding Camera Matrix from known Points python


I have 8 3d points of a 3D model and 8 2d points of that model's real world photograph. is it possible to get the camera matrix of that camera using these 3D and 2D points?

here are the 3D points

      X       Y        Z
0   0.098   35.484   16.58
1   17.34   38.638   16.28
2   27.65   44.133   0.083
3   17.23   38.678  -16.25
4   0.068   35.536  -16.58
5  -17.24   38.799  -16.06
6  -27.67   44.402   0.379
7  -17.10   38.820   16.21 

here are the 2D points

      X      Y   
0    777    203
1   1015    217
2   1142    440
3   1019    662
4    778    675
5    542    660
6    425    442
7    546    219

what would be the camera matrix for this scenario and How can I get it using python


Solution

  • Yes, the problem of estimating the camera matrix given 3D points and their projection is called Camera resectioning. You need at least 6 points to be able to solve it. In Python you can use OpenCV's calibrateCamera function:

    retval, cameraMatrix, distCoeffs, rvecs, tvecs = cv2.calibrateCamera(objectPoints, imagePoints, imageSize)
    

    For a more in-depth explanation of the camera resection problem, you can read here, section 3.1.

    EDIT: the 3d points should be in planar so that 3D points' z coordinates should be 0.0 . In order to do that you need to put the 3d dots on real object on z plane