I’ve trying to implement a multi stream pipeline using GStreamer and Python, where I have the hailotracker detecting the objects, and I would like to use the detection information inside a callback function.
I tried the pipeline below, but the callback isn’t happening. Is that correct? Should I use the hailopython in another way?
I modified the GStremer pipeline as showed on previous post, the entire detection.py file a kept the same. The callback_template.py is below:
# This is a template for a callback function that can be used with hailo detection.py
# Note that you must be in hailo virtual environment to run use these imports
import hailo
# Importing VideoFrame before importing GST is must
from gsthailo import VideoFrame
from gi.repository import Gst
import numpy as np
import sys
import time
import numpy as np
def run(video_frame: VideoFrame):
global frame
print("Hello!")
# get the detections from the frame
detections = video_frame.roi.get_objects_typed(hailo.HAILO_DETECTION)
print("# detection: ", len(detections))
if (detections is None) or (len(detections) == 0):
return Gst.FlowReturn.OK
# Get the video info from the video frame
width = video_frame.video_info.width
height = video_frame.video_info.height
# Get the numpy array from the video frame
with video_frame.map_buffer() as map_info:
# Create a NumPy array from the buffer data
numpy_frame_ro = VideoFrame.numpy_array_from_buffer(map_info, video_info=video_frame.video_info)
# Note this is a read only copy of the frame
# If you want to modify the frame you need to make a copy
# numpy_frame = numpy_frame_ro.copy()
# Note the modifing the frame will not change the original frame (for this you'll need to replave the buffer data)
# parse the detections
for detection in detections:
label = detection.get_label()
bbox = detection.get_bbox()
confidence = detection.get_confidence()
#print(label)
if (label == "car" or
label == "bus" or
label == "truck" or
label == "motorcycle"):
track = detection.get_objects_typed(hailo.HAILO_UNIQUE_ID)
track_id = track[0].get_id()
string_to_print = (f"Detection: {label} {confidence} {track_id}")
print(string_to_print)
print("")
return Gst.FlowReturn.OK
# This function will be called when the pipeline is closed
def close():
print("Python close function called")
When the “hailopython” is right after “hailotracker”, nothing happens, even the “Hello!” doesn’t happen. When I put “hailopython” after “compositor” the “Hello!” and the number of detections is 0.
I’m using the last version of docker image on x86 device with Hailo8L M.2
Yeah, I know that, I made that works previously. But as I mentioned my application have multiple cameras, so I need to create a multi stream pipeline. However it doesn’t work when I use multi stream.