欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python cv指定间隔截取视频帧并保存图像到指定路径

程序员文章站 2022-03-21 08:01:14
Python cv指定间隔截取视频帧并保存图像到指定路径import cv2import globimport osfrom datetime import datetimedef video_to_frames(path): """ 输入:path(视频文件的路径) """ # VideoCapture视频读取类 videoCapture = cv2.VideoCapture() videoCapture.open(path) # 帧率...

Python cv指定间隔截取视频帧并保存图像到指定路径

import cv2
import glob
import os
from datetime import datetime


def video_to_frames(path):
    """
    输入:path(视频文件的路径)
    """
    # VideoCapture视频读取类
    videoCapture = cv2.VideoCapture()
    videoCapture.open(path)
    # 帧率
    fps = videoCapture.get(cv2.CAP_PROP_FPS)
    # 总帧数
    frames = videoCapture.get(cv2.CAP_PROP_FRAME_COUNT)
    print("fps=", int(fps), "frames=", int(frames))

    for i in range(int(frames)):
        ret, frame = videoCapture.read()
        if i%300 == 1:

            cv2.imwrite("D:/pct_1/det/vedio%d.jpg" % (i), frame)
    return


if __name__ == '__main__':
    t1 = datetime.now()
    video_to_frames("D:/pct_1/net/ster/w-2.avi")
    t2 = datetime.now()
    print("Time cost = ", (t2 - t1))
    print("SUCCEED !!!")


本文地址:https://blog.csdn.net/weixin_45875199/article/details/107177824