File size: 911 Bytes
ce3199d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import cv2
import numpy as np
import gradio as gr
from ultralytics import YOLO
video_path = [['files/a.mp4']]
inputs = [gr.components.Video(type="filepath", label="Input ")]
outputs = [gr.components.Image(type="numpy", label="Output ")]
model = YOLO("files/yolov8n.pt")   
def show_preds_video(video_file):
    cap = cv2.VideoCapture(video_file)         
    while cap.isOpened():
        success, frame = cap.read()      
        if success:             
            results = model.track(frame, persist=True)             
            annotated_frame = results[0].plot()             
            yield cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB)                        
     
video_processing = gr.Interface(
    fn=show_preds_video,
    inputs=inputs,
    outputs=outputs,     
    examples=video_path,
    cache_examples=False,
    title="Video Multi Objects tracking",    
    )