Table of Contents

Camera Calibration

Introduction

SolAR provides a program based on OpenCV that can be used to calibrate your camera. The source code is available in the SolARModuleOpenCV repository (in the tools folder), and a executable is available in the releases of this OpenCV module.

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 pattern like the one below.

chessboard

Tutorial

Installation

Download and unzip the camera calibration tool for windows or linux

Configuration

In the unzipped folder, you find a calibration_config.yml file that contains information about the chessboard size, its square size, aspect ratio, number of frames used for calibration, OpenCV’s flags and delay time between each frame. You can configure all these parameters corresponding to your use case.

# 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)
aspect_ratio: 1
# number of frames to calibrate the camera
nb_frames: 10
# OpenCV Flags for camera calibration
flags: 0
# delay between each frame in milliseconds
delay: 2000

Input preparation

Firstly, print the chessboard pattern file in the installation folder, and update the calibration_config.yml according to the realse size of your printed chessboard.
Then this tool allows to calibrate a camera by using its index when plugged in, a video file or an image sequence. Please configure your input data in the SolARTool_CameraCalibration_conf.xml file. You can also choose the resolution of the camera that you want to calibrate, if this resolution is supported, by modifying width and height parameters in the camera_calibration.json file.

Execution

Run the execution file.

Windows:

SolARTool_CameraCalibration.exe

Linux:

./run.sh ./SolARTool_CameraCalibration
Parameters are passed with an equal operator (e.g. _SolARTool_CameraCalibration -i=1).

When launching this tool, it will show the following window. Press the g key to start the process.

run

A number of positive detections will be taken to calibrate. A positive detection is verified when the chessboard is correctly detected. This is illustrated with a frozen picture displaying corners and lines as below.

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

By default, an output calibration file has been generated in json format (camera_calibration.json) in the same folder. We illustrate an example of the calibration file as follows.

{
    "CameraParameters": {
        "name": "Logitech C920",
        "id": 0,
        "type": 0,
        "resolution": {
            "width": 640,
            "height": 480
        },
        "intrinsic": [
            6.2358844756875726e+02, 0, 3.19501379528701e+02,
            0, 6.2510924611650637e+02, 2.395453191051286e+02,
            0, 0, 1
        ],
        "distortion": [
            5.0406145631272294e-03, -7.3194070034412229e-01, 8.8401137738982200e-03,
            -4.1912068994392751e-03, 2.7609935737342024e+00
        ]
    }
}

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

Illustration Video

To better calibrate, the calibration process requires capturing the chessboard pattern at different poses of the camera. This is illustrated in the following video.