提取文件夹中视频的帧

'''
# 导入所需要的库
import os
from tqdm import tqdm
from os.path import join
import cv2

# videos_path="D:\\桌面\\deepfake-detection-challenge\\test_videos"
# images_path="D:\\桌面\\deepfake-detection-challenge\\test_images"


videos_path = ".\data"
images_path = ".\output"


def save_image(image, addr, num):
    print(addr)
    address = join(addr,'{:04d}.png'.format(num))
    # address = addr + str(num) + '.png'
    print(address)
    cv2.imwrite(address, image)


def extract_frame(data_path, output_path):
    # 判断目标路径是否存在
    os.makedirs(output_path, exist_ok=True)
    # 读取视频文件
    videoCapture = cv2.VideoCapture(data_path)
    # 读帧
    success, frame = videoCapture.read()
    i = 0
    # 设置固定帧率
    timeF = 10
    j = 0
    while success:
        i = i + 1
        if (i % timeF == 0):
            j = j + 1
            save_image(frame, output_path, j)
            print('save image:', i)
        success, frame = videoCapture.read()


if __name__=='__main__':
    for video in tqdm(os.listdir(videos_path)):
        image_floder=video.split('.')[0]
        print(video)
        print(image_floder)
        extract_frame(join(videos_path,video),join(images_path,image_floder))
'''

 

上一篇:C51单片机 写一个外部中断(入门单片机)


下一篇:优学院自动刷视频自动答题软件分享