9. ROS+Opencv application

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

Feature pack: ~/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, write a node that converts the camera topic into a [/image] node, and publish the [/image] topic.

The path to the node that enables the camera and publishes the [/image] topic:

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

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

image-20210903181852659

9.2. Use

9.2.1. Start

Step 1: Start camera

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

Step 2: Start the function of Opencv_apps

<PI5 needs to open another terminal and enter the same docker container

image-20240408144126098

Almost every functional case will have a parameter [debug_view], Boolean type, whether to use Opencv to display the picture, which is displayed by default.

Set to [False] if no display is required, for example

However, after this is started, some cases cannot 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 to select the corresponding topic

The system defaults to display, no need to do anything.

(same as the local area network) 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, and the easier the picture gets 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 of subscribing to images and publishing images.

9.3.1. edge detection algorithm

parametertypedefaultParse
~use_camera_infobooltrueSubscribe to the topic [camera_info] to get the default coordinate system ID, otherwise use the image information directly.
~debug_viewboolfalsewhether to create a window to display the node image
~edge_typeint0Specify the 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.2Enter the image aperture size
~apply_blur_postboolFalsewhether to apply GaussianBlur() to the input image
~L2gradientboolFalseParameters of canny
~queue_sizeint3queue size

image-20220219122359784

image-20210903212947694

9.3.2. Contour moment

parametertypedefaultParse
~use_camera_infobooltrueSubscribe to the topic [camera_info] to get 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 self-training and real-time recognition through real-time collection of human images, and the steps are slightly complicated.

parametertypedefaultParse
~approximate_syncboolfalseSubscribe to the topic [camera_info] to get the default coordinate system ID, otherwise use the image information directly.
~queue_sizeint100Queue size for subscribing to topics
~model_methodstring"eigen"Methods of face recognition: "eigen", "fisher" or "LBPH"
~use_saved_databooltrueLoad training data from ~data_dir path
~save_train_databooltrueSave the training data to the ~data_dir path for retraining
~data_dirstring"~/opencv_apps/face_data"Save training data path
~face_model_widthint190width of training face images
~face_model_heightint90height of training face images
~face_paddingdouble0.1Fill 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 character name after the colon in the following figure: Yahboom

  2. Confirm the name: y

  3. Then place the face in the center of the image and click OK.

  4. Add a photo cyclically: y, click OK.

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

  6. Close the launch file and restart.

If you need to enter the recognized recognition, cycle 1 to 5 in turn, until all recognition personnel are completed, and then perform the sixth step.

image-20210903213928003

Step 3: To ensure that the face can be recognized

image-20210906103107655

The final recognition effect

image-20210906103143423