GStreamer-CRITICAL **:gst_element_get_state:断言'GST_IS_ELEMENT(element)'在Opencv中失败错误

时间:2018-11-27 05:37:22

标签: opencv gstreamer gstreamer-1.0

我试图在Windows上使用Opencv通过GSTREAMER API打开网络摄像头,但 运行时出现此错误

  

GStreamer-CRITICAL **:gst_element_get_state:断言“ GST_IS_ELEMENT(元素)”失败   OpenCV | GStreamer警告:GStreamer:无法查询管道状态

下面是代码正在运行

VideoCapture capture(0,CAP_GSTREAMER);

if (capture.isOpened()) {
    std::cout << "Camera 0 via " << capture.getBackendName() << " backend" << std::endl;
    std::cout << "Frame width: " << capture.get(CAP_PROP_FRAME_WIDTH) << std::endl;
    std::cout << "     height: " << capture.get(CAP_PROP_FRAME_HEIGHT) << std::endl;
    std::cout << "Capturing FPS: " << capture.get(CAP_PROP_FPS) << std::endl;
}

但是相机可以通过Gstreamer命令正常工作

  

gst-launch-1.0.exe -v ksvideosrc设备索引= 0!自动视频接收器

我在启用GStreamer的情况下构建了OpenCV4.0,这里到底缺少什么元素,对此是否有修复程序?

1 个答案:

答案 0 :(得分:2)

尝试以下代码:

const char* pipeline= "ksvideosrc device-index=0 ! autovideoconvert ! appsink";

int cap_id = CAP_GSTREAMER;

VideoCapture cap( pipeline, cap_id);