Building OpenCV w/ Python 3 + Qt5 Support - DLL problems

asked 2018-03-28 00:04:31 -0600

convoluted gravatar image

updated 2018-03-28 01:40:52 -0600

Hi all. Been struggling with this all day. I'm working on compiling OpenCV 3.4.1 with Python 3.6.4 (32-bit) and Qt 5.10.1 support using MinGW 5.3.0 (32-bit) on Windows 10 64-bit. I'm compiling from OpenCV sources directly and using MinGW provided alongside Qt5.

I've trimmed many of the options in CMake, but kept the following checked:

BUILD_JPEG
BUILD_PNG
BUILD_SHARED_LIBS
BUILD_opencv_*
ENABLE_OMIT_FRAME_POINTER
ENABLE_PIC
OPENCL_FOUND
USE_WIN32_FILEIO
WITH_DIRECTX
WITH_DSHOW
WITH_FFMPEG
WITH_JPEG
WITH_OPENGL
WITH_PNG
WITH_QT
WITH_VFW
WITH_WIN32UI

I had to make one small fix to cap_dshow.cpp, but aside from that the build goes well and the OpenCV DLL's can be found in "C:\OpenCV\opencv-3.4.1-release\install\x86\mingw\bin". Qt5 w/ OpenCV works perfect. I also have "cv2.cp36-win32.pyd" in C:\Python\Python36-32\Lib\site-packages.

When I launch Python 3.6.4 and run "import cv2" I get one of the following:

ImportError: DLL load failed: %1 is not a valid Win32 application
ImportError: DLL load failed: The specified module could not be found

I'm not sure why I'm getting DLL dependency issues. Everything is for 32-bit as far as I can tell, and has been added to my system path.

I also tried DependencyWalker on cv2.cp36-win32.pyd, and it shows that several DLLs are missing, such as API-MS-WIN-CORE-APIQUERY-L1-1-0.DLL. There's also several that are found in my 64-bit MikTex install. Not sure if this matter, but though I'd toss it out there.

Any help would be appreciated. Thanks!

edit retag flag offensive close merge delete

Comments

1

BUILD_SHARED_LIBS -- this should be OFF, else you're cv2.pyd relies on external dlls like opencv_core341.dll

disable that in cmake, rebuild & try again, please.

berak gravatar imageberak ( 2018-03-28 01:42:59 -0600 )edit
1

Just gave it a try. Re-ran over the last build using the same settings except BUILD_SHARED_LIBS = False. It completed just fine and "cv2.cp36-win32.pyd" is now 19,917 KB. Interestingly I'm still getting the same errors as before. Seems like there is still a .dll dependency. Any other suggestions? Anything else I can try?

convoluted gravatar imageconvoluted ( 2018-03-28 02:24:17 -0600 )edit
1

Ok, I think I've come up with something. Looking again at DependencyWalker, I notice that some Qt5 files were marked with a yellow question mark (e.g., Qt5Core.dll, Qt5Gui.dll, etc.). I added the path to the Qt5 binaries (since I have Qt5, these are available to me), and what do you know, I can now import cv2 in Python. Here's where I'm lost... why would cv2.cp36-win32.pyd need Qt5 binaries?

convoluted gravatar imageconvoluted ( 2018-03-28 03:34:18 -0600 )edit
1

you built WITH_QT, so the highgui window will use that.

berak gravatar imageberak ( 2018-03-28 03:56:39 -0600 )edit

Right, makes sense. Also, I went back to try building with shared libs and everything works fine as well. Thanks!

convoluted gravatar imageconvoluted ( 2018-03-28 04:15:24 -0600 )edit