RPI5-Hailo8L C/C++ YOLOv8 sample code

Hi,
I’m building security camera software, and I want a C/C++ API for running Object Detection, preferably with the Ultralytics YOLO family of models. I’ve found example code inside Hailo-Application-Code-Examples/runtime/cpp/detection/yolov8/Rockchip at main · hailo-ai/Hailo-Application-Code-Examples · GitHub
However, attempting to run this on a Rpi5-Hailo8L causes a segfault.

It dies inside yolov8_postprocess.cpp, inside get_boxes_and_scores(), because it assumes that tensors.size() is a multiple of 2. But on my machine, I’m getting tensors.size() = 1.

Despite this example being labelled RockChip, it does seem to detect the PCIe attached Hailo8L.

Is there a better example to start from?

You can use Raspberry Pi’s YOLOv8 demo in rpicam-apps as a starting point.

Instructions on running this demo can be found at:
https://www.raspberrypi.com/documentation/accessories/ai-kit.html#object-detection

The config file is at:

The source code is available at:

Thanks, I’ll give that a try

That code looks OK, but I’m getting a linker error that I can’t explain.
Here’s my hello world app:

#include “hailo/hailort.h”
int main(int argc, char** argv) {
hailo_create_vdevice(nullptr, nullptr);
return 0;
}

And when I compile it with:
g++ -o yolohailo -lhailort yolov8.cpp

I get a linker error:
/usr/bin/ld: /tmp/ccbsStTd.o: in function main': yolov8.cpp:(.text+0x18): undefined reference to hailo_create_vdevice’
collect2: error: ld returned 1 exit status

Using nm to inspect the symbols inside /usr/lib/libhailort.so, I get:
nm -C --defined-only libhailort.so | rg hailo_create_vdevice
00000000000bc2d8 T hailo_create_vdevice

So all the symbols seem present in libhailort.so, and there is only one libhailort.so on my system.

What am I missing?

OKAY!! My linker problem was that I specified the library “-lhailort” BEFORE my source files. If I instead do “g++ -o yolohailo yolov8.cpp -lhailort”, then it compiles.

In case anybody finds this useful, I’ve created a minimal C++ demo repo that does YOLOv8 inference in C++:

github(dot)com/bmharper/hailo-rpi5-yolov8

1 Like

thank you
are you can modify the code for read images or webcam feed via opencv not with “stb_image.h” ?

I might get around to it, but not sure I’ll have time

Hello Rogojine,
Did you manage to modify thé code to read the webcam stream via opencv note with “stb_image.h” ?

Sorry, I haven’t done that. I think ChatGPT could make that change for you though.