如何将每 25 帧的图像保存到文件夹中

How to save one image every 25 frames into a folder

我正在尝试将网络摄像机中的图像写入新文件夹。但是,就目前而言,它是为每一帧编写的。如何每 25 帧只保存一张图像?这是我当前的代码:

import cv2
import os
folder = 'test_python'
os.mkdir(folder)

url = "rtsp://axis-media/media.amp"
count = 0
cap = cv2.VideoCapture(url)

while True:
    # read next frame
    ret, frame = cap.read()

    cv2.imshow('frame', frame)
    cv2.imwrite(os.path.join(folder, "frame{:d}.jpg".format(count)), frame)  
    count += 1

简单的解决方案是:

if count % 25 == 0:
    cv2.imwrite(...)