Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,44 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import os
|
3 |
import cv2
|
4 |
from ultralytics import YOLO
|
|
|
|
|
|
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
cap = cv2.VideoCapture(video)
|
11 |
-
|
12 |
-
while True:
|
13 |
-
ret, frame = cap.read()
|
14 |
-
|
15 |
-
if not ret:
|
16 |
-
break
|
17 |
-
|
18 |
-
results = model(frame)
|
19 |
-
for result in results:
|
20 |
-
box=result.boxes
|
21 |
-
|
22 |
-
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
23 |
-
print(x1, y1, x2, y2)
|
24 |
-
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
25 |
-
|
26 |
-
return cv2.imshow("img", frame)
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import cv2
|
2 |
from ultralytics import YOLO
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
import gradio as gr
|
6 |
|
7 |
+
def fonk(video_path):
|
8 |
+
|
9 |
+
model=YOLO("best.pt")
|
10 |
+
cap=cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
frame_width = int(cap.get(3))
|
13 |
+
frame_height = int(cap.get(4))
|
14 |
+
size = (frame_width, frame_height)
|
15 |
+
output_video = cv2.VideoWriter('filename.mp4',
|
16 |
+
cv2.VideoWriter_fourcc(*'XVID'),
|
17 |
+
10, size)
|
18 |
|
19 |
+
|
20 |
+
while True:
|
21 |
+
ret, frame= cap.read()
|
22 |
+
|
23 |
+
if ret!=True:
|
24 |
+
break
|
25 |
+
|
26 |
+
results= model(frame)
|
27 |
+
for result in results:
|
28 |
+
box=result.boxes
|
29 |
|
30 |
+
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
31 |
+
print(x1, y1, x2, y2)
|
32 |
+
frame= cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
33 |
+
output_video.write(frame)
|
34 |
+
|
35 |
+
return output_video
|
36 |
+
|
37 |
+
demo = gr.Interface(fonk,
|
38 |
+
inputs= gr.Video(),
|
39 |
+
outputs=gr.Video(),
|
40 |
+
examples=["cow-video-cows-mooing-and-grazing-in-a-field.mp4"],
|
41 |
+
title= "cows",
|
42 |
+
cache_examples=True)
|
43 |
+
demo.launch()
|
44 |
+
|