Reputation: 11
I would use the OpenCV libraries into a program using the Gtkmm graphic interface but when I try to open an image with cv::imread, there is an error message during the execution : gtk-error ** Using gtk+ 2.x and gtk+ 3 in the same process is not supported.
Here is a very simple sample code :
#include <gtkmm/main.h>
#include <gtkmm/window.h>
#include <gtkmm/image.h>
#include "opencv2/highgui/highgui.hpp"
int main(int argc, char* argv[]) {
Gtk::Main app(argc, argv);
Gtk::Image ImgGtk;
Gtk::Window Win0;
cv::Mat ImgOcv;
Win0.set_border_width(5);
Win0.set_default_size(250, 100);
ImgOcv= cv::imread("icone.png", -1);
ImgGtk.set("icone.png");
Win0.add(ImgGtk);
Win0.show_all();
Gtk::Main::run(Win0);
return 0;
}
The idea is to replace "ImgGtk.set("icone.png");" by a create_from_data and a gtk_img.set(pixbuf) or some things alike. The code above compile and link fine, but produces the above mentionned error during the exceution. Just remove the line 17 (ImgOcv= cv::imread("icone.png", -1);) and the error disapear, the image is displayed by ImgGtk.set("icone.png");.
Does anyone have heard about this kind of conflict? Does anybody know how to debug this?
I am using gtkmm 3.0 and have upgraded opencv to 2.4.5 but this did not solve the problem. The operating system is Ubuntu 12.04.
Thanking you in advance.
Upvotes: 1
Views: 1486
Reputation: 57920
OpenCV uses the version 2.0 API of the GTK library, which is not compatible with the version 3.0 API which your main program is using. Specifically, GTK contains code that tries to detect when they are being combined, and then crashes to let you know you can't do that.
There are three possible courses of action:
Upvotes: 1