File size: 1,207 Bytes
3818b72 65767be 3818b72 65767be 3818b72 65767be 3818b72 65767be 3818b72 65767be | 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 | 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 |