路径中不要出现中文!!!
import os
import cv2
videos_src_path = 'F:\dataset\\data2\\CrowdCounting\\dian\\11-22xin'
videos_save_path = 'F:\dataset\\data2\\CrowdCounting\\dian\\cut\\11-22xin'
videos = os.listdir(videos_src_path)
videos = filter(lambda x: x.endswith('mov'), videos)
for each_video in videos:
print(each_video)
# get the name of each video, and make the directory to save frames
each_video_name, _ = each_video.split('.')
os.mkdir(videos_save_path + '/' + each_video_name)
each_video_save_full_path = os.path.join(videos_save_path, each_video_name) + '/'
# get the full path of each video, which will open the video tp extract frames
each_video_full_path = os.path.join(videos_src_path, each_video)
cap = cv2.VideoCapture(each_video_full_path)
frame_count = 1
success = True
while(success):
success, frame = cap.read()
if success == False:
break
print('Read a new frame: ', success)
#params = []
#params.append(cv2.IMWRITE_PNG_BINARY)
#params.append(1)
cv2.imwrite(each_video_save_full_path + each_video_name + "_%d.jpg" % frame_count, frame)
frame_count = frame_count + 1
print(frame_count)
cap.release()