Include OpenCV library into a project.
-
I installed OpenCV
sudo apt-get install libopencv-dev
Now I open a project and in main.cpp include
#include "opencv2/opencv.hpp"
Qt sees the directory and files in it. But when I compile I get a lot of errors in the opencv library files. Why?
May be I should include it in the *.pro file - LIB+= ????? - what should I include? -
@jenya7 said in Include OpenCV library into a project.:
May be I should include it in the *.pro file - LIB+= ?
Yes.
"what should I include?" - all OpenCV libs you're using.
Which libs exactly you can deduce from the error messages and then checking OpenCV documentation. -
The errors I get
-1: error: main.o: in function cv::String::~String()': -1: error: main.o: in function cv::String::operator=(cv::String const&)' :/usr/include/opencv2/core/cvstd.hpp:672: error: undefined reference to `cv::String::deallocate()' -1: error: collect2: error: ld returned 1 exit status
What exactly I should include? In usr/include/ I see opencv2 folder with a lot of folders and files in it.
I found the solution
LIBS += -lopencv_core -lopencv_imgproc -lopencv_imgcodecs
Now I’m facing another problem - Build is OK but when I run I get
qt5ct: using qt5ct plugin GLib-GObject-WARNING **: 11:53:16.119: cannot register existing type ‘GtkWidget’ GLib-GObject-CRITICAL **: 11:53:16.119: g_type_add_interface_static: assertion ‘G_TYPE_IS_INSTANTIATABLE (instance_type)’ failed GLib-GObject-WARNING **: 11:53:16.119: cannot register existing type ‘GtkBuildable’ GLib-GObject-CRITICAL **: 11:53:16.119: g_type_interface_add_prerequisite: assertion ‘G_TYPE_IS_INTERFACE (interface_type)’ failed GLib-CRITICAL **: 11:53:16.119: g_once_init_leave: assertion ‘result != 0’ failed GLib-GObject-CRITICAL **: 11:53:16.119: g_type_add_interface_static: assertion ‘G_TYPE_IS_INSTANTIATABLE (instance_type)’ failed GLib-GObject-CRITICAL **: 11:53:16.119: g_type_register_static: assertion ‘parent_type > 0’ failed
I found a fix
sudo nano /etc/xdg/qt5ct/qt5ct.conf
replace style=gtk2 with style=gtk3