Table of Contents

Camera Calibration

Introduction

SolAR provides a program based on OpenCV that can be used to calibrate your camera. This program is available in the SolARModuleOpenCV repository. A chessboard image (chessboard.png) and a input configuration file are provided.

This tutorial is a simplified version of the one provided by OpenCV, feel free to visit OpenCV website to get details on the actual implementation.

The calibration process uses a chessboard. You can print the following one:

chessboard

steps

  • Download the zip file with the CameraCalibration executable according to your operating system exec

  • Plug your camera device

  • Run the program SolARCameraCalibrationOpenCV.exe

By default, the camera Id is supposed to be 0 and this is correct most of the time. But if you have several cameras plugged to your computer, you can launch your CameraCalibration execution file with the Id of your camera in the parameters:

SolARCameraCalibrationOpenCV.exe 1

When launch, you will visualize the following window:

run
  • Press the 'g' key to start the process.

A number of positive detections (default = 10) will be taken with a minimum period of time between two detections (default value = 2 seconds). The will be further explained in the last paragraph : input/output files. A positive detection is when the chessboard is correctly identified. This is illustrated with a frozen picture displaying corners and lines :

detect

Please, notice the bottom-right counter that indicates the number of positive detections so far.

When all the positive detections are obtained, the calibration is performed and the process is completed, then a bottom-right message indicates "Calibrated" :

completed
  • Press [Esc] to close the camera view and to exit the program.

An output calibration file has been generated :

outFile

This file can be used directly in SolARModuleOpenCV tests and samples if a calibration file is required.

Input/output files

The input/output file names are hard coded in the code.

fileNames

The input file is calibration_config.yml. An example is given which is described below :

INPUT

calibration_config.yml content :
# the number of inner corners on board width
chessboard_width: 9
# the number of inner corners on board height
chessboard_height: 6
# square size in some user-defined units
square_size: 0.026
#fix aspect ratio (fx/fy)
apsect_ration: 1
# number of frames to calibrate the camera : 10 is advised for a high calibration quality, you can put less if you are not so exigent
nb_frames: 10
# OpenCV Flags for camera calibration
flags: 0
# delay between each frame in milliseconds : 2 is good to let you enough time to move your camera and focus on the chessboard.
delay: 2000

The output file is camera_calibration.yml. It contains the result of the calibration and the format is described below :

OUTPUT

This program generates a file camera_calibration.yml.
Check the file date, to be sure that it has been generated when you run the SolARCameraCalibration.
The data in this file define the calibration parameters of your camera, and will hemp for computer vision and especially pose estimation.

calibration_time: "Wed Dec  6 14:02:31 2017"
image_width: 640
image_height: 480
board_width: 9
board_height: 6
square_size: 2.6000000536441803e-02
flags: 0
camera_matrix: !!opencv-matrix
   rows: 3
   cols: 3
   dt: d
   data: [ 6.2358844756875726e+02, 0., 3.1296501379528701e+02, 0.,
       6.2510924611650637e+02, 2.6595453191051286e+02, 0., 0., 1. ]
distortion_coefficients: !!opencv-matrix
   rows: 5
   cols: 1
   dt: d
   data: [ 5.0406145631272294e-03, -7.3194070034412229e-01,
       8.8401137738982200e-03, -4.1912068994392751e-03,
       2.7609935737342024e+00 ]

Video

This calibration requires that the chessboard is detected (positive detections) with, as far as possible, different poses of the camera. This is illustrated in the following video.