Working with the face-tracking ROS package

We have already created or copied the face_tracker_pkg package to the workspace and have discussed some of its important dependencies. Now, we are going to discuss what this package does exactly!

This package consists of an ROS node called face_tracker_node, which can track faces using OpenCV APIs and publish the centroid of the face to a topic. Here is a block diagram of the workings of face_tracker_node:

Block diagram of face_tracker_node

Let's discuss the things connected to face_tracker_node. One of the sections that may be unfamiliar to you is the face Haar classifier:

  • The face haar classifier: The Haar feature-based cascade classifier is a machine learning approach for detecting objects. This method was proposed by Paul Viola and Michael Jones in their paper, Rapid object detection using a boosted cascade of simple features, in 2001. In this method, a cascade file is trained using a positive and negative sample image, and after training, that file is used for object detection:
    • In our case, we are using a trained Haar classifier file along with OpenCV source code. You will get these Haar classifier files from the OpenCV data folder (https://github.com/opencv/opencv/tree/master/data). You can replace the desired Haar file according to your application. Here, we are using the face classifier. The classifier will be an XML file that has tags containing features of a face. Once the features inside the XML match, we can retrieve the Region Of Interest (ROI) of the face from the image using the OpenCV APIs. You can check the Haar classifier of this project from face_tracker_pkg/data/face.xml.
  • track.yaml: This is an ROS parameter file having parameters such as the Haar file path, input image topic, output image topic, and flags to enable and disable face tracking. We are using ROS configuration files because we can change the node parameters without modifying the face tracker source code. You can get this file from face_tracker_pkg/config/track.xml.
  • usb_cam node: The usb_cam package has a node publishing the image stream from the camera to ROS Image messages. The usb_cam node publishes camera images to the /usb_cam/raw_image topic, and this topic is subscribed to by the face tracker node for face detection. We can change the input topic in the track.yaml file if we require.
  • face_tracker_control: This is the second package we are going to discuss. The face_tracker_pkg package can detect faces and find the centroid of the face in the image. The centroid message contains two values, X and Y. We are using a custom message definition to send the centroid values. These centroid values are subscribed by the controller node and move the Dynamixel to track the face. The Dynamixel is controlled by this node.

Here is the file structure of face_tracker_pkg:

The file structure of face_tracker_pkg

Let's see how the face-tracking code works. You can open the CPP file at face_tracker_pkg/src/face_tracker_node.cpp. This code performs face detection and sends the centroid value to a topic.

We'll look at and understand some code snippets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.208