OpenCV does not display ip camara with gstreamer

I am trying to open with opencv the stream of an Axis ip camera on my Jetson Nano.

In the terminal with the following command i can see the camera footage:

gst-launch-1.0 rtspsrc location=rtsp://x.x.x/axis-media/media.amp user-id=user user-pw=pwd latency = 10 ! decodebin ! nv3dsink -e

So I know that the url is correct.

But when I use the following code with opencv:

gst = “rtspsrc location=rtsp://x.x.x/axis-media/media.amp user-id=user user-pw=pwd latency = 10 ! decodebin ! nv3dsink -e”

gst =
capture = cv.VideoCapture(gst, cv.CAP_GSTREAMER)

print(“1”)
print(capture.isOpened())

while True:
print(“2”)
ret,frame = capture.read()
print(ret)
cv.imshow(“Stream”, frame)
cv.waitKey(1)

I get this warnings and output:

[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) open OpenCV | GStreamer warning: Error opening bin: syntax error
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
1
False
2
False
Traceback (most recent call last):
File “a.py”, line 46, in
cv.imshow(“Stream”, frame)
cv2.error: OpenCV(4.1.1) /home/nvidia/host/build_opencv/nv_opencv/modules/highgui/src/window.cpp:352: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’

From which I understand that the pipeline has not been created correctly.

And using the same code changing the sink to appsink the terminal shows this output but it doesn’t show any camera image.

gst6 = “rtspsrc location=rtsp://x.x.x/axis-media/media.amp user-id=user user-pw=pwd latency = 10 ! decodebin ! appsink”

Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261

(i have buid opencv with gstreamer support and confirmed it with cv.getBuildInformation.

I have also tried :
gst = "videotestsrc ! appsink "

And it works correctly.

So i dont know what is happening, what can it be?

Thank you in advanced

Solved!!! =)

The problem was decodebin, that automatically constructs a decoding pipeline, and in the terminal works fine, but with opencv, does not, dont know why.

So changing the url to:

gst6 = “rtspsrc location=rtsp://x.x.x/axis-media/media.amp user-id=user user-pw=pwd latency = 10 ! rtph264depay ! avdec h264 ! videoconvert ! appsink”

works,

So it seems you cant use decodebin with opencv.

1 Like

Glad to know you found the solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.