top of page
Writer's pictureH-Barrio

Testing OpenCV Camera Calibration Measurements

In this post, we will check in a very preliminary manner the results of the camera calibration we performed in the previous post. We are also using our updated marker detection code from this notebook. So the first step is to use the camera calibration notebook and download the calibration results in cm.csv (camera matrix) and cd.csv (distortion matrix). Make sure that when calibrating the camera with the notebook, you move the checkerboard around the frame; if the calibration is not good, it is usually because all the points are taken from the same area of the camera lens, and the distortion introduced by the lenses is not equal all around the capture frame. n the future, we will automate this task to ensure that the calibration contains sample points from all octal sectors of the camera frame.


Upload the calibration files to the notebook at the bottom of the post. This code section will read the camera calibration and set the constants for the feed. Size is the size of one side of your ArUCO markers. The code assumes the use of only 4x4 markers:

CAMERA_PARAMETERS = pd.read_csv("cm.csv", header=0, index_col=0).to_numpy()
DISTORTION_PARAMETERS = pd.read_csv("cd.csv", header=0, index_col=0).to_numpy()
SIZE = 0.056
VIDEO_WIDTH = 512
VIDEO_HEIGHT = 512
print(f"The camera parameters are:\n {CAMERA_PARAMETERS}")

We are finely modifying our code to find the translation vectors of the detected markers and place them in a dictionary. As it is, it will just detect the distance between two markers even if more markers are present in the frame:

# Find the translation vector of the marker:
        estimator = cv2.aruco.estimatePoseSingleMarkers
        rvec, tvec, maker_points = estimator(marker_corner,
                                             SIZE, CAMERA_PARAMETERS,
                                             DISTORTION_PARAMETERS)
        t_vecs[marker_id] = tvec

The rest of the code is the same as in the previous posts. Now we need two markers separated by a known distance. In this case, these two markers are separated by 0.20 meters from center to center:

This is a crude measurement of reality:


In a follow-up post, we will execute this measurement exercise for markers at known distances for various points in the camera to check whether the calibration is homogeneous across all points of the camera lens. Do not hesitate to contact us if you require quantitative model development, deployment, verification, or validation. We will also be glad to help you with your machine learning or artificial intelligence challenges when applied to asset management, automation, or intelligence gathering from satellite, drone, or fixed-point imagery.


The Colab notebook with the code is at this link.



108 views0 comments

Recent Posts

See All

Comments


bottom of page