File size: 1,071 Bytes
f9b1aab
 
3e31bd0
 
 
f9b1aab
3e31bd0
 
 
 
f9b1aab
3e31bd0
 
 
 
 
 
f9b1aab
3e31bd0
 
 
 
 
 
 
 
 
 
f9b1aab
3e31bd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
import cv2
from ultralytics import YOLO
import numpy as np
import os
import gradio as gr

def fonk(video_path):
  
  model=YOLO("best.pt")
  cap=cv2.VideoCapture(video_path)

  frame_width = int(cap.get(3)) 
  frame_height = int(cap.get(4))
  size = (frame_width, frame_height)
  output_video = cv2.VideoWriter('filename.mp4',  
                         cv2.VideoWriter_fourcc(*'XVID'), 
                         10, size) 

  
  while True:
    ret, frame= cap.read()

    if ret!=True:
      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)
      frame= cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
      output_video.write(frame)
      
      return output_video

demo = gr.Interface(fonk,
                    inputs= gr.Video(),
                    outputs=gr.Video(),
                    examples=["cow-video-cows-mooing-and-grazing-in-a-field.mp4"],
                    title= "cows",
                    cache_examples=True)
demo.launch()