Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions camera_calibration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# camera_calibration

`camera_calibration` calibrates monocular and stereo cameras with a checkerboard.
It computes the `camera_info` of each camera, and sends it to the camera driver or saves it to a file.

For a camera that publishes `/my_camera/image_raw` and provides the `/my_camera/set_camera_info` service, with an 8x6 checkerboard (9x7 squares) of 108 mm squares:

```console
ros2 run camera_calibration cameracalibrator --size 8x6 --square 0.108 --ros-args \
-r image:=/my_camera/image_raw -r camera/set_camera_info:=/my_camera/set_camera_info
```

| Executable | Description |
| --- | --- |
| `cameracalibrator` | Calibrates a monocular or stereo camera from its live images, in a window |
| `cameracheck` | Checks the calibration of a camera from its rectified images |
| `tarfile_calibration` | Calibrates a camera again from the images saved by `cameracalibrator` |

## Documentation

The full documentation, including all the options and tutorials for monocular and stereo cameras, is in the [doc](https://github.com/ros-perception/image_pipeline/blob/rolling/camera_calibration/doc/index.rst) directory and it is published at [docs.ros.org](https://docs.ros.org/en/rolling/p/camera_calibration/).

To build it locally, [install rosdoc2](https://github.com/ros-infrastructure/rosdoc2#installation), source the workspace where `camera_calibration` is built, so that its Python API can be documented, and run:

```console
rosdoc2 build --package-path .
```

The result is written to `docs_output/camera_calibration/index.html`.
14 changes: 8 additions & 6 deletions camera_calibration/doc/api.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
API Documentation
=================
Python API
==========

.. autoclass:: camera_calibration.mono_calibrator.MonoCalibrator
:members:
The Python modules of ``camera_calibration`` are documented here for reference.
They are not a supported API: use the executables, described in :doc:`components`.

.. autoclass:: camera_calibration.stereo_calibrator.StereoCalibrator
:members:
.. toctree::
:maxdepth: 2

modules
234 changes: 194 additions & 40 deletions camera_calibration/doc/components.rst
Original file line number Diff line number Diff line change
@@ -1,52 +1,206 @@
Nodes
=====
Executables
===========

This package includes a number of ROS 2 components that can be assembled
into image processing pipelines.
See the tutorial :ref:`Launch image_proc Components`.
The executables of ``camera_calibration`` are command-line tools, run with ``ros2 run``.
Their options are given before ``--ros-args``, and the topic and service remappings after it.

Alternatively, each component can be run as a standalone node.
.. contents::
:local:
:depth: 1

camera_calibrator
-----------------
``cameracalibrator`` subscribes to ROS raw image topics, and presents a
calibration window. It can run in both monocular and stereo modes.
The calibration window shows the current images from the cameras,
highlighting the checkerboard. When the user presses the **CALIBRATE**
button, the node computes the camera calibration parameters. When the
user clicks **COMMIT**, the node uploads these new calibration parameters
to the camera driver using a service call.
.. _cameracalibrator:

cameracalibrator
----------------

Calibrates a monocular or a stereo camera, in a window that shows the images of the camera with the detected checkerboard.
Node name: ``cameracalibrator``.

It runs in monocular mode when it receives images on ``image``, and in stereo mode when it receives synchronized images on ``left`` and ``right``.

Subscribed Topics
^^^^^^^^^^^^^^^^^
* **image** (sensor_msgs/Image): Raw image topic, for monocular cameras.
* **left** (sensor_msgs/Image): Raw left image topic, for stereo cameras.
* **right** (sensor_msgs/Image): Raw right image topic, for stereo cameras.
* **image** (sensor_msgs/msg/Image): Raw image of a monocular camera.
* **left** (sensor_msgs/msg/Image): Raw left image of a stereo camera.
* **right** (sensor_msgs/msg/Image): Raw right image of a stereo camera.

The images can be color or monochrome, and are converted to monochrome.
``cameracalibrator`` does not use the ``camera_info`` of the camera.

Services Called
^^^^^^^^^^^^^^^
* **camera/set_camera_info** (sensor_msgs/SetCameraInfo): Sets the camera
info for a monocular camera.
* **left_camera/set_camera_info** (sensor_msgs/SetCameraInfo): Sets the camera
info for the left camera of a stereo pair.
* **right_camera/set_camera_info** (sensor_msgs/SetCameraInfo): Sets the camera
info for the right camera of a stereo pair.

camera_check
------------
``cameracheck`` subscribes to ROS rectified image topics and their associated
camera_info, and prints out an error estimate. It can run in both monocular
and stereo modes. The program expects to see a standard checkerboard target.
* **camera/set_camera_info** (sensor_msgs/srv/SetCameraInfo): Sends the calibration of a monocular camera, with **COMMIT**.
* **left_camera/set_camera_info** (sensor_msgs/srv/SetCameraInfo): Sends the calibration of the left camera of a stereo camera.
* **right_camera/set_camera_info** (sensor_msgs/srv/SetCameraInfo): Sends the calibration of the right camera of a stereo camera.

Remap the services themselves, for example ``-r camera/set_camera_info:=/my_camera/set_camera_info``: remapping ``camera`` has no effect on ``camera/set_camera_info``.

At startup, ``cameracalibrator`` waits one second for each of the three services, and exits with ``RuntimeError: no camera service available`` if none of them is available.
Use ``--no-service-check`` to skip this check, for example to calibrate from a bag, and save the calibration with **SAVE** instead of **COMMIT**.

The window
^^^^^^^^^^

.. image:: images/mono_0.png
:alt: the calibration window while it collects samples

The window shows the images, with the detected checkerboard drawn on them, and a sidebar:

* **X**, **Y**, **Size** and **Skew**: how much of the range of each of these parameters the collected samples cover.
X and Y are the position of the checkerboard in the image, Size its size in the image, and Skew its tilt.
A bar turns green when its range is covered.
A sample is collected only when the checkerboard is different enough from all the previous samples, and the terminal prints ``*** Added sample``.
* **CALIBRATE**: enabled when all the bars are green, or after 40 samples. Computes the calibration from the collected samples.
* **SAVE**: enabled after the calibration. Writes the samples and the calibration to ``/tmp/calibrationdata.tar.gz``.
* **COMMIT**: enabled after the calibration. Sends the calibration to the camera with its ``set_camera_info`` service, and exits if it succeeds.

After the calibration, the window shows the rectified images, and the sidebar shows the error of the calibration on the current image, in pixels:
``lin.`` for a monocular camera, how far the rectified corners of each row of the checkerboard are from a straight line, and ``epi.`` for a stereo camera, the vertical distance between the same corner in the left and right rectified images.

Under the images, two sliders:

* **Camera type**: 0 for a pinhole camera, 1 for a fisheye camera. Set it before clicking **CALIBRATE**, after the first image is shown. See :ref:`fisheye-cameras`.
* **scale**: after the calibration, the scale of the rectified images, from 0 to 100.
At 0, the rectified image only contains valid pixels, and some pixels of the camera are cut out.
At 100, it contains all the pixels of the camera, with black borders where the rectified image has no pixels.

Keys, when the window has the focus: **s** saves the window to ``/tmp/dump0.png`` (then ``dump1.png``, and so on), **q** or **Esc** closes it.

Options
^^^^^^^

Pass ``--help`` for the full list:

.. code-block:: text

Usage: cameracalibrator --size SIZE1 --square SQUARE1 [ --size SIZE2 --square SQUARE2 ]

Options:
-h, --help show this help message and exit
-c CAMERA_NAME, --camera_name=CAMERA_NAME
name of the camera to appear in the calibration file

Chessboard Options:
You must specify one or more chessboards as pairs of --size and
--square options.

-p PATTERN, --pattern=PATTERN
calibration pattern to detect - 'chessboard',
'circles', 'acircles', 'charuco' if 'charuco' is
used, a --charuco_marker_size and --aruco_dict
argument must be supplied with each --size and
--square argument
-s SIZE, --size=SIZE
chessboard size as NxM, counting interior corners
(e.g. a standard chessboard is 7x7)
-q SQUARE, --square=SQUARE
chessboard square size in meters
-m CHARUCO_MARKER_SIZE, --charuco_marker_size=CHARUCO_MARKER_SIZE
ArUco marker size (meters); only valid with `-p
charuco`
-d ARUCO_DICT, --aruco_dict=ARUCO_DICT
ArUco marker dictionary; only valid with `-p charuco`;
one of 'aruco_orig', '4x4_250', '5x5_250', '6x6_250',
'7x7_250'

ROS Communication Options:
--approximate=APPROXIMATE
allow specified slop (in seconds) when pairing images
from unsynchronized stereo cameras
--no-service-check disable check for set_camera_info services at startup
--queue-size=QUEUE_SIZE
image queue size (default 1, set to 0 for unlimited)

Calibration Optimizer Options:
--fix-principal-point
for pinhole, fix the principal point at the image
center
--fix-aspect-ratio for pinhole, enforce focal lengths (fx, fy) are equal
--zero-tangent-dist
for pinhole, set tangential distortion coefficients
(p1, p2) to zero
-k NUM_COEFFS, --k-coefficients=NUM_COEFFS
for pinhole, number of radial distortion coefficients
to use (up to 6, default 2)
--fisheye-recompute-extrinsicsts
for fisheye, extrinsic will be recomputed after each
iteration of intrinsic optimization
--fisheye-fix-skew for fisheye, skew coefficient (alpha) is set to zero
and stay zero
--fisheye-fix-principal-point
for fisheye,fix the principal point at the image
center
--fisheye-k-coefficients=NUM_COEFFS
for fisheye, number of radial distortion coefficients
to use fixing to zero the rest (up to 4, default 4)
--fisheye-check-conditions
for fisheye, the functions will check validity of
condition number
--disable_calib_cb_fast_check
uses the CALIB_CB_FAST_CHECK flag for
findChessboardCorners
--max-chessboard-speed=MAX_CHESSBOARD_SPEED
Do not use samples where the calibration pattern is
moving faster than this speed in
px/frame. Set to eg. 0.5 for rolling shutter cameras.

Some details that the help does not give:

* ``--approximate``: by default, the left and right images must have exactly the same timestamp. With ``--approximate 0.01``, images up to 0.01 seconds apart are paired.
* ``--disable_calib_cb_fast_check``: despite its help, this option *disables* the ``CALIB_CB_FAST_CHECK`` flag, which is used by default. The fast check quickly rejects images without a checkerboard.
* ``--max-chessboard-speed``: in pixels per frame. Moving checkerboards blur the images, especially with rolling shutter cameras.
* ``--k-coefficients``: with more than 3 coefficients, the distortion model is ``rational_polynomial``.
* ``--fisheye-recompute-extrinsicsts``: needed for fisheye cameras, see :ref:`fisheye-cameras`.

.. _cameracheck:

cameracheck
-----------

Checks the calibration of a camera: it finds the checkerboard in the rectified images, and prints the error of the calibration for each image.
Node name: ``cameracheck``.

* For a monocular camera, it prints ``Linearity RMS Error`` and ``Reprojection RMS Error``, in pixels. See :ref:`known-issues`: this mode currently crashes.
* For a stereo camera, it prints the ``epipolar error``, in pixels, and the ``dimension`` of a square of the checkerboard, in meters, measured with the stereo camera.

Subscribed Topics
^^^^^^^^^^^^^^^^^
* **monocular/image** (sensor_msgs/Image): Rectified image topic, for
monocular camera.
* **monocular/camera_info** (sensor_msgs/CameraInfo): Camera info for
the monocular camera.
* **stereo/left/image** (sensor_msgs/Image): Rectified left image topic,
for stereo cameras.
* **stereo/right/image** (sensor_msgs/Image): Rectified right image topic,
for stereo cameras.
* **stereo/camera_info** (sensor_msgs/CameraInfo): Camera info for the
stereo pair.
* **monocular/image_rect** (sensor_msgs/msg/Image): Rectified image of a monocular camera.
* **monocular/camera_info** (sensor_msgs/msg/CameraInfo): Camera info of the monocular camera.
* **stereo/left/image_rect** (sensor_msgs/msg/Image): Rectified left image of a stereo camera.
* **stereo/left/camera_info** (sensor_msgs/msg/CameraInfo): Camera info of the left camera.
* **stereo/right/image_rect** (sensor_msgs/msg/Image): Rectified right image of a stereo camera.
* **stereo/right/camera_info** (sensor_msgs/msg/CameraInfo): Camera info of the right camera.

The image and the camera info must have exactly the same timestamp, unless ``--approximate`` is given.

Options
^^^^^^^
* ``-s``, ``--size`` (default: ``8x6``): Size of the checkerboard, in interior corners.
* ``-q``, ``--square`` (default: ``0.108``): Size of a square of the checkerboard, in meters.
* ``--approximate``: Allowed time difference between the synchronized messages, in seconds.

Unlike ``cameracalibrator``, ``cameracheck`` takes a single checkerboard.

.. _tarfile_calibration:

tarfile_calibration
-------------------

Calibrates a camera from the images in an archive saved by ``cameracalibrator``, for example to try other calibration options without the camera:

.. code-block:: console

$ ros2 run camera_calibration tarfile_calibration /tmp/calibrationdata.tar.gz --mono --size 8x6 --square 0.108 -k 3

It prints the calibration in the text format of the OST calibration tool.
Without ``--mono``, it calibrates a stereo camera, from the ``left-*.png`` and ``right-*.png`` images.

Options
^^^^^^^
* ``--mono``: Calibrate a monocular camera, from the ``left-*.png`` images.
* ``-s``, ``--size`` and ``-q``, ``--square`` (default: ``8x6`` and ``0.108``): Size of the checkerboard, as for ``cameracalibrator``. Can be repeated for several checkerboards.
* ``--fix-principal-point``, ``--fix-aspect-ratio``, ``--zero-tangent-dist`` and ``-k``, ``--k-coefficients``: Calibration options, as for ``cameracalibrator``.
* ``--visualize``: Show each image rectified with the new calibration, one by one. Press a key for the next image, **q** or **Esc** to stop (it stops with a ``RuntimeError``, which can be ignored).
* ``-a``, ``--alpha`` (default: 1.0): Scale of the rectified images of ``--visualize``, from 0 to 1, as the **scale** slider of ``cameracalibrator``.
* ``--upload``: Send the calibration to the camera. See :ref:`known-issues`: it currently fails.
Loading