The following edits extend the object detection examples in ’hailo-rpi5-examples’ to optionally read from a RTSP stream topic and to write the pipeline detection stream to an RTSP Server in parallel to the output on the rpi5 screen.
Therefore edit the file hailo_rpi_common.py
file and add the following lines:
- read from RTSP stream:
def get_source_type(input_source):
# This function will return the source type based on the input source
# return values can be "file", "rpi", "rtsp" or "usb"
if input_source.startswith("/dev/video"):
return 'usb'
else:
if input_source.startswith("rpi"):
return 'rpi'
elif input_source.startswith("rtsp"): #check for streaming from a rtsp source stream
return 'rtsp'
else:
return 'file'
To read from a RTSP Stream, choose option:
--input rtsp://<myRTSP-Server address>:8554/my_stream
- Change the following lines to write detection pipeline results to an RTSP Server:
# Construct the display pipeline string
display_pipeline = (
f'{QUEUE(name=f"{name}_hailooverlay_q")} ! '
f'hailooverlay name={name}_hailooverlay ! '
f'tee name=rtspstream ! ' # Add a tee after hailooverlay
f'{QUEUE(name=f"{name}_videoconvert_q")} ! '
f'videoconvert name={name}_videoconvert n-threads=2 qos=false ! '
f'{QUEUE(name=f"{name}_q")} ! '
f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '
f'rtspstream. ! ' # Branch for RTSP stream
f'videoconvert ! video/x-raw,format=I420 ! '
f'x264enc tune=zerolatency bitrate=500 speed-preset=superfast ! '
f'video/x-h264,profile=baseline ! '
f'rtspclientsink location=rtsp://localhost:8554/mystream '
)
return display_pipeline