Hello everyone, I'm Xiaoyu. This morning, there was a fish meal in the group asking to choose the camera number in ROS2?
question
In the Foxy version of ROS2, you can use the following command to run the camera.
source /opt/ros/foxy/setup.bash
ros2 run image_tools cam2image
What if we have multiple video devices in the computer?
Use the command below to view the video
ll /dev/video*
crw-rw----+ 1 root video 81, 0 3月 7 11:02 /dev/video0
crw-rw----+ 1 root video 81, 1 3月 7 11:02 /dev/video1
crw-rw----+ 1 root video 81, 2 3月 7 11:02 /dev/video2
crw-rw----+ 1 root video 81, 3 3月 7 11:02 /dev/video3
crw-rw----+ 1 root video 81, 4 3月 8 20:50 /dev/video4
crw-rw----+ 1 root video 81, 5 3月 8 20:50 /dev/video5
crw-rw----+ 1 root video 81, 6 3月 8 01:32 /dev/video6
You can see that Xiaoyu has 7 videos, so what should we do if we specify the video number when running? Let's look at the help information for this node.
$ ros2 run image_tools cam2image --help
Usage: cam2image [-h] [--ros-args [-p param:=value] ...]
Publish images from a camera stream.
Example: ros2 run image_tools cam2image --ros-args -p reliability:=best_effort
Options:
-h, --help Display this help message and exit
Parameters:
reliability Reliability QoS setting. Either 'reliable' (default) or 'best_effort'
history History QoS setting. Either 'keep_last' (default) or 'keep_all'.
If 'keep_last', then up to N samples are stored where N is the depth
depth Depth of the publisher queue. Only honored if history QoS is 'keep_last'. Default value is 10
frequency Publish frequency in Hz. Default value is 30
burger_mode Produce images of burgers rather than connecting to a camera
show_camera Show camera stream. Either 'true' or 'false' (default)
width Width component of the camera stream resolution. Default value is 320
height Height component of the camera stream resolution. Default value is 240
frame_id ID of the sensor frame. Default value is 'camera_frame'
Note: try running v4l2-ctl --list-formats-ext to obtain a list of valid values.
Unfortunately, the parameter video number is not specified.
solution
Check out Github to see that this feature will be added in foxy
the next version of .galactic
Use --ros-args -p device_id:=id号
to specify the video number.
source /opt/ros/galactic/setup.bash
ros2 run image_tools cam2image --ros-args -p device_id:=0
You can choose to install two versions at the same time ros2
and use it when running the camera galactic
. After the Xiaoyu test, the foxy version can still receive topic data normally.
Another way is to download the source code and compile it, and it can still be used normally under the foxy version~