Creating face tracker ROS packages
Let's start creating a new workspace for keeping the entire ROS project files for this book. You can name the workspace ros_robotics_projects_ws
.
Download or clone the source code of the book from GitHub using the following link.
$ git clone https://github.com/qboticslabs/ros_robotics_projects
Now, you can copy two packages named face_tracker_pkg
and face_tracker_control
from the chapter_2_codes
folder into the src
folder of ros_robotics_projects_ws
.
Do a catkin_make
to build the two project packages!
Yes, you have set up the face tracker packages on your system, but what if you want to create your own package for tracking? First, delete the current packages that you copied to the src
folder, and use the following commands to create the packages.
Switch to the src
folder:
$ cd ~/ros_robotics_projects_ws/src
The next command will create the face_tracker_pkg
ROS package with the main dependencies, such as cv_bridge
, image_transport
, sensor_msgs
, message_generation
, and message_runtime
.
We are including these packages because these packages are required for the proper working of the face tracker package. The face tracker package contain ROS nodes for detecting faces and determining the centroid of the face:
$ catkin_create_pkg face_tracker_pkg roscpp rospy cv_bridge image_transport sensor_msgs std_msgs message_runtime message_generation
Next, we need to create the face_tracker_control
ROS package. The important dependency of this package is dynamixel_controllers
. This package is used to subscribe to the centroid from the face tracker node and control the Dynamixel in a way that the face centroid will always be in the center portion of the image:
$ catkin_create_pkg face_tracker_pkg roscpp rospy std_msgs dynamixel_controllers message_generation
Okay, you have created the ROS packages on your own. What's next? Before starting to code, you may have to understand some concepts of OpenCV and its interface with ROS. Also, you have to know how to publish ROS image messages. So let's master the concepts first.
The interface between ROS and OpenCV
Open Source Computer Vision (OpenCV) is a library that has APIs to perform computer vision applications. The project was started in Intel Russia, and later on, it was supported by Willow Garage and Itseez. In 2016, Itseez was acquired by Intel.
Note
OpenCV website: http://opencv.org/
Willow Garage: http://www.willowgarage.com/
Itseez: http://itseez.com
OpenCV is a cross-platform library that supports most operating systems. Now, it also has an open source BSD license, so we can use it for research and commercial applications. The OpenCV version interfaced with ROS Kinetic is 3.1. The 3.x versions of OpenCV have a few changes to the APIs from the 2.x versions.
The OpenCV library is integrated into ROS through a package called vision_opencv
. This package was already installed when we installed ros-kinetic-desktop-full
in Chapter 1, Getting Started with ROS Robotics Application Development.
The vision_opencv
metapackage has two packages:
cv_bridge
: This package is responsible for converting the OpenCV image data type (cv::Mat
) into ROSImage
messages (sensor_msgs/Image.msg
).image_geometry
: This package helps us interpret images geometrically. This node will aid in processing such as camera calibration and image rectification.
Out of these two packages, we are mainly dealing with cv_bridge
. Using cv_bridge
, the face tracker node can convert ROS Image
messages from usb_cam
to the OpenCV equivalent, cv::Mat
. After converting to cv::Mat
, we can use OpenCV APIs to process the camera image.
Here is a block diagram that shows the role of cv_bridge
in this project:
Figure 14: The role of cv_bridge
Here, cv_bridge
is working between the usb_cam
node and face-tracking node. We'll learn more about the face-tracking node in the next section. Before that, it will be good if you get an idea of its working.
Another package we are using to transport ROS Image
messages between two ROS nodes is image_transport
(http://wiki.ros.org/image_transport). This package is always used to subscribe to and publish image data in ROS. The package can help us transport images in low bandwidth by applying compression techniques. This package is also installed along with the full ROS desktop installation.
That's all about OpenCV and the ROS interface. In the next section, we are going to work with the first package of this project: face_tracker_pkg
.