Measures camera distortion values and computes the translation vector by which the image should be shifted.
It uses opencv function cv.calibrateCamera()
- Print a chessboard.
- Make sure to install numpy and opencv.
- Run command:
python get_distortion_from_camera.py [CAMERA_NAME]
- Move the chessboard in front of the camera until the program finishes.
- The distortion parameters are stored in the file
camera_distortion.yaml
(by default in the code directory).
-path [PATH]
optional parameter to set, where to store the camera distortion values. By default, is the directory, where the code is located.-num_pic [NUMBER]
optional parameter to set the amount of pictures to make for calibration. More pictures, more accurate calibration. By default, is set to 20.-demo
optional flag to use a demo mode. During the demo mode the camera image is showed along with current calibration applied.
Distortion values are stored in the camera_distortion.yaml
file. It has a dictionary:
image_shift
array of two values: shift in X direction and shift in Y direction, that you need to apply to the original image to make it centered.dist
np.array of distortion of the lens.mtx
np.array which include focal length and optical center.ret
float. The Euclidean distance between the distorted image point and the distortion center.
More about dist
, mtx
, ret
you can find here
Alternatively, you can call this python script as library and use its functions.
from get_distortion_from_camera import update_calibration, read_camera_distortion, read_image_shift
# Do the calibration and save new distortion values to the file
update_calibration(camera_name=1, number_of_pictures=20, path="1")
# Read all camera distortion values from file
cam_dist = read_camera_distortion(path = "1")
# Read only image shift vector from file
im_shift = read_image_shift(path = "1")