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:
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:
- Create
CameraCalibrator
object usingFacerecService.createCameraCalibrator
method. - Initialize
CameraCalibrator
object by calling theCameraCalibrator.initCalibration
method. - Capture the pattern in different poses with the camera you chose to calibrate and provide the captured frames in
CameraCalibrator.addImage
. - 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. - Call the
CameraCalibrator.calibrate
method. - 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. - 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:
- First, load the saved calibrated parameters using the
CameraCalibrator.loadCameraParameters
method. - Then, correct the image distortion using the
CameraCalibrator.undistort
method.