Python使用opencv获取视频每帧的图片

上代码!

import os

import cv2

cap = cv2.VideoCapture('视屏路径')

while (1):
    ret, frame = cap.read()
    if ret == False:
        break
    frame_index = 0
    frame_count = 0
    if cap.isOpened():
        success = True
    else:
        success = False
    while (success):
        success, frame = cap.read()
        print("---> 正在读取第%d帧:" % frame_index, success)
        if frame_index % 1 == 0 and success:
            resize_frame = cv2.resize(frame, (1920, 1080), interpolation=cv2.INTER_AREA)
            cv2.imwrite('./save_path' + "%d.jpg" % frame_count, resize_frame)
            frame_count += 1
        frame_index += 1
    cap.release()
已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页