all repos — videocr @ fe68c35cc823b70f1f83c317c7b285e30d2568b6

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()