5. Color tracking

5. Color tracking5.1. Description of program functions5.2. Program Code Reference Path5.3.1. Application Startup and Web page Display5.3.2. Color Recognition and tracking5.3.3 Dynamic parameter tuning5.3.4. View the node topic communication graph5.4. Core Source Code Parsing5.4.1. color_identify. Py5.4.2. color_track.py

5.1. Description of program functions

After the program starts, the image published by the camera is displayed on the web page. Select the color through the mouse box, the car will lock this color, press the [space] key to enter the tracking mode. The car will maintain a distance of 1 meter from the tracked object, and always ensure that the tracked object remains in the center of the picture.

In addition, the [L1] button on the handle locks/turns on the car's motion controls. When motion control is enabled, the function is locked; This function can be turned on when the motion control is locked.

5.2. Program Code Reference Path

The node or launch file is explained as follows:

5.3.1. Application Startup and Web page Display

After SSH connects to the car, terminal input,

Open the browser on the PC side (note that the computer and the Rising Sun network must be in the same LAN), enter the URL: car IP:9999, for example, my car IP is 192.168.2.67, enter the URL in the browser on the virtual machine side to open the ROSboard webpage:

Select three topics: /camera/color/image_raw, /astra_binary, and /astra_roi. Only the RGB images published by the camera are displayed at this time, and no data is published for /astra_binary and /astra_roi topics.

1684915860559

5.3.2. Color Recognition and tracking

Press [i] or [I] on the page to enter the Identify mode, click the mouse frame twice in the RGB image to select a region (this region can only have one color).

image-20230610120618675

After the box is selected, the following screen will appear: /astra_binary displays the binary image after color selection; /astra_roi displays the HSV value range of the color and the center point of the color area.

image-20230610120642031

Press the [space] key in the page to enter the tracking mode, and the car will move to the position of 1 meter away from the target; Press the [q] key in the page to cancel the tracking; Press [r] in the page to clear the color selection, then press [i] to re-select the color.

image-20230610120724836

Move the object slowly, the car will follow, and keep a distance of 1 meter.

The interaction between this function and the keyboard is as follows:

buttonfunctionRemarks
【r】or【R】color recognitioncolor selection mode, the program starts to enter the default mode
【space】Color trackingthe car is tracked to the position |, 1 meter away from the target
【q】or【Q】Stop the motionstop the motion and keep the HSV range of colors
【i】or【I】Resetstops motion while clearing the HSV range of color

5.3.3 Dynamic parameter tuning

Virtual machine terminal input,

1684918964832

The adjustable parameters are the PID of the linear speed of the car, the angular speed, and the tracking distance.

After modifying the parameters, press Enter or click the blank area of the GUI to write the parameter values.

5.3.4. View the node topic communication graph

Open the VM terminal and run the following command to view topic communication between nodes:

1684923124179

5.4. Core Source Code Parsing

5.4.1. color_identify. Py

This program mainly has the following functions:

Part of the core code is as follows,

5.4.2. color_track.py

This program mainly has the following functions: receive /Current_point and depth image topic data, calculate the speed size, and then publish the speed data.

Part of the code is as follows,