all repos — videocr @ 51ab92cca4e15de4695cb07c756488c6cd22f663

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