# Opencv 4.5.3 (for windows) cannot run imshow()

**URL:** <https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505>\
**Category:** C++\
**Tags:** build, plugin\_loader\
**Created:** [July 28, 2021, 10:08am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505 "2021-07-28T10:08:50Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 28, 2021, 10:08am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/1 "2021-07-28T10:08:50Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/0/0e25d4ab9122a97ee23a322fb2eacf7d1d70b13e.png)

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)

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 28, 2021, 10:14am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/2 "2021-07-28T10:14:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 28, 2021, 10:20am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/3 "2021-07-28T10:20:43Z")

</div>

> [@qceptliujun](#):
>
> It cannot run cv.imshow().

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

> [@qceptliujun](#):
>
> Do I have to install GTK library?

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

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 28, 2021, 10:58am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/4 "2021-07-28T10:58:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 28, 2021, 11:32am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/5 "2021-07-28T11:32:15Z")

</div>

> [@qceptliujun](#):
>
> 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.

please show code (also try release build)

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 28, 2021, 1:18pm UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/6 "2021-07-28T13:18:22Z")

</div>

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

Here is the code:

```auto
#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);
}

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 28, 2021, 1:32pm UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/7 "2021-07-28T13:32:11Z")

</div>

> [@qceptliujun](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 28, 2021, 2:08pm UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/8 "2021-07-28T14:08:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 28, 2021, 2:16pm UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/9 "2021-07-28T14:16:53Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [July 28, 2021, 2:57pm UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/10 "2021-07-28T14:57:09Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [July 29, 2021, 12:18am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/11 "2021-07-29T00:18:36Z")

</div>

> [@qceptliujun](#):
>
> ```auto
> std::cout << "No image file";
> 
> ```

did the code print that while running?

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

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 29, 2021, 12:24am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/12 "2021-07-29T00:24:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 29, 2021, 4:41am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/13 "2021-07-29T04:41:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [July 29, 2021, 6:44am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/14 "2021-07-29T06:44:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![falbala](https://avatars.discourse-cdn.com/v4/letter/f/9d8465/32.png) [@falbala](https://forum.opencv.org/u/falbala)\
**Post date:** [February 1, 2022, 4:27pm UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/15 "2022-02-01T16:27:16Z")

</div>

Hi,  
I’m running openCV 4.5.5, vs2017, VC15, and face the exact same behaviour. Images run properly when building vs2017, but in vs2017\_debug I get only first image. @qceptliujun did you move forward on this topic ?  
Thanks

---

<div class="post-metadata">

**Author:** ![qceptliujun](https://avatars.discourse-cdn.com/v4/letter/q/f9ae1b/32.png) [@qceptliujun](https://forum.opencv.org/u/qceptliujun)\
**Post date:** [April 14, 2022, 7:29am UTC](https://forum.opencv.org/t/opencv-4-5-3-for-windows-cannot-run-imshow/4505/16 "2022-04-14T07:29:11Z")

</div>

No. I don’t think I can fix this issue. But, you can always try release version, I think it is OK.

Also, I read somewhere (from a book), seems you cannot close the window manually, so just let code end with all windows.  
I haven’t tried this idea.
