Skip to content

Camera Calibration

Jenn edited this page Jul 26, 2018 · 2 revisions

Using ROS Camera Calibration

Dependencies

Install any camera stream package (Jenn's can be found here) and ROS's camera_calibration package (e.g. sudo apt-get install ros-kinetic-camera-calibration)

(1) Launch camera_calibration

Launch the camera stream package, then the camera_calibration package

e.g.

roslaunch camera_stream camera_stream_publisher.launch
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.254 image:=/usb_cam/image_raw camera:=/usb_cam

Where --size refers to the number of interior vertex points for _[rows]_x_[columns]_ and --square refers to the length in meters of a side of a square.

Refer to ROS Monocular Camera Calibration Tutorial for more information.

If you are using a Intel RealSense D435 camera then you may need to add --no-service-check at the end of the last command (rosrun camera_calibration ...). Found solution here.

Note: After you hit Calibrate button, it may take awhile (anywhere from ~5-30 mins depending on your system). It may appear to be frozen and the GUI may display something like "Stopped responding" or "No Response". This is normal, just wait for some time before force quitting the application. The calibration algorithm is iterating through all the images so it can take awhile.

(2) Save and reuse camera calibration parameters

Once the camera is calibrated, click the Save then Commit buttons. The calibration data will be written to /tmp/calibrationdata.tar.gz.

Copy/move it to some location and unpack it,

e.g.

mv /tmp/calibrationdata.tar.gz /some/location/for/calibration/data
tar -xzf calibrationdata.tar.gz

Rename the ost.yaml to something meaningful (e.g. logitech_c910_cam_calibration.yaml) then create a launch file that links the camera stream to the the calibrated camera information.

Launch file example (calibrated_camera_stream.launch):

<launch>
  <arg name="video_device" default="/dev/video0" />
  <arg name="image_width" default="640" />
  <arg name="image_height" default="480" />

  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="$(arg video_device)" />
    <param name="image_width" value="$(arg image_width)" />
    <param name="image_height" value="$(arg image_height)"/>
    <param name="pixel_format" value="mjpeg" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>

    <param name="camera_info_url" type="string" value="file://$(find camera_stream)/camera_calibration/logitech_c910_cam_calibration.yaml" />
  </node>
</launch>

Note: The important thing is to override the value for <param name="camera_info_url" ... to where ever you saved the calibrated camera's .yaml file. In this example, it was located in a camera_calibration folder inside Jenn's custom camera_stream package (Hence, $(find camera_stream)/camera_calibration). If this is not overwritten, ROS automatically uses their default which located ~/.ros/camera_info/head_camera.yaml.

(Found answer on how to reuse calibration parameters here)