python 视频转图片

def save_rgb(path):
    rgb = path + 'rgb.mp4'
    print(rgb)
    # 获得视频的格式
    videoCapture = cv2.VideoCapture(rgb)

    # 获得码率及尺寸
    fps = videoCapture.get(cv2.CAP_PROP_FPS)
    size = (int(videoCapture.get(cv2.CAP_PROP_FRAME_WIDTH)),
            int(videoCapture.get(cv2.CAP_PROP_FRAME_HEIGHT)))
    fNUMS = videoCapture.get(cv2.CAP_PROP_FRAME_COUNT)

    print(fps, size, fNUMS)
    # 读帧
    success, frame = videoCapture.read()
    # print(success)
    i = 0
    while success:
        # plt.imshow(frame)
        # plt.show()
        left = frame[0:1024, :, :]
        right = frame[1024:2048, :, :]
        cv2.imwrite(path + 'image/frame_data_%s_left.jpg' % str(i).zfill(6), left)
        cv2.imwrite(path + 'image/frame_data_%s_right.jpg' % str(i).zfill(6), right)
        i = i + 1
        success, frame = videoCapture.read()  # 获取下一帧

    videoCapture.release()

你可能感兴趣的:(python 视频转图片)