zircon/video_reader/base_reader.py
2025-04-04 03:35:58 +07:00

37 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from abc import ABC, abstractmethod
class BaseReader(ABC):
def __init__(self, video_path, retries_get_frame=1, retries_connect=0):
self.retries_get_frame = retries_get_frame
self.retries_connect = retries_connect
self.video_path = video_path
@abstractmethod
def connect(self):
'''
метод подключения к видео потоку по пути заданному в __init__
должен определять внутри себя объект потока к которому будет применяться функция get_frame
'''
pass
@abstractmethod
def get_frame(self):
'''
метод извлечения кадра из потока с прменением объекта потока
'''
pass
def __iter__(self):
return self
def __next__(self):
for connect_count in range (self.retries_connect+1):
for get_frame_count in range(self.retries_get_frame+1):
frame = self.get_frame()
if frame is not None and frame.size > 0:
return frame
self.connect()
raise StopIteration