Skip to content

Latest commit

 

History

History
44 lines (36 loc) · 2.17 KB

README.md

File metadata and controls

44 lines (36 loc) · 2.17 KB

Camera Calibration

Measures camera distortion values and computes the translation vector by which the image should be shifted. It uses opencv function cv.calibrateCamera()


How to use

  1. Print a chessboard.
  2. Make sure to install numpy and opencv.
  3. Run command:
python get_distortion_from_camera.py [CAMERA_NAME]
  1. Move the chessboard in front of the camera until the program finishes.
  2. The distortion parameters are stored in the file camera_distortion.yaml (by default in the code directory).

Parameters

  • -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.

Output

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

Python library use (alternative use)

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")