RPI5-Hailo8L Low FPS

Hi. I am running the full detection example utilizing YOLOv8m on a RPI5 Hailo-8 with 26 TOPS. I have this FPS issue where I only get 30 FPS with my USB camera instead of 60 FPS which is supported by the camera running MJPG format at 640x480 as I’ve checked with v4l2-ctl --list-formats-ext -d /dev/video0. I tried to print out the output of GStreamerDetectionApp(app_callback, user_data) as shown in the code and it indeed is using 30 FPS. Is there any way that I can modify it to 60 FPS? Thanks.

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib

import os
import time
import cv2
import numpy as np
import hailo
from datetime import datetime

from hailo_apps_infra.hailo_rpi_common import (
    get_caps_from_pad,
    get_numpy_from_buffer,
    app_callback_class,
)
from hailo_apps_infra.detection_pipeline import GStreamerDetectionApp


# Custom class to hold frame count, FPS, and resolution
class user_app_callback_class(app_callback_class):
    def __init__(self):
        super().__init__()
        self.frame_times = []
        self.last_time = time.time()
        self.width = 640   # Force resolution width
        self.height = 480  # Force resolution height

    def calculate_fps(self):
        now = time.time()
        self.frame_times.append(now)
        self.frame_times = [t for t in self.frame_times if now - t <= 1.0]
        return len(self.frame_times)


# Callback function called for each frame
def app_callback(pad, info, user_data):
    buffer = info.get_buffer()
    if buffer is None:
        return Gst.PadProbeReturn.OK

    user_data.increment()
    fps = user_data.calculate_fps()

    # Get caps and frame
    format, width, height = get_caps_from_pad(pad)
    print("Incoming format:", format)
    frame = None
    if user_data.use_frame and format and width and height:
        frame = get_numpy_from_buffer(buffer, format, width, height)

    # Resize frame to 480p if needed
    if frame is not None:
        frame = cv2.resize(frame, (user_data.width, user_data.height))

    # Get detections
    roi = hailo.get_roi_from_buffer(buffer)
    detections = roi.get_objects_typed(hailo.HAILO_DETECTION)

    car_count = 0
    for det in detections:
        label = det.get_label()
        confidence = det.get_confidence()
        if label == "car":
            car_count += 1

    timestamp_str = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    if user_data.use_frame and frame is not None:
        frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        cv2.putText(frame, f"FPS: {fps}", (10, 30),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
        cv2.putText(frame, f"Cars: {car_count}", (10, 60),
                    cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
        cv2.putText(frame, f"{timestamp_str}", (10, user_data.height - 20),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)
        user_data.set_frame(frame)

    print(f"Frame {user_data.get_count()} | Cars: {car_count} | FPS: {fps} | Time: {timestamp_str}")
    return Gst.PadProbeReturn.OK


if __name__ == "__main__":
    user_data = user_app_callback_class()
    app = GStreamerDetectionApp(app_callback, user_data)
    print(app)
    app.run()

Hi,

Please try to set the --frame_rate parameter: hailo-apps-infra/doc/user_guide/running_applications.md at main · hailo-ai/hailo-apps-infra · GitHub

Thanks for the reply. I did

import os
import subprocess

os.chdir("/home/ren/hailo-rpi5-examples")
subprocess.run("source setup_env.sh && python3 basic_pipelines/detection_zh.py --input usb --frame-rate 60",shell=True, executable="/bin/bash")

But there’s an error:
usage: detection_zh.py [-h] [–input INPUT] [–use-frame] [–show-fps]
[–arch {hailo8,hailo8l}] [–hef-path HEF_PATH]
[–disable-sync] [–disable-callback] [–dump-dot]
[–labels-json LABELS_JSON]
detection_zh.py: error: unrecognized arguments: --frame-rate 60

Hi,
The addition of the argument --frame-rate is from our latest release (last week) which is available here:

For the older version, it’s possible to modify in file detection_pipeline.py (located in the infrastructure repository ) the call to SOURCE_PIPELINE function by adding to it input argument frame_rate and then modifying the function similar to the current newest version of it: hailo-apps-infra/hailo_apps/hailo_app_python/core/gstreamer/gstreamer_helper_pipelines.py at main · hailo-ai/hailo-apps-infra · GitHub