all repos — videocr @ 7b607e5ca7b7d058e9f4cc108b6c75b9ef7e1ba0

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