Member-only story
How To Calibrate a Camera Using Python And OpenCV
In this article, we'll look at how we can determine a monocular camera's camera matrix and distortion coefficients using Python and OpenCV for undistorting images.
First, we'll take some pictures with a monocular camera — in my case, it is my webcam. These pictures will contain a chessboard in various positions and attitudes.
Then, a calibration program will take those images, extract the corners on those chessboards, and use them to determine our camera's distortion coefficients and intrinsic properties. The output will be saved in a JSON file.
Finally, we'll load the camera matrix and the distortion coefficients from the JSON file and use them to undistort the original chessboard images.
The following documentation results from some experimentation I recently performed out of curiosity.
Take pictures with the camera
First, let's take some pictures with our camera. In my case, this is a Logitech C270 HD-Webcam.
There are countless ways in which this can be done. Here is how I did it: