In this tutorial, I’m gonna show you stereo camera calibration with ROS and OpenCV. So you need a pair of cameras, I bought a pair of this USB webcam which is okay for this task.
1)Save the following text under “stereo_usb_cam_stream_publisher.launch”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<launch> <arg name="video_device_right" default="/dev/video1" /> <arg name="video_device_left" default="/dev/video2" /> <arg name="image_width" default="640" /> <arg name="image_height" default="480" /> <arg name="right_image_namespace" default="stereo" /> <arg name="left_image_namespace" default="stereo" /> <arg name="right_image_node" default="right" /> <arg name="left_image_node" default="left" /> <arg name="image_topic_name_right" default="image_raw" /> <arg name="camera_info_topic_name_right" default="camera_info" /> <arg name="image_topic_name_left" default="image_raw" /> <arg name="camera_info_topic_name_left" default="camera_info" /> <arg name="left_camera_name" default="left" /> <arg name="right_camera_name" default="right" /> <arg name="left_camera_frame_id" default="left_camera" /> <arg name="right_camera_frame_id" default="right_camera" /> <arg name="framerate" default="30" /> <arg name="camera_info" default="false" /> <arg name="camera_info_path" default="stereo_camera_info" /> <node ns="$(arg right_image_namespace)" name="$(arg right_image_node)" pkg="usb_cam" type="usb_cam_node" output="screen" > <param name="video_device" value="$(arg video_device_right)" /> <param name="image_width" value="$(arg image_width)" /> <param name="image_height" value="$(arg image_height)"/> <param name="pixel_format" value="yuyv" /> <param name="io_method" value="mmap"/> <remap from="/usb_cam/image_raw" to="$(arg image_topic_name_right)" /> <param name="framerate" value="$(arg framerate)"/> <!-- if camera_info is available, we will use it--> <param name="camera_frame_id" value="$(arg right_camera_frame_id)" if="$(arg camera_info)" /> <param name="camera_info_url" value="file://${ROS_HOME}/$(arg camera_info_path)/right.yaml" if="$(arg camera_info)"/> <param name="camera_name" value="narrow_stereo/$(arg right_camera_name)" if="$(arg camera_info)"/> <remap from="/usb_cam/camera_info" to="$(arg camera_info_topic_name_right)" if="$(arg camera_info)"/> </node> <node ns="$(arg left_image_namespace)" name="$(arg left_image_node)" pkg="usb_cam" type="usb_cam_node" output="screen" > <param name="video_device" value="$(arg video_device_left)" /> <param name="image_width" value="$(arg image_width)" /> <param name="image_height" value="$(arg image_height)"/> <param name="pixel_format" value="yuyv" /> <param name="io_method" value="mmap"/> <param name="framerate" value="$(arg framerate)"/> <remap from="/usb_cam/image_raw" to="$(arg image_topic_name_left)"/> <!-- if camera_info is available, we will use it--> <param name="camera_frame_id" value="$(arg left_camera_frame_id)" if="$(arg camera_info)"/> <param name="camera_name" value="narrow_stereo/$(arg left_camera_name)" if="$(arg camera_info)"/> <param name="camera_info_url" value="file://${ROS_HOME}/$(arg camera_info_path)/left.yaml" if="$(arg camera_info)"/> <remap from="/usb_cam/camera_info" to="$(arg camera_info_topic_name_left)" if="$(arg camera_info)"/> </node> </launch> |
2)Then run the following node to publish both cameras.
1 |
roslaunch stereo_usb_cam_stream_publisher.launch video_device_right:=/dev/video1 video_device_left:=/dev/video2 image_width:=640 image_height:=480 left_camera_name:=left right_camera_name:=right |
3)Now call the calibration node:
1 |
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 right:=/stereo/right/image_raw left:=/stereo/left/image_raw right_camera:=/stereo/right left_camera:=/stereo/left --no-service-check --approximate=0.1 |
Super important:
If you have USB cam with some delays you should add the following “–no-service-check –approximate=0.1”
4)Pose the chess board in different position, and then click on the calibrate and save button.
5) The result gonna be store at /tmp/calibrationdata.tar.gz. Unzip the file and save it under “/home/<username>/.ros/stereo_camera_info“
[…] my other tutorial, I showed you how to calibrate you stereo camera. After Calibration, we can get disparity map […]
roslaunch stereo_usb_cam_stream_publisher.launch video_device_right:=/dev/video1 video_device_left:=/dev/video2 image_width:=640 image_height:=480 left_camera_name:=left right_camera_name:=right
When I run the above code, the following error shows up:
ERROR: cannot launch node of type [usb_cam/usb_cam_node]: usb_cam
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/opt/ros/melodic/share
ERROR: cannot launch node of type [usb_cam/usb_cam_node]: usb_cam
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/opt/ros/melodic/share
How do I resolve it? Please help.
Hi, could someone elaborate on that issue? The problem with cameras out of normal webcams seems to be that they need to be syncronized. Also the professional 3D cams use an ASIC or an FPGA. Thanks.
That’s almost true, that’s why I have added the following:
If you have USB cam with some delays you should add the following “–no-service-check –approximate=0.1”
Hello there same webcam but unfortunately not working in my ubuntu system:
dmeseg:
[ 6447.831829] usb 2-1.5: New USB device found, idVendor=093a, idProduct=2620, bcdDevice= 1.00
[ 6447.831833] usb 2-1.5: New USB device strings: Mfr=0, Product=0, SerialNumber=0
[ 6447.832549] gspca_main: gspca_pac7302-2.14.0 probing 093a:2620
[ 6447.833397] input: gspca_pac7302 as /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.5/input/input40
v4l2-ctl –list-devices
USB Camera (093a:2620) (usb-0000:00:1d.0-1.5):
/dev/video0
I only see black scream on cheese and vlc can you help me to make this work.