#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @Author : liuyuqi @Contact : liuyuqi.gov@msn.cn @Time : 2020/02/17 16:08:13 @Version : 1.0 @License : (C)Copyright 2019 @Desc : 预处理 ''' import cv2 videoName = r'videos/大象解说《血战钢锯岭》.mp4' # 截图 videoCap=cv2.VideoCapture(videoName) # 帧频 fps = videoCap.get(cv2.CAP_PROP_FPS) # 视频总帧数 total_frames = int(videoCap.get(cv2.CAP_PROP_FRAME_COUNT)) # 图像尺寸 image_size = (int(videoCap.get(cv2.CAP_PROP_FRAME_HEIGHT)), int(videoCap.get(cv2.CAP_PROP_FRAME_WIDTH))) print(fps) print(total_frames) print(image_size) for i in range(2818): sucess, frame = videoCap.read() # sucess,frame=videoCap.read(2818) from PIL import Image # img = Image.fromarray(frame) # img.show() ## 确定字幕范围 im = frame[:, :, 0] im = im[325:640, :] img = Image.fromarray(im) # img.show() # 二值化 thresh = 150 _, im = cv2.threshold(im, thresh, 255, cv2.THRESH_BINARY) img = Image.fromarray(im) img.show() # 计算两张图像间每个像素点的平方误差之和的平均值百分比:当 e > 1 时,图像才有字幕。 # 接着计算相同字幕和不同字幕图像直接的误差 e: 误差 e > 1 时,字幕发生切换。 # 为了方便文字识别,将 20 句字幕组合成一张图片。完整的提取字幕的代码如下: