from flask import Flask, rendertemplate, Response, request import cv2 import torch from…
- User
from flask import Flask, render_template, Response, request import cv2 import torch from ultralytics import YOLO from Utils import LIVE, MODEL, CLASSES, annotate, recorder from Src import recognize_color, chooseOne, recognize_violation
app = Flask(name)
model = YOLO(MODEL)
def generate_frames(video_path): cap = cv2.VideoCapture(video_path)
codeline_height = {'n': 0, 'x': 0, 'sum': 0, 'mean': 0} veh_set = torch.empty(0) while cap.isOpened(): success, frame = cap.read() if not success: break if frame.shape[0] > 720: scale_factor = 720 / frame.shape[0] frame = cv2.resize(frame, None, fx=scale_factor, fy=scale_factor) result = model.track(frame, persist=True, classes=[n for n in CLASSES])[0] if result is not None and hasattr(result, 'boxes'): result = result.boxes.data else: result = torch.empty((0,)) traffic_lights = result[result[:, -1] == 9] if len(result) > 0 else torch.empty((0,)) vehicles = result[result[:, -1] != 9] if len(result) > 0 else torch.empty((0,)) light_colors = recognize_color(frame, traffic_lights, print_info=False) chosen = chooseOne(light_colors) annotate(frame, traffic_lights, recognizedColor=light_colors) raw, pos, veh_set, violator = recognize_violation( frame, vehicles, traffic_lights[chosen[0]][:4] if len(traffic_lights) > 0 else [], line_height, veh_set, imaginary_line=True ) if torch.any(violator): annotate(frame, violator, violationMode=True) _, buffer = cv2.imencode('.jpg', frame) frame_bytes = buffer.tobytes() yield (b'--frame\r\n' b'Content-Type: image/jpeg\r\n\r\n' + frame_bytes + b'\r\n') cap.release() - Assistant
- User
proess from the model and showing the result is not happening in the code u provided Live Processed Video
- Assistant