all repos — videocr @ f8e99465c7c7ad17cba974ff73f6ce7f409f07af

Extract hardcoded subtitles from videos using machine learning

videocr/opencv_adapter.py (view raw)

 1import cv2
 2
 3
 4class Capture:
 5    def __init__(self, video_path):
 6        self.path = video_path
 7
 8    def __enter__(self):
 9        self.cap = cv2.VideoCapture(self.path)
10        if not self.cap.isOpened():
11            raise IOError('Can not open video {}.'.format(self.path))
12        return self.cap
13
14    def __exit__(self, exc_type, exc_value, traceback):
15        self.cap.release()