简体   繁体   English

Gstreamer 输入到 opencv

[英]Gstreamer input into opencv

From this link I think I may be close but I don't get any errors except for the Nonetype errors when I use the stream.从这个链接我想我可能已经接近了,但是当我使用流时,除了 Nonetype 错误之外,我没有收到任何错误。

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

I am struggling to find the mistake in the above line.我正在努力寻找上述行中的错误。 Has anyone accomplished this and mind helping me out.有没有人做到了这一点,并介意帮助我。

I have a raspberry pi posting a video stream with gstreamer and can successfully stream it onto an Ubuntu pc with gstreamer in terminal.我有一个使用 gstreamer 发布视频流的树莓派,并且可以在终端中使用 gstreamer 成功地将其流式传输到 Ubuntu pc 上。

Sender:发件人:

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

Reciever接收器

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

The python script I am trying to get working我正在尝试使用的 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)

Gives the error 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'给出错误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'

This posting conversation along with many others helped me formulate a solution.这篇帖子与许多其他人的对话帮助我制定了一个解决方案。 I managed to stream video wirelessly from Raspberry Pi 4 Model B to Jetson Nano with GStreamer and OpenCV using the following:我设法使用 GStreamer 和 OpenCV 使用以下方法将视频从 Raspberry Pi 4 Model B 无线传输到 Jetson Nano:

Launching GStreamer on 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

Receiving video stream in Jetson Nano terminal:在 Jetson Nano 终端接收视频流:

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

Receiving video stream in Jetson Nano VideoCapture object:在 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()

你的意思是appsink而不是opencvsink吗?

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

To get log messages from gstreamer, set GST_DEBUG before running your Python script.要从 gstreamer 获取日志消息, 在运行 Python 脚本之前设置 GST_DEBUG Eg:例如:

GST_DEBUG=4 ./script.py

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

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