问题遇到的现象和发生背景
目标检测入门实战:贪吃蛇小游戏
遇到的现象和发生背景,请写出第一个错误信息
我在进行视频抽帧时,显示已经保存但文件夹里却没有
path of F:\Learning\study\tanchishe——paddlex\video\123/ already exist and rebuild
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/1_15.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/2_30.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/3_45.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/4_60.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/5_75.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/6_90.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/7_105.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/8_120.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/9_135.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/10_150.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/11_165.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/12_180.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/13_195.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/14_210.jpg is saved
JPEGImages of F:\Learning\study\tanchishe——paddlex\video\123/15_225.jpg is saved
video is all read
进程已结束,退出代码0
文件夹为空
用代码块功能插入代码,请勿粘贴截图。 不用代码块回答率下降 50%
我的抽帧代码:
import cv2
import os
import shutil
def get_frame_from_video(video_name, interval):
"""
Args:
video_name:输入视频名字
interval: 保存图片的帧率间隔
Returns:
"""
# 保存图片的路径
save_path = video_name.split('.mp4')[0] + '/'
is_exists = os.path.exists(save_path)
if not is_exists:
os.makedirs(save_path)
print('path of %s is build' % save_path)
else:
shutil.rmtree(save_path)
os.makedirs(save_path)
print('path of %s already exist and rebuild' % save_path)
# 开始读视频
video_capture = cv2.VideoCapture(video_name)
i = 0
j = 0
while True:
success, frame = video_capture.read()
i += 1
if i % interval == 0:
# 保存图片
j += 1
save_name = save_path + str(j) + '_' + str(i) + '.jpg'
cv2.imwrite(save_name, frame)
print('JPEGImages of %s is saved' % save_name)
if not success:
print('video is all read')
break
if __name__ == '__main__':
# 视频文件名字
video_name = r'F:\Learning\study\tanchishe——paddlex\video\123.mp4' # 不具体到视频会报错
interval = 15
get_frame_from_video(video_name, interval)
运行结果及详细报错内容
不报错,就是保存不了
我的解答思路和尝试过的方法,不写自己思路的,回答率下降 60%
我换过其他抽帧代码,但是会报错2