File size: 1,199 Bytes
8e8f78f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import cv2
from ultralytics import YOLO

class ObjectDetectionModel():
    def __init__(self):
        self.model = YOLO("models/yolov8n_openvino_model", task = "detect")

    def process(self, img):
        result = self.model(img)
        img_plot = result[0].plot()

        return img_plot

    def play_video(self, video_path):
        camera = cv2.VideoCapture(video_path)
        frame_width = int(camera.get(cv2.CAP_PROP_FRAME_WIDTH))
        frame_height = int(camera.get(cv2.CAP_PROP_FRAME_HEIGHT))
        fps = camera.get(cv2.CAP_PROP_FPS)

        fourcc = cv2.VideoWriter_fourcc(*'mp4v')
        output_video_path = 'output_video.mp4'
        out = cv2.VideoWriter(output_video_path,fourcc,fps, (frame_width,frame_height))
        processed_frames = []
        
        while(True):
            ret, frame = camera.read()
            if not ret:
                break
    
            result = self.model(frame, verbose=False)
            img_plot = result[0].plot()
            processed_frames.append(img_plot)
        camera.release()
        for frame in processed_frames:
             out.write(frame)
        out.release()

        return output_video_path