Home > Blockchain >  How to save one image every 25 frames into a folder
How to save one image every 25 frames into a folder

Time:03-22

I am trying to write images from IP camera into a new folder. However, as for now, it is writing for each frame. How to only save one image every 25 frames? This is my current code:

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

CodePudding user response:

The trivial solution would be:

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