dabble.camera_calibration

Description

Calculates camera coefficients to be used to remove distortion from a wide-angle camera image.

class Node(config=None, **kwargs)[source]

Calculates camera coefficients for undistortion.

To calculate your camera, first download the following checkerboard and print it out in a suitable size and attach it to a hard surface, or display it on a sufficiently large device screen, such as a computer or a tablet. For most use cases, an A4-sized checkerboard works well, but depending on the position and distance of the camera, a bigger checkerboard may be required.

../_images/checkerboard.png

Next, create an empty pipeline_config.yml in your project folder and modify it as follows:

1nodes:
2- input.visual:
3    source: 0 # change this to the camera you are using
4    threading: True
5    mirror_image: True
6- dabble.camera_calibration
7- output.screen

Run the above pipeline with peekingduck run. If you are unfamiliar with the pipeline file and running peekingduck, you may refer to the HelloCV tutorial.
You should see a display of your camera with some instructions overlaid. Follow the instructions to position the checkerboard at 5 different positions in the camera. If the process is successful, the camera coefficients will be calculated and written to a file and you can start using the augment.undistort node.

Inputs

img (numpy.ndarray): A NumPy array of shape \((height, width, channels)\) containing the image data in BGR format.

Outputs

img (numpy.ndarray): A NumPy array of shape \((height, width, channels)\) containing the image data in BGR format.

Configs
  • num_corners (List[int]) – default = [10, 7].
    A list containing the number of internal corners along the vertical and horizontal axes. For example, in the given image above, the checkerboard is of size 11x8, so the number of internal corners is 10x7. If you are using the given checkerboard above, you do not need to change this parameter.

  • scale_factor (int) – default = 2.
    Factor to scale the image by when finding chessboard corners. For example, with a scale of 4, an image of size (1080 x 1920) will be scaled down to (270 x 480) when detecting the corners. Increasing this value reduces computation time. If the node is unable to detect corners, reducing this value may help.

  • file_path (str) – default = “PeekingDuck/data/camera_calibration_coeffs.yml”.
    Path of the YML file to store the calculated camera coefficients.