Im trying to know the position of detection object in the frame. I need help to understand the format of HailoBbox.
My result:
Frame count: 186
Detection 0: Label = Spantile, BBox = <hailo.HailoBBox(140733461937616)>, Confidence = 0.97
Total detections: 1
Frame count: 187
Detection 0: Label = Spantile, BBox = <hailo.HailoBBox(140733461935024)>, Confidence = 0.97
Total detections: 1
Frame count: 188
Detection 0: Label = Spantile, BBox = <hailo.HailoBBox(140733461937584)>, Confidence = 0.97
Total detections: 1
Frame count: 189
Detection 0: Label = Spantile, BBox = <hailo.HailoBBox(140733461935152)>, Confidence = 0.97
Total detections: 1
FPS: 30.10, Droprate: 0.00, Avg FPS: 30.25
My detection code:
def app_callback(pad, info, user_data):
# Get the GstBuffer from the probe info
buffer = info.get_buffer()
# Check if the buffer is valid
if buffer is None:
return Gst.PadProbeReturn.OK
# Using the user_data to count the number of frames
user_data.increment()
string_to_print = f"Frame count: {user_data.get_count()}\n"
# Get the caps from the pad
format, width, height = get_caps_from_pad(pad)
# Get the video frame from the buffer if needed
frame = None
if user_data.use_frame and format is not None and width is not None and height is not None:
frame = get_numpy_from_buffer(buffer, format, width, height)
# Get the detections from the buffer
roi = hailo.get_roi_from_buffer(buffer)
detections = roi.get_objects_typed(hailo.HAILO_DETECTION)
# Parse the detections and output detailed info
detection_count = 0
for detection in detections:
label = detection.get_label()
bbox = detection.get_bbox() # (x_min, y_min, x_max, y_max)
confidence = detection.get_confidence()
string_to_print += f"Detection {detection_count}: Label = {label}, BBox = {bbox}, Confidence = {confidence:.2f}\n"
detection_count += 1
if detection_count > 0:
string_to_print += f"Total detections: {detection_count}\n"
# If frame is used, annotate and convert it
if user_data.use_frame and frame is not None:
cv2.putText(frame, f"Detections: {detection_count}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
user_data.set_frame(frame)
print(string_to_print)
return Gst.PadProbeReturn.OK