4. ROS+Opencv application

4. ROS+Opencv application4.2. Use4.2.1. Startup4.2.2. Display methods4.2.3. Effect display4.3 Nodes4.3.1 Edge detection algorithm4.3.2. Contour moment4.3.3. Face recognition

4.1, Overview

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

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

Function package: ~/orbbec_ws/src/opencv_apps

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

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

ROS Wiki has the relevant node analysis, the corresponding node topic subscription and topic publication, related parameters introduction, etc. See the ROS WiKi for details.

image-20210903181852659

4.2. Use

4.2.1. Startup

Step 1: Start the camera

If the page cannot be viewed, check whether there is no [web_video_server] node, if not, run the following command

Step 2: Start the Opencv_apps function

Almost every function case will have a parameter [debug_view], Boolean type, whether to use Opencv display image, the default display.

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

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

4.2.2. Display methods

Enter the following command to select a topic

It is displayed by default. No action is required.

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

4.2.3. Effect display

Move the screen and observe the phenomenon.

image-20210903215736978

image-20210903215933659

image-20210903220054380

The lower the threshold, the more lines, and the easier it is to get stuck.

image-20210903220336691

The faster the camera moves, the larger the radius of the circle.

image-20210903220246064

Use the mouse to select different objects, the system will automatically distinguish.

image-20210903220528108

4.3 Nodes

Each case in this section will have a topic for subscribing images and publishing images.

4.3.1 Edge detection algorithm

ParametersTypesDefaultParsing
~use_camera_infobooltrueSubscribe to [camera_info] to get the default coordinate ID, otherwise use the image information directly.
~debug_viewboolfalseWhether to create a window to display the node image
~edge_typeint0Specify edge detection methods: 0: Sobel operator, 1: Laplacian operator, 2: Canny edge detection
~canny_threshold1int100Specifies the second canny threshold
~canny_threshold2int200Specifies the first canny threshold
~apertureSizeint3The aperture size of a Sobel operator.
~apply_blur_preboolTrueWhether blur() is applied to the input image
~postBlurSizedouble3.2Enter the image aperture size
~apply_blur_postboolFalseWhether to apply GaussianBlur() to the input image
~L2gradientboolFalsecanny parameters
~queue_sizeint3Queue size

image-20210903212838217

image-20210903212947694

4.3.2. Contour moment

ParametersTypesDefaultParsing
~use_camera_infobooltrueSubscribe to [camera_info] to get the default coordinate ID, otherwise use the image information directly.
~debug_viewboolfalseWhether to create a window to display the node image
~canny_low_thresholdint0Canny edge detects a low threshold
~queue_sizeint3Queue size

image-20210903212751344

4.3.3. Face recognition

This case is through the real-time collection of people's images of autonomous training, real-time recognition, the steps are slightly complicated.

ParametersTypesDefaultParsing
~approximate_syncboolfalseSubscribe to [camera_info] to get the default coordinate ID, otherwise use the image information directly.
~queue_sizeint100The queue size for subscribing to a topic
~model_methodstring"eigen"Face recognition method: "eigen", "fisher" or "LBPH"
~use_saved_databooltrueLoad the training data from the ~data_dir path
~save_train_databooltrueSave the training data to the ~data_dir path for retraining
~data_dirstring"~/opencv_apps/face_data"Save the training data path
~face_model_widthint190Train the width of the face image
~face_model_heightint90Train the height of the face image
~face_paddingdouble0.1The fill ratio for each face
~model_num_componentsint0Number of components in the face recognizer model (0 is considered unlimited)
~model_thresholddouble8000.0Face recognition model threshold
~lbph_radiusint1Radius parameters (for LBPH method only)
~lbph_neighborsint8Neighborhood parameters (for LBPH method only)
~lbph_grid_xint8Grid x parameter (for LBPH method only)
~lbph_grid_yint8Grid y parameter (for LBPH method only)
~queue_sizeint100Image subscriber queue size

Operation steps:

  1. First, after the colon in the picture below, enter the name of the person: Yahboom
  2. Confirm name: y
  3. Then place the face in the center of the image and click OK.
  4. Add a photo in the loop: y, click confirm.
  5. To finish collecting pictures, enter n and click OK.
  6. Close the launch file and restart.

If it is necessary to enter the knowledge, cycle 1 to 5 in turn until all the identification personnel are entered, and then perform the sixth step.

image-20210903213928003

Step 3: Make sure you can recognize faces

image-20210906103107655

Final recognition effect

image-20210906103143423