56 lines
1.3 KiB
Python
Executable File
56 lines
1.3 KiB
Python
Executable File
'''
|
||
author : Hatcher W
|
||
Email: hcwang@semi.ac.cn
|
||
use: 视频抽帧
|
||
|
||
'''
|
||
# -*- coding:utf8 -*-
|
||
import cv2
|
||
import os
|
||
import shutil
|
||
|
||
|
||
# 视频文件名字l
|
||
|
||
# 保存图片的路径
|
||
def vedio_img(input,output,fps):
|
||
isExists = os.path.exists(output)
|
||
if not isExists:
|
||
os.makedirs(output)
|
||
print('path of %s is build' % (output))
|
||
else:
|
||
shutil.rmtree(output)
|
||
os.makedirs(output)
|
||
print('path of %s already exist and rebuild' % (output))
|
||
|
||
# 视频帧率12
|
||
# fps = 1
|
||
# 保存图片的帧率间隔
|
||
#count = 1
|
||
|
||
# 开始读视频
|
||
videoCapture = cv2.VideoCapture(input)
|
||
i = 0
|
||
j = 0
|
||
|
||
while True:
|
||
success, frame = videoCapture.read()
|
||
|
||
if not success:
|
||
print('video is all read')
|
||
break
|
||
#frame = cv2.resize(frame, (1024, 768))
|
||
i += 1
|
||
if (i % fps == 0):
|
||
# 保存图片
|
||
j += 1
|
||
savedname = output+"/" + "{}".format(j).zfill(7)+ '.jpg' #density
|
||
#savedname = output + "/" + "{}".format(j).zfill(7) + '.jpg' #detection
|
||
cv2.imwrite( savedname, frame)
|
||
print('image of %s is saved' % (savedname))
|
||
|
||
if __name__ == '__main__':
|
||
filename = '../data_MPKFNet/rawdata/1_3.mp4'
|
||
savedpath = '../data_MPKFNet/result_raw/' + "2021.2.23"
|
||
vedio_img(filename,savedpath,1000)
|