Spaces:
Runtime error
Runtime error
File size: 940 Bytes
f9b1aab 22114ba f9b1aab 437ec05 f9b1aab f2aa429 437ec05 f9b1aab 6e7b469 f9b1aab d145c5e 437ec05 d145c5e f9b1aab |
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 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
import os
import cv2
from ultralytics import YOLO
def object_detection(video):
model=YOLO("best.pt")
cap = cv2.VideoCapture(video)
while True:
ret, frame = cap.read()
if not ret:
break
results = model(frame)
for result in results:
box=result.boxes
x1, y1, x2, y2 = map(int, box.xyxy[0])
print(x1, y1, x2, y2)
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
return cv2.imshow("img", frame)
iface = gr.Interface(object_detection,
gr.Video(),
"playable_video",
examples=[
os.path.join(os.path.abspath(''),
"cow-video-cows-mooing-and-grazing-in-a-field.mp4")],
cache_examples=True)
iface.launch(share=True) |