赞
踩
在python3环境下安装opencv3
下载安装
https://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv
截取图片
import cv2
# windows 系统 注意文件夹分隔符
filepath = 'D:/视频/动漫/Bojack.Horseman/Bojack.Horseman 第1季/马男波杰克.Bojack.Horseman.S01E01.中英字幕.WEB-HR.AC3.1024X576.x264.mkv'
vc = cv2.VideoCapture(filepath) # 读入视频文件
c = 1
if vc.isOpened(): # 判断是否正常打开
rval, frame = vc.read()
else:
rval = False
# 一般一秒48帧
timeF = 1000 # 视频帧计数间隔频率
while rval: # 循环读取视频帧
rval, frame = vc.read()
dirpath = 'img/'
if (c % timeF == 0): # 每隔timeF帧进行存储操作
cv2.imwrite(dirpath + str(c) + '.jpg', frame) # 存储为图像
c = c + 1
cv2.waitKey(1)
vc.release()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。