ViSP library allows to grab images from cameras using specific classes depending on the underlaying camera drivers. Thus it allows to grab images from firewire or usb cameras using either vp1394TwoGrabber or vpV4l2Grabber classes.
In the next section Image grabbing using ViSP, we recall how ViSP can be used to grab images. Then in section How to grab images from ROS we introduce vpROSGrabber that can be used to grab images published by a ROS camera node.
Let us consider the following classical ViSP example provided in tutorial-visp-grabber-1394.cpp and given here after. Thanks to the vp1394TwoGrabber class provided in ViSP library we are able to grab images from a firewire camera.
This example is described in ViSP image frame grabbing tutorial pages.
To build this example ViSP should be installed. If not, depending on your ROS distro it could be done like:
sudo apt-get install ros-<distro>-visp
ViSP could also be installed from Debian package:
sudo apt-get install libvisp-dev
Now to build this example, just run the following commands in a terminal:
cd ~/catkin_ws/src/visp_ros/tutorial/grabber/visp cmake . make
To run this example, connect a firewire camera hit in the same terminal:
./tutorial-visp-grabber-1394
Let us consider this other ViSP example provided in tutorial-visp-grabber-v4l2.cpp and given here after. Thanks to the vpV4l2Grabber class we are able this time to grab images from an usb camera.
To run this example, connect an usb camera and hit in the same terminal:
./tutorial-visp-grabber-v4l2
Depending on the camera that is used, you may adapt your code to use the right camera driver. This may be fastidious. That is why, in the next section we show how to use a more generic grabber class based on ROS and called vpROSGrabber. It just subscribes to a camera topic.
visp_ros package provides vpROSGrabber class that is able to handle any images published on a ROS topic. This class is interesting since it can be used as a classical ViSP class without knowing ROS very well since it makes ROS transparent for the user.
To be able to grab images published by a ROS camera node and display these images, the previous example need to be modified as in tutorial-ros-grabber.cpp given below:
Compared to the example based fully on ViSP and given in the Image grabbing using ViSP, once declared :
we simply indicate which is the image topic name:
If camera_info parameters are provided including distorsion, the image is rectified:
Next as usual with ViSP, the device is opened
and a new image is acquired using:
Now to build this example, install visp_ros catkin package and setup the environment as described in the tutorial: Howto build and install visp_ros.
source ~/catkin_ws/install/setup.bash
Build the example by entering the following commands in a terminal:
cd ~/catkin_ws/src/visp_ros/tutorial/grabber/ros cmake . make
The previous example can work with images published by camera1394 node. To this end let us consider the following launch file named "camera-firewire.launch" where images are published on topic /camera/image_raw and camera parameters on topic /camera/camera_info.
When launched, you will see the images:
cd ~/catkin_ws/src/visp_ros/tutorial/grabber/ros roslaunch camera-firewire.launch ./tutorial-ros-grabber --use-camera-info
The previous example can also work with images published by usb_cam node. To this end let us consider the following launch file named "camera-usb.launch" where images are published on topic /camera/image_raw and camera parameters on topic /camera/camera_info.
When launched, you will see the images:
cd ~/catkin_ws/src/visp_ros/tutorial/grabber/ros roslaunch camera-usb.launch --use-camera-info ./tutorial-ros-grabber