I need to take snapshots of an ip camera connected to my raspberry pi 3 b+. I´m using python3 and opencv. There is a timer in the camera so I can check if the snapshot is taken in the right moment.
This script works well in my PC with Windows but does not in the raspberry. The script takes a snapshot every second, but the frame taken is not the correct, its old.
In the raspberry pi, I ran the video with VLC and omxplayer and its ran fluidly, so I think that the problem is in Opencv and my code. I have the impression that the frames are stored in a buffer, the raspberry is too slow to take all the frames from the buffer in real time, so as the time pass there is more delay between the last real frame and the frame taken.
import threading
import time
import cv2
cap = cv2.VideoCapture(‘rtsp://192.168.0.88’)
cap.set(cv2.CAP_PROP_BUFFERSIZE, 3)
counter = 0
while True:
ret, frame = cap.read()
if ret:
cv2.imwrite(str(counter) + '.jpg', frame)
counter = counter + 1
time.sleep(1)
Anyone have an idea of how can I take only the latest frame from the camera? I want to remark that the resolution is 1920x1080 and the video format is h264. Furthermore, in the real application I need that the time between frames to be 0.1 seconds.