1 | initial version |
some VideoCapture implementations (i.e. v4l) have an internal ringbuffer for the images. it seems, you're not flushing that fast enough, and so you get outdated images.
try to change your logic, read images continuously from the cam (don't sleep that long), and save, when appropriate
import cv2
import time
cap = cv2.VideoCapture(0)
steps = [120,120,120,10,10,10,60,60,10,10,10,10,10,10,0]
n = 0
next = time.time() + steps[0]
while True:
ret, frame = cap.read()
if not ret : break
now = time.time()
if now >= next:
n += 1
if n >= len(steps) : break
next = now + steps[n]
t = time.strftime("%Y-%m-%d_%H-%M-%S")
cv2.imwrite('test_' + t + '.jpg',frame)
time.sleep(1)
cap.release()
2 | No.2 Revision |
some VideoCapture implementations (i.e. v4l) have an internal ringbuffer for the images. it seems, you're not flushing that fast enough, and so you get outdated images.
try to change your logic, read images continuously from the cam (don't sleep that long), and save, when appropriate
import cv2
import time
cap = cv2.VideoCapture(0)
steps = [120,120,120,10,10,10,60,60,10,10,10,10,10,10,0]
n = 0
next = time.time() + steps[0]
while True:
ret, frame = cap.read()
if not ret : break
now = time.time()
if now >= next:
n += 1
if n >= len(steps) : break
next = now + steps[n]
t = time.strftime("%Y-%m-%d_%H-%M-%S")
cv2.imwrite('test_' + t + '.jpg',frame)
time.sleep(1)
cap.release()
(note: unfortunately no python on this box, so this is untested)