[英]Opening an OpenCV window in a gstreamer element
I'm trying to do a very basic Gstreamer element that opens an OpenCV window with an image. 我正在尝试做一个非常基本的Gstreamer元素,该元素会打开带有图像的OpenCV窗口。
In my element, I have a chain function that only calls the window-opening function called select_points(), which is in select_points.cpp. 在我的元素中,我有一个链函数,该函数仅调用select_points.cpp中的窗口打开函数select_points()。
the chain_function: 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);
}
Now in my select_points.cpp, I have the following code 现在在我的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 loaded\n");
cvNamedWindow("Select", CV_WINDOW_AUTOSIZE);
cvMoveWindow("Select", 200, 200); // offset from the UL corner of the screen
cvShowImage("Select",img);
cvDestroyWindow("Select");
cvReleaseImage(&img);
}
}
The problem is that when I run the pipeline with my element, it hangs when calling cvNamedWindow. 问题是,当我使用我的元素运行管道时,在调用cvNamedWindow时管道会挂起。 Any suggestions?
有什么建议么? Everything else works fine if I comment out select_points().
如果我将select_points()注释掉,其他所有东西都可以正常工作。
First , move cvNamedWindow()
out of select_points()
and into the main()
function, before the gstreamer pipeline is activated. 首先 ,在激活gstreamer管道之前,将
select_points()
cvNamedWindow()
从select_points()
cvNamedWindow()
移出并移入main()
函数。
Second , if you want to see the window you must add a call to cvWaitKey(0);
其次 ,如果要查看窗口,则必须添加对
cvWaitKey(0);
的调用cvWaitKey(0);
after cvShowImage()
is called. 调用
cvShowImage()
之后。 Else, you will end up displaying the image and immediately destroying the window, making it display nothing. 否则,您最终将显示图像并立即破坏窗口,使其不显示任何内容。
:) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.