RTSP is slow when using Opencv

Hello. I’m trying to create a program that when a motion is detected, it takes a picture of a car and storage it, but, I’m using cv2.VideoCapture(“rtsp://admin:a10b20c30d40@192.168.0.116:554/cam/realmonitor?channel=1&subtype=0”) to get that RTSP stream, but, it is really slow and lost some frames compared with the camera stream when access it via http, what could causing this slowly stream ? When I use VLC to show rtsp stream it works normally. Thanks all

import cv2
import imutils

cap = cv2.VideoCapture(“rtsp://admin:a10b20c30d40@192.168.0.116:554/cam/realmonitor?channel=1&subtype=0”)

while cap.isOpened():

ret, frame1 = cap.read()
resized = imutils.resize(frame1, width=600)
cv2.imshow('feed', resized)
# frame1 = frame2

if cv2.waitKey(20) & 0xFF == ord('q'):
    break

cap.release()
cv2.destroyWindow(‘rwr’)

It depends what you mean by slow?

If you are loosing frames then I would reduce your wait from 20ms to 1ms waitKey(1). This may also be causing rtsp to be “slow”. When you have a long wait in between calls to read(), the bitstream that you are reading from and decoding from under the hood, can get overwritten before you read from it.

Tried to change waitKey(1) nothing changed cudawarped. What I mean is when I access camera stream from http and run that project, the difference between a car that appears in a http camera stream image and the applications is about 4 seconds between then, and when my application show that car on a screen, it goes slowly and lost some frames of that image.

That’s odd. I find VLC has round the same delay (between what’s happening live and what is displayed) as opencv, that’s using opencv with the ffmpeg backend on windows.

Is there still a delay if you remove the resize operation and/or use opencv for the resize operation?

Worked cudawarped, tried cv2.resize instead of imutils.resize as you said is working well. Thanks a lot…

That’s great glad I could help.