6. Opencv application - face recognition

6.1. Overview

Wiki: http://wiki.ros.org/opencv_apps

Source code: https://github.com/ros-perception/opencv_apps.git

Most of the code was originally taken from https://github.com/Itseez/opencv/tree/master/samples/cpp

Function package: ~/software/library_ws/src/opencv_apps

The topic subscribed by this function package is [/image]. What we need to do is to open the camera node and write a node to convert the camera topic into [/image] and publish the [/image] topic.

The path of the node that opens the camera and publishes the topic [/image]:

The opencv_apps program provides various nodes that run opencv functions internally and publish the results to ROS topics. When using the opencv_apps program, you only need to run a launch file according to your own business needs, so you don't have to write program code for these functions.

ROS Wiki has relevant node analysis, topic subscription and topic publishing of corresponding nodes, and related parameter introductions. For details, please see ROS WiKi.

6.2, Use

Step 1: Start the camera

The [usb_cam-test.launch] file opens the [web_video_server] node by default, and you can directly use the [IP:8080] web page to view images in real time.

Step 2: Start the face recognition function

Almost every case of ros+opencv application has a parameter [debug_view], Boolean type, whether to use Opencv to display the image, which is displayed by default.

If it does not need to be displayed, set it to [False], for example

However, after starting in this way, some cases may not be displayed in other ways, because in the source code, some [debug_view] is set to [False], which will turn off image processing.

6.3, Display method

Enter the following command and select the corresponding topic

The system displays by default, no processing is required.

(Under the same LAN) Enter IP+port in the browser, for example:

For specific IP, use your current virtual machine IP.

6.4, Face recognition display

This case is to collect people's images for self-training and real-time recognition, and the steps are slightly complicated.

ParameterTypeDefaultAnalysis
~approximate_syncboolfalseSubscribe to the topic [camera_info] to obtain the default coordinate system ID, otherwise use the image information directly.
~queue_sizeint100Queue size for subscribing to topics
~model_methodstring"eigen"Face recognition method: "eigen", "fisher" or "LBPH"
~use_saved_databooltrueLoad training data from ~data_dir
~save_train_databooltrueSave training data to ~data_dir for retraining
~data_dirstring"~/opencv_apps/face_data"Path to save training data
~face_model_widthint190Width of training face images
~face_model_heightint90Height of training face images
~face_paddingdouble0.1Padding ratio for each face
~model_num_componentsint0The number of components of the face recognizer model (0 is considered unlimited)
~model_thresholddouble8000.0Face recognition model threshold
~lbph_radiusint1Radius parameter (only for LBPH method)
~lbph_neighborsint8Neighborhood parameter (only for LBPH method)
~lbph_grid_xint8Grid x parameter (only for LBPH method)
~lbph_grid_yint8Grid y parameter (only for LBPH method)
~queue_sizeint100Image subscriber queue size

Steps:

  1. First, enter the name of the person after the colon in the figure below: Yahboom

  2. Confirm the name: y

  3. Then put the face in the center of the image and click Confirm.

  4. Loop to add a photo: y, click Confirm.

  5. End the image collection, enter: n, and click OK.

  6. Close the launch file and restart.

If you need to enter the recognition, loop 1 to 5 in sequence until all the recognized people are entered, and then execute step 6.

image-20210903213928003

Step 3: Ensure that the face can be recognized

image-20210906103107655

Final recognition effect

image-20210906103143423