Opencv 4.5.3 (for windows) cannot run imshow()

When I download and installed latest opencv (4.5.3) for windows, I have problem with my C++ code.
It cannot run cv.imshow(). The error is shown in the picture:

I wonder if the opencv was compiled with GTK or something.
Do I have to install GTK library? I used to use another version opencv dlls built by my co-worker for 32bit and I have no such issue.

Thank you in advance!

[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\highgui\src\registry.impl.hpp (114) cv::highgui_backend::UIBackendRegistry::UIBackendRegistry UI: Enabled backends(4, sorted by priority): GTK(1000); GTK3(990); GTK2(980); WIN32(970) + BUILTIN(WIN32UI)
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load C:\LiuJun\Code\C\SUW1\x64\Debug\opencv_highgui_gtk453_64.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk453_64.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load C:\LiuJun\Code\C\SUW1\x64\Debug\opencv_highgui_gtk3453_64.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk3453_64.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load C:\LiuJun\Code\C\SUW1\x64\Debug\opencv_highgui_gtk2453_64.dll => FAILED
[ INFO:0] global c:\build\master_winpack-build-win64-vc15\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_highgui_gtk2453_64.dll => FAILED
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\highgui\src\backend.cpp (90) cv::highgui_backend::createUIBackend UI: using backend: WIN32 (priority=970)
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\highgui\src\window_w32.cpp (3009) cv::impl::Win32BackendUI::createWindow OpenCV/UI: Creating Win32UI window: out (1)

please, NO SCREENSHOTS of code or error msgs here, replace with TEXT, thank you.

you really can’t ? (hard to believe…)
there is no error here at all, only INFO messages
(it tries to load some plugins, that do not exist on your machine)
there wont be any such messages in RELEASE mode

no.
however, if you would have a gtk (or qt) based highgui plugin dll, you could choose that as backend at runtime

Well, I tried to show a number of images (with a loop), and only the first one was displayed.
Maybe you are correct that the first imshow() runs, but the following imshow() cannot run.

This whole screen of messages comes up after the first imshow() pops up and no more imshow() can be run.
This behavior is very different from the 32bit library.

1 Like

please show code (also try release build)

FIrst of all, thank you for your quick response!
I have tried release version and it works well!!!

Here is the code:

#include <iostream>
#include <string>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#if _WIN32 || _WIN64
#if _WIN64
#ifdef _DEBUG
#pragma comment(lib, "opencv_world453d.lib")
#else
#pragma comment(lib, "opencv_world453.lib")
#endif
#else
#ifdef _DEBUG
#pragma comment(lib, "opencv_world410_ghj_x86d.lib")
#else
#pragma comment(lib, "opencv_world410_ghj_x86.lib")
#endif
#endif

int main()
{
cv::Mat src_tm;

src_tm = cv::imread("C:\\testing-images\\ex1.bmp", cv::IMREAD_GRAYSCALE);

if (src_tm.empty()) {
std::cout << "No image file";
}
cv::imshow("first", src_tm);
cv::waitKey(0);
cv::imshow("second", src_tm);
cv::waitKey(0);
}

this will block, until you actually press a key !
(that’s why you do not see the 2nd imshow())

and please do not link libraries via #pragma, this is terribly non-portable.

I understand that waitKey(0) will block until I press the key.
But only in case of Debug/x64, there is no the 2nd imshow(), instead it will exit with error code:
In fact it throw except:
Exception thrown at 0x00007FFC380E5A26 (opencv_world453d.dll) in SUW1.exe: 0xC0000005: Access violation reading location 0x0000000000000010.

However for release/x64, there is no problem.
For 32bit there is no problem for both debug and release dll.

I am sure it is not a bug in my code, but I suspect there is a need to set some flag etc in Debug/x64

Here is what I see when press the key after the 1st imshow() appears

C:\LiuJun\Code\C\SUW1\x64\Debug\SUW1.exe (process 21348) exited with code -1073741819.

The part of A#pragma is done by my coworker when we work with the code using 32bit library.

Thank you for suggestion regarding #pragma!

your code is unlikely to be the problem, now.

which VS version do you use ? (is vc15 the right lib folder ?)
and your coworker ? the 32bit libs were obviously locally built.
can you try to build from src, too ?

did the code print that while running?

-1073741819 is 0xc0000005 and that means “access violation”, i.e. “segfault”.

Thank you for your persistence!

I use VS2019, version 16.10.4. and use vc15.
The Platform toolset in VS is Visual Studio 2019 (V142)

We want to use a clean and new laptop to install VS 2019 and the latest OpenCV to see if these are sufficient to start the programming in C++ with OpenCV
I only installed these 2 days ago. And I did not install anything else except python Opencv 3.7 which is working perfectly.

My old laptop has multiple OpenCV libraries, some are locally built, some are downloaded from release 3.5 onwards.
We never experienced such inconsistencies between Debug and Release versions.

I am thinking to build a local opencv or download an old version to see if there is a problem.

No. The first image shown by imshow() is correct.

I build both debug and release version of OpenCV, using my VS2019.
I have the exact result as I use the dlls downloaded.
For release version, it can run the second imshow() without problem.
For debug version, it shows the first image, but with a lot of “info” and then exit with error code.
Since this debug info is an option, I will try to unchecked it and build a debug version soon.