由于本次设计中所涉及到的文件是视频文件,所以我就必须要对它进行处理。而在训练网络前需要带标签信息的文件,然后我参考了一下人民币1元和100元的数据,决定把所有图一类别的视频所截取的数据集都放在一个文件夹下,所以就必须要对其中的命名进行操作,然后其中涉及到的内容是全局变量的问题,具体贴代码吧
def extract_frames(video_file,label,num_frames=8):
"""Return a list of PIL image frames uniformly sampled from an mp4 video."""
videoCapture = cv2.VideoCapture(video_file)
label_flag = label
c = 0
test_path = os.path.join(os.getcwd(),'test')
path = os.path.join(test_path,label_flag)
if videoCapture.isOpened():
rval, frame = videoCapture.read()
else:
rval = False
# if os.path.exists(path):
# shutil.rmtree(path)
if not os.path.exists(path):
os.makedirs(path)
global flag
flag = 0
num = 10
fram_Num = videoCapture.get(7)
# rate = videoCapture.get(5)
timef = int((fram_Num - 1) / num)
while rval:
rval, frame = videoCapture.read()
c = c + 1
if c % timef == 0:
if rval:
print(c)
flag += 1
cv2.imwrite(path + r'/' + str(flag) + '.jpg', frame)
else:
print('end')
break
frame_paths = sorted([os.path.join(path, frame)
for frame in os.listdir(path)])
# frames = load_frames(frame_paths, num_frames=num_frames)
return frame_paths
感觉做出来的数据集还行,是理想的状态,
然后这部分主要是调用的部分,等所有的弄完了,我再来把所有的代码都弄上来