Using OpenCV in Qt (Linux)

My code

 cv::Mat mat = cv::imread("David.jpg", cv::IMREAD_GRAYSCALE);
 cv::namedWindow("David", cv::WINDOW_NORMAL);
 cv::imshow("David", mat);

//just for a test
cv::Mat mat1;
split(mat, mat1);

I get the following errors

error: undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)' error: undefined reference to cv::namedWindow(cv::String const&, int)’

Why some of the functions from the cv namespace compiled (imread, split) and other (namedWindow, imshow) - undefined?

opencv version ? installed how ?

please show, how you compile & link this
(maybe it is as simple as a missing -lopencv_highgui)

1 Like

This way I installed

sudo apt-get install libopencv-dev
Then in *.pro file

LIBS += -lopencv_core -lopencv_imgproc -lopencv_imgcodecs

Qt sees the cv namespace and the functions. the errors pop up on a build action.
I suspect my installation (sudo apt-get install libopencv-dev) isn’t good. It installed it as a source files not as a library.

That’s it - missing -lopencv_highgui. Thank you.

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

1 Like