RPI5 + Hailo8L Object counting python

Hello community,
I need your advice to solve my project task.

I have a Raspberry Pi 5 + Hailo8L AI kit, and I am running the RPi-examples, all working perfectly.
Now, I need to modify a Python script to count items using the RPi camera.
Could you recommend some solutions or advice on how to implement this with the Hailo8L?
Currently, I am using YOLOv10 for object counting with the RPi, but the FPS is too slow. I found that the Hailo8L could be a very good solution for this task.

Thank you!

Hey @device.ai,

Welcome to the Hailo Community! We’re excited to have you here. Let’s get you started with some resources to help you integrate the Hailo API with your Raspberry Pi camera setup:

  1. Hailo Python API Examples:
    Check out these helpful examples to understand how to use the Hailo Python API:

  2. Pre-trained YOLO Model:
    You can find a ready-to-use YOLO model here:
    hailo_model_zoo/docs/public_models/HAILO8L/HAILO8L_object_detection.rst at master · hailo-ai/hailo_model_zoo · GitHub

  3. Next Steps:
    With these resources, you’ll need to update your current script to:
    a) Interface with the Raspberry Pi camera
    b) Integrate the Hailo model for processing

If you run into any issues or have questions during the integration process, don’t hesitate to ask. We’re here to help!

Good luck with your project!

Regards,
Omri

@device.ai

I can recommend a simple step in case you just want to count objects in the frame.

You can use object detection example (shared above) and add the hailotracker gstreamer element that tracks the object and assign id.

gst-launch-1.0 \
libcamerasrc ! \
video/x-raw, format=RGB, width=640, height=480 ! \
queue name=queue_src_scale leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
videoscale ! \
video/x-raw, format=RGB,  width=640, height=640, framerate=30/1 ! \
queue name=queue_hailonet leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
videoconvert n-threads=3 ! \
hailonet hef-path=/home/admin/Desktop/yolov8s_h8l.hef batch-size=4 nms-score-threshold=0.3 nms-iou-threshold=0.45 output-format-type=HAILO_FORMAT_TYPE_FLOAT32 force-writable=true ! \
queue name=queue_hailofilter leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
hailofilter so-path=/lib/aarch64-linux-gnu/hailo/tappas/post_processes/libyolo_hailortpp_post.so qos=false ! \
queue name=queue_hailotracker leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
hailotracker ! \
queue name=queue_hailooverlay leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
hailooverlay ! \
queue name=queue_videoconvert leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
videoconvert n-threads=3 qos=false ! \
queue name=queue_hailo_display leaky=no max-size-buffers=3 max-size-bytes=0 max-size-time=0 ! \
fpsdisplaysink video-sink=xvimagesink name=hailo_display sync=false text-overlay=true signal-fps-measurements=true

I am assuming you have installed the hailo related softwares on your device. Otherwise this code will not work on your device.
Download the yolov8s.hef from here https://hailo-model-zoo.s3.eu-west-2.amazonaws.com/ModelZoo/Compiled/v2.13.0/hailo8l/yolov8s.hef and place hef on desktop. You can also change path in the code.
Run on raspberry pi terminal to see the tracker result.

This gstreamer code can be used with object detection hailo-rpi5-examples/basic_pipelines/detection_pipeline.py at 123e6755d88583ccee6ebd4123de41b6868f1239 · hailo-ai/hailo-rpi5-examples · GitHub
to build pipeline string and you can use this function to handle detections and counting hailo-rpi5-examples/basic_pipelines/detection.py at 123e6755d88583ccee6ebd4123de41b6868f1239 · hailo-ai/hailo-rpi5-examples · GitHub.

You can use hailotracker assigns id to each detections you can get the id and count unique items.