Object Detection

This example demonstrates object detection. It uses the YOLOv6n model by default. It also supports the yolov8s and yolox_s_leaky models. It uses Hailo's NMS (non-maximum suppression) layer as part of the HEF file, so all detection networks compiled with NMS can use the same code.

1. Detect the video

Terminal input,

Then enter the command to enter the virtual environment

Enter the command. Run the video to detect

The .mp4 suffix indicates the path of the video

image-20240809174211471

To close the appearance, you can press ctrl+c.

What's in this example:

Custom callback class:

This is an example of a custom callback class. It can be used to send user defined data to the callback function. It inherits from app_callback_class and can be extended with user defined variables and functions. In this example, we added a variable and a function to the class. These are used in the callback function when under the flag --use-frame. These values are then displayed on the user frame. --use-frame

Application callback function:

In this function, we see an example of how to parse metadata. Each Gstreamer buffer contains objects. This object is the root of all Hailo metadata objects attached to this buffer. All detections are read and their labels, bounding boxes and confidences are read. In this example, we assume that there is a "person" near you. All detections are parsed and the number of people detected is counted. The information of each detected person is printed to the terminal. If the flag is used, the frame is extracted from the buffer and displayed. The number of detected people is displayed on the frame. In addition, user defined data is displayed on the frame. HAILO_DETECTION``HAILO_ROI``--use-frame

2. Real-time camera image detection

In the virtual environment terminal, enter the following command. By default, these examples run using a USB camera (/dev/video0). You can use the --input flag to change the input source according to the real-time situation.

image-20240809175340443

If the camera does not display properly, you can check which video devices are available by running the following command:

You can test that the camera is working properly by running the following command:

If you get an error, try another device such as /dev/video2.

3. Use the retrained model (taking QR code recognition as an example)

Note: (If you need to use your own trained model for acceleration, please follow the tutorial below and convert it to the hef format required by the hailo board)Retraining example

This application includes support for using a retrained detection model. The model should be compiled with HailoRT NMS post-processing (HailortPP). To use a custom model, you can load its HEF using the flag. The default labels used by our model are COCO labels (80 categories). If you are using a custom model with different labels, you can use this flag to load the label file. For example, (using RPi camera input):

Among them, yolov8s-hailo8l-barcode.hef is the hef format converted after retraining, output:

image-20240809175809401

 

Troubleshooting and known issues

If the camera case suddenly stops working, you can refer to the following solution steps. If it still doesn't work, you need to restart the Raspberry Pi.