capturing rtsp camera using OpenCV python

2019-03-22 16:11发布

问题:

I have a remote camera streaming through rtsp protocol and am trying to access it in OpenCV 2.13.1 using python with following code.

camera = cv2.VideoCapture("rtsp://admin:<port>@<ip>/xyz/video.smp")

However, when I do that I get the following warning

WARNING: Couldn't read movie file rtsp://admin:<port>@<ip>/xyz/video.smp

I have also tried doing this:

camera = cv2.VideoCapture.open("rtsp://admin:<port>@<ip>/xyz/video.smp")

but when I do this I get this error:

`AttributeError: 'builtin_function_or_method' object has no attribute` 'open'

I did searched quite a bit about this problem but couldn't get the idea that works for me. Any help would be appreciated.

回答1:

Credit from RTSP stream and OpenCV (Python):

vcap = cv.VideoCapture("rtsp://192.168.1.2:8080/out.h264")
while(1):
    ret, frame = vcap.read()
    cv.imshow('VIDEO', frame)
    cv.waitKey(1)