首页 > 解决方案 > 在 Yocto Linux 中使用 Opencv 的 Gstreamer

问题描述

我有两个在不同处理器上运行的 Yocto 构建,我正在尝试使用 GStreamer 编写 OpenCV 代码,其中一个将发送数据包,另一个将接收。我面临的问题是,在接收器脚本中,程序卡在“VideoCapture”函数中并且没有进一步执行。接收器与HDMI屏幕连接,运行目标文件后显示器没有变化。下面我附上代码。

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

using namespace std;
using namespace cv;

int main(void)
{
        cout<<"in main function"<<endl;
        const char* gstrec="udpsrc port=5000 ! application/x-rtp,media=video,encoding-name=H264,payload=96,clock-rate=90000,framerate=30/1 ! \
                            rtpjitterbuffer latency=10 drop-on-latency=TRUE ! rtph264depay ! video/x-h264 ! h264parse ! decodebin ! video/x-raw,\
                            format=NV12 ! videoconvert ! video/x-raw,format=BGR ! appsink";

        cout<<"Gstreamer script running"<<endl;
        VideoCapture cap(gstrec,CAP_GSTREAMER);
        cout<<"You are out of VideoCapture function"<<endl;

    if(!cap.isOpened())
    {
        cout<<"VideoCapture not opened"<<endl;
        exit(-1);
    }

    cout<<"The videocapture is opened"<<endl;

    Mat frame;

    for(;;) {

        cap.read(frame);
        if(frame.empty())
            break;

        cout<<"In while loop"<<endl;
        imshow("Receiver", frame);
        if(waitKey(1) == 'r')
            break;
    }
    destroyWindow("Receiver");

return 0;
}

这是输出:

在主函数中

Gstreamer 脚本运行

[信息] bitstreamMode 1,chromaInterleave 0,mapType 0,tiled2LinearEnable 0

请注意,'cout << you are out of videocapture' 语句不会打印在屏幕上,并且连接到接收器的显示器没有显示任何变化。

标签: c++linuxopencvgstreameryocto

解决方案


推荐阅读