in agora/contoso_motors/src/webapp-decode/app.py [0:0]
def gen_frames(video_name):
"""
Generate frames from a video stream.
Args:
video_name (str): The name of the video.
Yields:
bytes: The processed frame in JPEG format.
Returns:
None
"""
global latest_choice_detector
# Add a check in case of failed intit model
if 'latest_choice_detector' not in locals() and 'latest_choice_detector' not in globals():
latest_choice_detector = None
# Check if the video name is different from the current model name
if(latest_choice_detector is None or latest_choice_detector.model_name != video_name):
# Call the destructor first
del latest_choice_detector
# Reload configuration for changes with GitOps
config = reload_config()
if video_name == "yolov8n":
latest_choice_detector = init_yolo_detector()
elif video_name == "safety-yolo8":
latest_choice_detector = init_yolo_safety_detector()
elif video_name == "welding":
latest_choice_detector = init_bolt_detector()
elif video_name == "human-pose-estimation":
latest_choice_detector = init_pose_estimator()
while video_name != "":
processed_frame = latest_choice_detector.run()
if processed_frame is not None:
ret, buffer = cv2.imencode('.jpg', processed_frame)
frame = buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')