Skip to main content
Version: 3.22.0 (latest)

Camera calibration and correction of distortion

If the camera transmits distorted images, you need to correct the distortion. For this correction it is necessary to calibrate the camera.

Camera calibration

To calibrate a camera, follow the steps below:

  1. Before calibration print a calibration pattern and fix it on a flat surface, preferably black.

    There are three pattern types:

    • asymmetric circles grid pattern (recommended)
    • chessboard pattern
    • circles grid pattern

Here are examples of the patterns:

  1. Create CameraCalibrator object using FacerecService.createCameraCalibrator method.
  2. Initialize CameraCalibrator object by calling the CameraCalibrator.initCalibration method.
  3. Capture the pattern in different poses with the camera you chose to calibrate and provide the captured frames in CameraCalibrator.addImage.
  4. Use CameraCalibrator.getPatternSpaceCoverProgress method to get the approximate progress of pattern pose and orientation space coverage. CameraCalibrator.getTip method returns a tip, which pattern pose is required.
  5. Call the CameraCalibrator.calibrate method.
  6. After calibration is successfully completed (true), you can save the calibrated parameters using the CameraCalibrator.saveCameraParameters method. Otherwise (false), add more images and perform a calibration again.
  7. To reset the calibration, call CameraCalibrator.initCalibration method.

Camera calibration example: test_calibration.

Information on how to run and work with camera calibration sample: test_calibration.

Distortion correction

To correct the distortion, do the following:

  1. First, load the saved calibrated parameters using the CameraCalibrator.loadCameraParameters method.
  2. Then, correct the image distortion using the CameraCalibrator.undistort method.