Skip to content Skip to sidebar Skip to footer

Cv2.videocapture.read() Gets Old Frame After Time.sleep()

I tried to capture (stereo) images with Python's opencv and two cameras so therefore every 5 seconds an image should be saved. But the problem here is that an old frame is saved. T

Solution 1:

you need to count the elapsed time, but not stop read frames. like this:

import cv2
import time

cap = cv2.VideoCapture(0)
preframe_tm = time.time()
i = 0
while True:
    ret, frame = cap.read()
    elapsed_time = time.time() - preframe_tm
    if elapsed_time < 5:
        continue
    preframe_tm = time.time()
    i += 1
    print("Taking image %d:" % i)
    cv2.imwrite("image_%d.jpg" % i, frame)
    if i >= 20:
        break

cap.release()
cv2.destroyAllWindows()


Post a Comment for "Cv2.videocapture.read() Gets Old Frame After Time.sleep()"