Views
No views yet
# Read video
cap = cv2.VideoCapture(file_path)
frame_results = []
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
results = model(frame) # Run YOLO inference
detections = results.pandas().xyxy[0].to_dict(orient="records")
frame_results.append(detections)
cap.release()
os.remove(file_path)
return JSONResponse(content={"detections": frame_results})
except Exception as e:
return JSONResponse(content={"error": str(e)}, status_code=500)