File size: 1,248 Bytes
f9b1aab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
import gradio as gr
import cv2
from ultralytics import YOLO

def object_detection():
    
    model=YOLO("/home/kahraman/Masaüstü/HuggingFace_Models_and_Spaces/yolov8_model_on_custom_data/best.pt")
    
    source="/home/kahraman/Masaüstü/HuggingFace_Models_and_Spaces/yolov8_model_on_custom_data/cow-video-cows-mooing-and-grazing-in-a-field.mp4"
    
    cap = cv2.VideoCapture(source)
    
    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)
    
        cv2.imshow("img", frame)
        
        if cv2.waitKey(1) & 0xFF == ord("q"):
            break
    
    cap.release()
    cv2.destroyAllWindows()


iface = gr.Interface(object_detection, 
                    gr.Video(), 
                    "playable_video", 
                    examples=[
                        os.path.join(os.path.abspath(''), 
                                     "video/video_sample.mp4")], 
                    cache_examples=True)

iface.launch(share=True)