C 如何在Gstreamer插件链函数中解析GstBuffer和Mat之间的图像

C 如何在Gstreamer插件链函数中解析GstBuffer和Mat之间的图像,c,plugins,computer-vision,gstreamer,mat,C,Plugins,Computer Vision,Gstreamer,Mat,我正在尝试基于其模板实现一个Gstreamer plugin _chain函数,它只是将输入视频帧(BGRx)替换为相同大小的转换图像,如下所示: static GstFlowReturn gst_myplugin_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) { Gstmyplugin *filter; filter = GST_MYPLUGIN (parent); if(filter->silent ==

我正在尝试基于其模板实现一个Gstreamer plugin _chain函数,它只是将输入视频帧(BGRx)替换为相同大小的转换图像,如下所示:

static GstFlowReturn gst_myplugin_chain (GstPad * pad, GstObject * parent, GstBuffer * buf) {
  Gstmyplugin *filter;
  filter = GST_MYPLUGIN (parent);
  if(filter->silent == FALSE)
     g_print("I'm plugged, therefore I'm in. \n");
  // retrieve pass-in image frame from input buf
  GstMapInfo map;
  gst_buffer_map(buf, &map, GST_MAP_READ);
  cv::Mat frame(cv::Size(width, height), CV_8UC4, (char *)map.data, cv::Mat::AUTOSTEP);      //Q1

  // check the orignal frame
  cv::imshow("Input image", frame);           //Q2

  // convert to new image by same size
  cv::Mat out = my_convert(frame);

  // how to populate output buffer from Mat out then
  GstBuffer *out_buf = ???              //Q3

  //return gst_pad_push(filter->srcpad, buf);   transparent filter in plugin template

  return gst_pad_push(filer->srcpad, out_buf);   //send my converted image
}
所以有三个问题(也在上面几行中标出):

Q1:如何获取输入图像的宽度和高度

问题2:为什么解析后的图像不能像视频中那样正确显示

问题3:如何填充输出缓冲区


我在网上搜索了好几天,但仍然没有找到答案。

嗨,编辑了你的帖子,所以它不会触发任何人,更具可读性。检查此注释-只有一些memcpy从Mat::data成员变量获取数据。不知道它是否正确。检查这条评论,这样当你得到原始数据时,你就可以使用GstMap并将原始数据映射到GstBuffer。感谢nayana澄清了这一点,这对理解非常有帮助。从语言上来说,如果你已经弄明白了,甚至回答你自己的问题也是一件好事:)它可以帮助其他人SQ1-我猜你是从caps得到的,当caps活动在第2季度到来时,您可以存储哪些内容-视觉上发生了什么(打开窗口,显示garbadge?)?我不知道,也许你使用的格式和缓冲区中的不同?Q3-默认构造GstBuffer,使用GST_map_WRITE映射out_buf缓冲区,并将数据存储到map.data中