【问题标题】:Gstreamer input into opencvGstreamer 输入到 opencv
【发布时间】:2018-09-27 19:02:32
【问题描述】:

从这个link 我想我可能已经接近了,但是当我使用流时,除了 Nonetype 错误之外,我没有收到任何错误。

cap = cv2.VideoCapture("tcpclientsrc host=192.168.1.111 port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! opencvsink sync=false")

我正在努力找出上述行中的错误。有没有人做到这一点并介意帮助我。

我有一个树莓派使用 gstreamer 发布视频流,并且可以成功地将其流式传输到终端中带有 gstreamer 的 Ubuntu pc。

发件人:

raspivid -t 999999 -h 720 -w 1080 -fps 25 -hf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse !  rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=192.168.1.111 port=5000

接收者

gst-launch-1.0 -v tcpclientsrc host=192.168.1.111 port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false

我正在尝试使用的 python 脚本

import cv2

cap = cv2.VideoCapture('tcpclientsrc host=192.168.1.111 port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! '
                           'videoconvert ! appsink')

while True:
    r, frame = cap.read()

    try:
        cv2.imshow('yes', frame)
    except cv2.error as e:
        print(e)

给出错误OpenCV(3.4.3) /io/opencv/modules/highgui/src/window.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'imshow'

【问题讨论】:

  • 问题是什么?请发布错误消息!
  • 对不起,我添加了代码和错误。 @micha137

标签: python opencv raspberry-pi gstreamer


【解决方案1】:

与许多其他人一起发布的对话帮助我制定了解决方案。我设法使用 GStreamer 和 OpenCV 将视频从 Raspberry Pi 4 Model B 无线传输到 Jetson Nano,使用以下方法:

在 Raspberry Pi 上启动 GStreamer:

raspivid -t 0 -h 720 -w 1080 -fps 25 -hf b 2000000 -o – | gstlaunch-1.0 v fdsrc ! h264parse ! rtph264pay ! config-interval=1 pt=96 ! gdppay ! tcpserversink host=192.168.1.147 port=5000

在 Jetson Nano 终端中接收视频流:

gst-launch-1.0 -v tcpclientsrc host=192.168.1.147 port=5000 ! gdpdepay ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! autovideosink sync=false

在 Jetson Nano VideoCapture 对象中接收视频流:

import cv2
import matplotlib.pyplot as plt

RaspiStreamCam=cv2.VideoCapture(‘tcpclientsrc host=192.168.1.147 port=5000 ! gdpdepay ! rtph264depay ! h264parse ! omxh264dec ! nvvidconv ! video/x-raw, format=BGRx ! videoconvert ! video/x-raw, format=BGR ! appsink’, cv2.CAP_STREAMER)

while True:

    ret, frameRaspiIP=RaspiStreamCam.read()

    cv2.imshow(‘RaspiStreamCam’,frameRaspiIP)

    if cv2.waitKey(1)==ord(‘q’):
        break

RaspiStreamCam.release()

cv2.destroyAllWindows()

【讨论】:

    【解决方案2】:

    你的意思是appsink 而不是opencvsink

    cap = cv2.VideoCapture("tcpclientsrc host=192.168.1.111 port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! appsink")
    

    【讨论】:

    • 它不起作用,我无法提供反馈,因为错误只出现在 imshow() 行。
    • 您可以尝试在imshow 之前检查r 吗? if r is True: cv2.imshow('yes', frame)
    【解决方案3】:

    要从 gstreamer 获取日志消息,set GST_DEBUG 在运行 Python 脚本之前。例如:

    GST_DEBUG=4 ./script.py
    

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-01
      • 2018-01-14
      • 1970-01-01
      相关资源
      最近更新 更多