当前位置:   article > 正文

python cv2跳帧保存图片_python 循环保存图片

python 循环保存图片
def save_img():
    video_path = '/home/sg-ai/桌面/keras训练/reportfile/test.mp4'
    # videos = os.listdir(video_path)
    # for video_name in videos:
    #     file_name = video_name.split('.')[0]
    #     folder_name =  file_name
    #     os.makedirs(folder_name,exist_ok=True)
    vc = cv2.VideoCapture(video_path) #读入视频文件
    c = 1
    if vc.isOpened():  # 判断是否正常打开
        rval, frame = vc.read()
    else:
        rval = False

    timeF = 300  # 视频帧计数间隔频率

    while rval:  # 循环读取视频帧
        rval, frame = vc.read()
        pic_path = '/home/sg-ai/桌面/keras训练/reportfile/' + '/'
        if (c % timeF == 0):  # 每隔timeF帧进行存储操作
            cv2.imwrite(pic_path + '_' + str(c) + '.jpg', frame)  # 存储为图像,保存名为 文件夹名_数字(第几个文件).jpg
        c = c + 1
        cv2.waitKey(1)
    vc.release()
save_img()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/爱喝兽奶帝天荒/article/detail/823788
推荐阅读
相关标签
  

闽ICP备14008679号