Gtk + 3与OpenCV编译时出错 [英] Gtk+ 3 Error when compiling with OpenCV

查看:328
本文介绍了Gtk + 3与OpenCV编译时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在linux上使用源代码构建了OpenCV 3。我能够成功编译和运行OpenCV程序。然后我下载了Gtk + 3和所有必需的软件包(GLib 2.52,Pango 1.40,Gdk-Pixbuf 2.36,ATK 2.24 ,GObject-Introspection 1.52)。我能够成功编译和运行这个简单的程序编译:

  g ++ -std = c ++ 11 gtkexample.cpp` pkg-config --cflags gtk + -3.0` -o gtkexample`pkg-config --libs gtk + -3.0` 



源代码:

  #include< gtk-3.0 / gtk / gtk.h> 

int main(int argc,
char * argv [])
{
GtkWidget * window;
GdkRGBA * color;
gtk_init(& argc,& argv);
gdk_rgba_parse(color,(0,0,0));
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated(GTK_WINDOW(window),FALSE);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
gtk_widget_override_background_color(窗口,GTK_STATE_FLAG_NORMAL,颜色);
gtk_widget_show(window); (int i = 200; i <400; i ++)
gtk_window_move(GTK_WINDOW(window),i,200)的

;



gtk_main();

返回0;

$ / code>

成功编译后,我尝试使用Gtk +和FlyCapture摄像头执行我的OpenCV程序我遇到了:


Gtk-ERROR **:检测到GTK + 2.x符号使用GTK + 2.x和GTK + 3在同一过程中不受支持


pkg-config --cflags gtk + -3.0 是:

  -pthread -I / usr / local / include / gtk-3.0 -I / usr / local / include / gio-unix-2.0 / -I / usr / local / include / cairo -I / usr / local / include / pango-1.0 -I / usr / local / include / harfbuzz -I / usr / local / include / pango-1.0 -I / usr / local / include / atk-1.0 -I / usr / local / include / cairo -I / usr / local / include / gdk -pixbuf-2.0 -I / usr / local / include / glib-2.0 -I / usr / local / lib / glib-2.0 / include -I / usr / include / at-spi2-atk / 2.0 -I / usr / include /at-spi-2.0 -I / usr / include / dbus-1.0 -I / usr / lib / aarch64-linux-gnu / dbus-1.0 / include -I / usr / include / pixman-1 -I / usr / include / freetype2 -I / usr / include / libpng12 

pkg-config --libs gtk + -3.0 的输出是:

  -L / usr / local / lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo- gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 

片段的OpenCV程序看起来像:

  #includeFlyCapture2.h

#include< opencv2 /型芯/ core.hpp>
#include< opencv2 / highgui / highgui.hpp>
#include< opencv2 / objdetect / objdetect.hpp>
#include< opencv2 / imgproc / imgproc.hpp>
#include< opencv2 / highgui / highgui.hpp>
#include< opencv2 / core / cuda.hpp>
#include< opencv2 / cudalegacy / NCVHaarObjectDetection.hpp>
#include< opencv2 / cudaobjdetect.hpp>

#include< thread>
#include< iostream>
#include< vector>
#include< gtk-3.0 / gtk / gtk.h>

使用命名空间FlyCapture2;

int main(int argc,
char * argv [])
{
GtkWidget * window;

gtk_init(& argc,& argv); //这是发生错误的地方
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_decorated(GTK_WINDOW(window),FALSE);
gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);

gtk_widget_show(window);
gtk_main();
// ...
}

成功编译:

  g ++ -std = c ++ 11 FlyCap2_to_MatImage.cpp`pkg-config --cflags gtk + -3.0` -I / home / nvidia / flycapture.2.11.3.121_arm64 / include -I / usr / local / cuda-8.0 / include -o FlyCap2_to_MatImage`pkg-config --libs gtk + -3.0` -lflycapture -lopencv_core -lopencv_highgui -lopencv_objdetect -lopencv_imgproc -lopencv_cudaobjdetect 

我的问题是:


  • OpenCV 3可能使用旧版本的GTK +吗?

  • 我需要重新构建OpenCV以配置更新版本的Gtk +吗?


解决方案

考虑到在构建OpenCV之后已经安装了Gtk + 3 ,它很可能已经构建与Gtk + 3.因为它抱怨,它表明你已经有一些旧版本安装,并使用它。



因此,如果你想使用th e OpenCV中的GUI便利功能,您需要重新构建OpenCV,确保它是使用正确版本的Gtk +构建的。

然而,由于您提供了自己的GUI,看起来你并不需要使用OpenCV的那部分。由于您已将OpenCV构建为单独的模块,因此您可以无需链接 opencv_highgui 以避免冲突。


I have recently built OpenCV 3 from source on linux. I am able to successfully compile and run OpenCV programs.

I then downloaded Gtk+ 3 and all the required packages (GLib 2.52, Pango 1.40, Gdk-Pixbuf 2.36, ATK 2.24, GObject-Introspection 1.52). I am able to successfully compile and run this simple program compiling with:

g++ -std=c++11 gtkexample.cpp `pkg-config --cflags gtk+-3.0` -o gtkexample `pkg-config --libs gtk+-3.0`

Source code:

#include <gtk-3.0/gtk/gtk.h>

int main( int   argc,
      char *argv[] )
{
    GtkWidget *window;
    GdkRGBA *color;
    gtk_init (&argc, &argv);
    gdk_rgba_parse(color,"(0,0,0)");
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_decorated(GTK_WINDOW (window),FALSE);
    gtk_window_set_position(GTK_WINDOW (window), GTK_WIN_POS_CENTER);
    gtk_widget_override_background_color(window, GTK_STATE_FLAG_NORMAL, color);
    gtk_widget_show  (window);

    for (int i=200;i<400;i++)
        gtk_window_move(GTK_WINDOW (window),i,200);



    gtk_main ();

    return 0;
}

After successfully compiling I try to execute my OpenCV program with Gtk+ and a FlyCapture camera and I am faced with:

"Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported"

The output of pkg-config --cflags gtk+-3.0 is:

-pthread -I/usr/local/include/gtk-3.0 -I/usr/local/include/gio-unix-2.0/ -I/usr/local/include/cairo -I/usr/local/include/pango-1.0 -I/usr/local/include/harfbuzz -I/usr/local/include/pango-1.0 -I/usr/local/include/atk-1.0 -I/usr/local/include/cairo -I/usr/local/include/gdk-pixbuf-2.0 -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/aarch64-linux-gnu/dbus-1.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12

Output of pkg-config --libs gtk+-3.0 is :

-L/usr/local/lib -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

A snippet of the OpenCV program looks like:

#include "FlyCapture2.h"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include<opencv2/highgui/highgui.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudalegacy/NCVHaarObjectDetection.hpp>
#include <opencv2/cudaobjdetect.hpp>

#include <thread>
#include <iostream>
#include <vector>
#include <gtk-3.0/gtk/gtk.h>

using namespace FlyCapture2;

int main( int   argc,
      char *argv[])
{
    GtkWidget *window;

    gtk_init (&argc, &argv); //This is where the error occurs
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_decorated(GTK_WINDOW (window),FALSE);
    gtk_window_set_position(GTK_WINDOW (window), GTK_WIN_POS_CENTER);

    gtk_widget_show(window);
    gtk_main();
    //  ...
}

Compiling successfully with:

g++ -std=c++11 FlyCap2_to_MatImage.cpp `pkg-config --cflags gtk+-3.0` -I/home/nvidia/flycapture.2.11.3.121_arm64/include -I/usr/local/cuda-8.0/include -o FlyCap2_to_MatImage `pkg-config --libs gtk+-3.0` -lflycapture -lopencv_core -lopencv_highgui -lopencv_objdetect -lopencv_imgproc -lopencv_cudaobjdetect

My questions are:

  • Could OpenCV 3 possibly be using an old version of GTK+ ?
  • Will I have to rebuild OpenCV to configure with newer version of Gtk+ ?

解决方案

Considering you've installed Gtk+ 3 after building OpenCV, it's quite likely that it would have been built to work with Gtk+ 3. Since it complains, it suggests you already had some older version installed, and it uses that.

Hence, if you want to use the GUI convenience functions in OpenCV, you need to rebuild OpenCV, making sure it is built with with the correct version of Gtk+.

However, since you're providing your own GUI, it would seem that you don't really need to use that part of OpenCV. Since you have built OpenCV as individual modules, you could simply not link with opencv_highgui in order to avoid the conflict.

这篇关于Gtk + 3与OpenCV编译时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆