您的位置:首页 > 编程语言 > Python开发

python Opencv目录下视频转换为

2017-09-20 11:16 691 查看


import cv2
import os

curdir="/home/lisa/dataset/video/selected/"

index=1;

interval=10

def video2pic(path):
global  interval
cap=cv2.VideoCapture(path);
success,frame=cap.read()
while success:
global index
index=index+1
if index%interval!=0:
success, frame = cap.read()
continue
else:
temp=index/interval

cv2.imshow("temp",frame)
if index<10000:
cv2.imwrite("/home/lisa/dataset/handPicStage2/720p/1/"+str(temp)+".jpg",frame)
else:
cv2.imwrite("/home/lisa/dataset/handPicStage2/720p/2/" + str(temp) + ".jpg", frame)
success, frame = cap.read()
if cv2.waitKey(1) & 0xFF == ord('q'):
break

for parent,dirname,filenames in os.walk(curdir):
for filename in filenames:
path=os.path.join(parent,filename)
if path.endswith("mp4"):
video2pic(path)
pass
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: