在 gstreamer 元素中打开 OpenCV 窗口

Opening an OpenCV window in a gstreamer element

本文关键字:OpenCV 窗口 gstreamer 元素      更新时间:2023-10-16

我正在尝试做一个非常基本的Gstreamer元素,该元素打开一个带有图像的OpenCV窗口。

在我的元素中,我有一个链函数,它只调用名为 select_points() 的窗口打开函数,该函数在 select_points.cpp 中。

chain_function:

static GstFlowReturn
gst_georeg_chain (GstPad * pad, GstBuffer * buf)
{
  GstGeoreg *filter;
  georeg_val gvals;
  filter = GST_GEOREG (GST_OBJECT_PARENT (pad));
  get_data(&gvals);
  select_points(&gvals);
  return gst_pad_push (filter->srcpad, buf);
}

现在在我的select_points.cpp中,我有以下代码

#include <stdio.h>
#include "datasetup.h"
#include <opencv/cv.h>
#include <opencv/highgui.h>
using namespace cv;
extern "C" void select_points(georeg_val *gvals) //plugin is in C
{
  IplImage* img=0; 
  img=cvLoadImage(gvals->imageName,1);
  if(!img) 
  {
    printf("Could not load image file: n$%s$n",gvals->imageName);
  }
  else
  {        
    printf("Image was loadedn");
    cvNamedWindow("Select", CV_WINDOW_AUTOSIZE); 
    cvMoveWindow("Select", 200, 200); // offset from the UL corner of the screen
    cvShowImage("Select",img);
    cvDestroyWindow("Select");
    cvReleaseImage(&img); 
  }
}

问题是当我使用我的元素运行管道时,它在调用 cvNamedWindow 时挂起。有什么建议吗?如果我注释掉 select_points(),其他一切都很好。

首先,在激活 gstreamer 管道之前,将cvNamedWindow()移出select_points()并移入 main() 函数。

其次,如果要查看窗口,则必须在调用cvShowImage()后添加对cvWaitKey(0);的调用。否则,您最终将显示图像并立即破坏窗口,使其不显示任何内容。

:)