在opencv中使用gstreamer从raspberrry pi捕获流 [英] capture stream from raspberrry pi using gstreamer in opencv

查看:172
本文介绍了在opencv中使用gstreamer从raspberrry pi捕获流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过本地网络将树莓派摄像机的视频流传输到我的PC.

I'm trying to stream a video from a raspberry pi camera to my PC through a local network.

在RaspberryPi端,我通过以下命令使用gstreamer:

On the RaspberryPi side, I use gstreamer with the following command:

raspivid -n -t 0 -rot 270 -w 960 -h 720 -fps 30 -b 6000000 -o - | gst-launch-1.0 -e -vvvv fdsrc ! h264parse ! rtph264pay pt=96 config-interval=5 ! udpsink host=192.168.1.85 port=5000

我在PC端使用以下命令:

And I use the following command on the PC side:

gst-launch-1.0 -e -v udpsrc port=5000 ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! fpsdisplaysink sync=false text-overlay=false

在这种情况下,视频将被显示并且一切正常.但是,我想在C ++程序中使用OpenCV捕获流.我正在尝试使用通过gstreamer-1.0 32bit编译的OpenCV 3.2来做到这一点.

In this case, the video gets displayed and everything works fine. However, I would like to capture the stream with OpenCV in a C++ program. I'm trying to do this using OpenCV 3.2 compiled with gstreamer-1.0 32bit.

当我运行以下代码来尝试捕获流时:

When I run the following code to try to capture the stream:

#include <opencv2/opencv.hpp>

int main(int argc, char *argv[])
{
    cv::VideoCapture cap("udpsrc port=5000 ! application/x-rtp, payload=96 ! rtpjitterbuffer ! rtph264depay ! avdec_h264 ! appsink");

    return 0;
}

我收到以下错误:

GStreamer Plugin: Embedded video playback halted; module udpsrc0 reported: Internal data stream error.

OpenCV Error: Unspecified error (GStreamer: unable to start pipeline) in cvCaptureFromCAM_GStreamer, file:\opencv\modules\videoio\src\cap_gstreamer.cpp, line 832

我可以使用OpenCV接收其他流,但是无法使其与gstreamer一起使用.我搜索了此问题,但找不到任何有用的信息,因此,我将非常感谢您的帮助.

I was able to receive other streams using OpenCV, but I can't get it to work with gstreamer. I searched for this problem, but I can't find anything helpful, so I would really appreciate some help.

推荐答案

我再次尝试了此问题,现在可以使用了.我会发布我的操作方法,希望其他人会更轻松.

I have given this problem another try, and it works now. I'll post how I did it in the hope others will have an easier time.

我按照 wumpus 使其起作用.在PC端,我运行:

I followed the instructions by wumpus to make it work. On the pc side I run:

#include <opencv2/opencv.hpp>
int main(int argc, char *argv[])
{
    cv::VideoCapture cap("udpsrc port=5000 ! gdpdepay ! rtph264depay ! avdec_h264 ! videoconvert ! appsink sync=false");

    return 0;
}

然后我在树莓派上运行:

And then I run on the raspberry pi:

gst-launch-1.0 rpicamsrc bitrate=3000000 ! video/x-h264, width=960, height=720 ! h264parse ! queue ! rtph264pay config-interval=1 pt=96 ! gdppay ! udpsink host=192.168.1.85 port=5000

要执行此操作,您需要在树莓派上安装gstreamer和rpicamsrc.

To make this work you need to install gstreamer and rpicamsrc on the raspberry pi.

此外,您还需要在PC上使用gstreamer 32位编译opencv.首先安装gstreamer(开发人员版本),然后编译opencv.有关帮助的信息,请参见在Visual Studio中编译opencv.

Also you need to have opencv compiled with gstreamer 32 bit on your pc. First install gstreamer, developer version, and then compile opencv. See this for help on compiling opencv in visual studio.

这篇关于在opencv中使用gstreamer从raspberrry pi捕获流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆