简体   繁体   English

无法在 Jetson-Nano 中使用 Gstreamer 和 OpenCV 显示视频 stream

[英]Unable to show video stream using Gstreamer and OpenCV in Jetson-Nano

I'm trying to open a video stream using OpenCV and G stream from an IP camera.我正在尝试使用 OpenCV 和 G stream 从 ZA12A3079E14A8CEDB24E 相机打开视频 stream。 The pipeline reads each frame, but no window is being shown with imshow .管道读取每一帧,但没有 window 与imshow一起显示。 It works fine when I run the pipeline with gst-launch-1.0 and nvoverlaysink on bash.当我在 bash 上使用gst-launch-1.0nvoverlaysink运行管道时,它工作正常。 The following is the python code that I have been using:以下是我一直在使用的python代码:

import cv2 as cv

gst = "rtspsrc location=rtsp://usser:pass@ip:port/url latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink"
capture = cv.VideoCapture(gst, cv.CAP_GSTREAMER)

print("Is pipeline open: ", capture.isopened())
while True:
     ret, frame = capture.read()
     print("Is receiving frames: ", ret)
     cv.imshow("Stream",frame)

capture.release()

When I run the script, I can see that the pipeline is open and OpenCV is reading frames.当我运行脚本时,我可以看到管道是打开的,并且 OpenCV 正在读取帧。 I only have the following warning:我只有以下警告:

[ WAN:0] global /tmp/pip-install-r_pt66np/opencv-python/opencv/modules/videoto/
src/cap_gstreamer.cpp (935) open Opencv | GStreamer warning: Cannot query video
position: status=1, value=0, duration=-1 

Although the script runs and consumes frames, imshow doesn't generate a window.尽管脚本运行并消耗帧, imshow不会生成 window。

The problem wasn't the pipeline.问题不在于管道。 I had so many errors with the pipeline that I suppose that the error was there.我的管道有很多错误,我想错误就在那里。 imshow needs a wait key to work. imshow需要等待键才能工作。 Here it's the working code:这是工作代码:

import cv2 as cv

gst = "rtspsrc location=rtsp://usser:pass@ip:port/url latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! appsink"
capture = cv.VideoCapture(gst, cv.CAP_GSTREAMER)

print("Is pipeline open: ", capture.isopened())
while capture.isOpened() :
     ret, frame = capture.read()
     print("Is receiving frames: ", ret)
     cv.imshow("Stream", frame)
     
     if cv.waitKey(25) & 0xFF == ord("q"):
          break

capture.release()
cv.destroyAllWindows()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM