Hello everyone,
Im working on the hailo rpi5 example for object detection GitHub - hailo-ai/hailo-rpi5-examples at 0c70ac577677d997c0c0b38290670466ed3fe9a2
For the moment im able to launch the detection with my raspberry pi module 2 camera. So a window is opening with the video feedback and the detection.
But i would like to have this detection on a webpage using flask. I think that i have to change the display sink in the display_pipeline. Thats why i changed the line
f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '```
by the line :
fâjpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000â
in this code :
def DISPLAY_PIPELINE(video_sink=âautovideosinkâ, sync=âtrueâ, show_fps=âfalseâ, name=âhailo_displayâ):
ââ"
Creates a GStreamer pipeline string for displaying the video.
It includes the hailooverlay plugin to draw bounding boxes and labels on the video.
Args:
video_sink (str, optional): The video sink element to use. Defaults to 'autovideosink'.
sync (str, optional): The sync property for the video sink. Defaults to 'true'.
show_fps (str, optional): Whether to show the FPS on the video sink. Should be 'true' or 'false'. Defaults to 'false'.
name (str, optional): The prefix name for the pipeline elements. Defaults to 'hailo_display'.
Returns:
str: A string representing the GStreamer pipeline for displaying the video.
"""
# Construct the display pipeline string
display_pipeline = (
f'{OVERLAY_PIPELINE(name=f"{name}_overlay")} ! '
f'{QUEUE(name=f"{name}_videoconvert_q")} ! '
f'videoconvert name={name}_videoconvert n-threads=2 qos=false ! '
f'{QUEUE(name=f"{name}_q")} ! '
f'jpegenc ! rtpjpegpay ! udpsink host=127.0.0.1 port=5000'
#f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '
)
return display_pipeline
So i think that by doing this when i launch the code using python detection.py --input rpi i create a udp server host=127.0.0.1 port=5000 instead of creating a video output.
So to have the video on the web page using flask i need to connect my flask webpage as a client to this udp host server.
But i dont know where to integrate this in the code of detection.py or on of the other script that are use in this example.
I asked to chatgpt and he proposed to create a stream_server.py :
from flask import Flask, Response, render_template
import cv2
app = Flask(name)
def generate_frames():
cap = cv2.VideoCapture(âudp://127.0.0.1:5000â, cv2.CAP_FFMPEG)
while True:
success, frame = cap.read()
if not success:
print(âImpossible de lire une image.â)
break
else:
print(âImage lue avec succès.â)
ret, buffer = cv2.imencode(â.jpgâ, frame)
frame = buffer.tobytes()
yield (bââframe\r\nâ
bâContent-Type: image/jpeg\r\n\r\nâ + frame + bâ\r\nâ)
@app.route(â/â)
def index():
return render_template(âindex.htmlâ)
@app.route(â/video_feedâ)
def video_feed():
return Response(generate_frames(), mimetype=âmultipart/x-mixed-replace; boundary=frameâ)
if name == âmainâ:
app.run(host=â0.0.0.0â, port=8080)
and a template html :
Object Detection Stream
Detection d'objets
and then to launch detection.py and after stream_server.py but it doesnt work for me. Does anyone know why or have a suggestion to display the video on a flask web page? thanks