我正在尝试构建一个程序,我使用gstreamer和opencv来操作图像。这是我的主要文件:
public class MessageEventArgs : EventArgs
{
public string Message { get; private set;}
public MessageEventArgs(string message)
{
Message = message;
}
}
public class MyReceiver : IDisposable
{
private Thread _thread;
private ManualResetEvent _terminating = new ManualResetEvent(false);
public void Start()
{
_thread = new Thread(() =>
{
try
{
IntPtr hPipe;
string dwWritten;
byte[] buffer = new byte[BUFSIZE];
NamedPipeClientStream pipeClient = new NamedPipeClientStream(".","testpipe", PipeDirection.In, PipeOptions.WriteThrough);
if (pipeClient.IsConnected != true) { pipeClient.Connect(); }
StreamReader sr = new StreamReader(pipeClient);
string temp;
while(!_terminating.WaitOne(0))
{
temp = "";
temp = sr.ReadLine();
if (temp != null)
{
OnMessage?.Invoke(temp);
}
if (temp != "QUIT")
{
sw.WriteLine("Response");
sw.Flush();
pipeClient.WaitForPipeDrain();
}
else
{
sw.WriteLine("Response");
_terminating.Set();
}
}
}
catch (Exception ex)
{
throw new Exception("Exception: " + ex.Message);
}
});
_thread.Start();
}
public void Dispose()
{
_terminating.Set();
_thread.Join();
}
public event EventHandler<MessageEventArgs> OnMessage;
}
// Example of how to use the Receiver class.
public class Form1: Form
{
MyReceiver _receiver;
public Form1()
{
InitializeComponent();
this.FormClosed += FormClosed;
_receiver = new MyReceiver();
_receiver.OnMessage += MessageReceived;
_receiver.Start();
}
public void MessageReceived(object sender, MessageEventArgs e)
{
// You need to invoke this, because the event is run on other than the UI thread.
this.Invoke(new Action(() =>
{
listBox1.Items.Add(e.Message);
});
}
public void FormClosed(object sender, EventArgs e)
{
_receiver.Dispose();
}
}
这是.pro文件:
#include "GstSource.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <iostream>
static const int Key_Escape = 27;
int main(int argc, char *argv[])
{
cv::namedWindow("Gstreamer");
cvMoveWindow("Gstreamer",100,100);
GstreamerPlayer player;
if (! player.open("videotestsrc") )
std::cerr << "Unable to open pipeline" << std::endl;
if ( !player.setWidth(640) || !player.setHeight(480) ) {
std::cerr << "Unable to change resolution" << std::endl;
return 1;
}
bool fps_readed = false;
while (true) {
if (!player.grabFrame()) {
std::cerr << "Failed to grab frame" << std::endl;
break;
}
GstreamerImage * frame = player.getImage();
if (!frame) {
std::cerr << "Failed to retrieve frame" << std::endl;
break;
}
if (!fps_readed) {
std::cout << "Video playing at " << player.getFps() << " fps" < std::endl;
fps_readed = true;
}
cv::Mat canvas = cv::Mat(frame->height, frame->width, CV_8UC3, frame->data);
if ( canvas.empty() )
break;
cv::imshow("Gstreamer", canvas);
int key = cv::waitKey(10);
if (key == Key_Escape)
break;
}
}
我得到147这种类型的错误:未定义引用.....因为许多函数被声明但未定义。他们的定义在哪里?我怎么能包括他们的定义?
答案 0 :(得分:1)
使用PKGCONFIG怎么样:
在你的专业人士:
CONFIG += pkgconfig
PKGCONFIG += gstreamer-1.0 gstreamer-video-1.0
您可以在shell中查看您拥有它们:
pkg-config --list-all | grep gst
如果指向正确的库,则检查一个包:
pkg-config --cflags gstreamer-1.0
应打印:
-pthread -I / usr / local / include / gstreamer-1.0 -I / usr / local / lib / gstreamer-1.0 / include -I / usr / include / glib-2.0 -I / usr / lib / x86_64- linux-gnu / glib-2.0 / include -L / usr / local / lib -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0
如果您没有.pc文件,则不会列出..您需要安装-dev版本的gstreamer软件包。
还有一个env变量可用于告诉pkg config在哪里查找.pc文件:
PKG_CONFIG_PATH=/home/something/gst/1.6/gst-devtools/validate/pkgconfig
Here有人试图以这种方式链接opencv ..