Python-opencv视频取帧
import cv2
import os
from tqdm import tqdm
video_path = './shuangmu_biaoding/11_10-02/11_10-02_left/MVI_1773.MOV'
frame_save_path ='./shuangmu_biaoding/11_10-02/11_10-02_left/MVI_1773_frame/'
if not os.path.exists(frame_save_path):
os.makedirs(frame_save_path)
i = 0
video = cv2.VideoCapture(video_path)
FPS = video.get(cv2.CAP_PROP_FPS)
print('fps: ', FPS)
while True:
ret, frame = video.read()
if ret:
if i% 2 == 0:
cv2.imwrite(frame_save_path+ 'frame_%d.jpg'%i, frame)
i+= 1
cv2.waitKey(1)
else:
break
cv2.destroyAllWindows()
video.release()