9. ROS+Opencv Application

9. ROS+Opencv Application9.1. Overview9.2, Use9.2.1, Start9.2.2, Display method9.2.3, Effect display9.3, Node9.3.1, Edge Detection Algorithm9.3.2, contour moment9.3.3, Face recognition

9.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: 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 [/image] topic:

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.

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

image-20210903181852659

9.2, Use

9.2.1, Start

Step 1: Start the camera

Add the [web_video_server] node to the [usb_cam-test.launch] file as required. After it is turned on, you can use the [IP:8080] web page to view the image in real time.

Step 2: Start the function of Opencv_apps

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

If you don't need to display, 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.

9.2.2, Display method

Enter the following command and select the corresponding topic

The system displays by default, and no processing is required.

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

9.2.3, Effect display

Move the screen and observe the phenomenon.

image-20210903215736978

image-20210903215933659

image-20210903220054380

The lower the threshold, the more lines there are, and the easier it is for the picture 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, and the system will automatically distinguish them.

image-20210903220528108

9.3, Node

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

9.3.1, Edge Detection Algorithm

ParameterTypeDefaultAnalysis
~use_camera_infobooltrueSubscribe to the topic [camera_info] to obtain the default coordinate system ID, otherwise use the image information directly.
~debug_viewboolfalseWhether to create a window to display the node image
~edge_typeint0Specify edge detection method: 0: Sobel operator, 1: Laplacian operator, 2: Canny edge detection
~canny_threshold1int100Specify the second canny threshold
~canny_threshold2int200Specify the first canny threshold
~apertureSizeint3The aperture size of the Sobel operator.
~apply_blur_preboolTrueWhether to apply blur() to the input image
~postBlurSizedouble3.2Input image aperture size
~apply_blur_postboolFalseWhether to apply GaussianBlur() to the input image
~L2gradientboolFalsecanny parameters
~queue_sizeint3queue size

image-20220219122359784

image-20210903212947694

9.3.2, contour moment

parametertypedefaultanalysis
~use_camera_infobooltrueSubscribe to the topic [camera_info] to obtain the default coordinate system ID, otherwise use the image information directly.
~debug_viewboolfalseWhether to create a window to display the node image
~canny_low_thresholdint0Canny edge detection low threshold
~queue_sizeint3Queue size

image-20220219122556604

9.3.3, Face recognition

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