0
votes

I have a problem when I'm trying to use OpenCV (v3.1.0) in Python (v3.4). To make things more complicated, OpenCV is built with the "contrib" package and Qt support (v5.5).

This is what I did (this has some pitfalls on it's own, but those are out of the scope of this question):

  1. Install required software
    1. I installed WinPython (v3.4.4, 64 Bit version)
    2. I installed cmake (v3.6.0)
  2. Download sources
    1. I downloaded the Qt sources from the GIT repo
    2. I downloaded the OpenCV sources from the GIT repo
    3. I downloaded the OpenCV "contrib" sources from the GIT repo
  3. build sources -> RELEASE, 64 Bit (!)
    1. build Qt from sources
    2. build OpenCV from sources (with "contrib" modules)

cmake ( OpenCV 3.1.0 for python 3 ) already took care of copying the "cv2.pyd" to the "your/python/folder/Lib/site-modules" directory.

Now I have the problem that calling "import cv2" from python gives the error "

>>> import cv2
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
import cv2
ImportError: DLL load failed: Module not found

How can I find out which module is missing and how to solve it?

2

2 Answers

1
votes

What you may not want to do is just adding paths that are likely needed to your environment variables.

There is a way to find out what is missing:

  1. Download DependencyWalker
  2. open your "cv2.pyd" with the dependency walker
  3. Analyze your file (starts automatically when you select your file)
  4. Hit "F9" such that it shows the full paths to the required DLLs
  5. Check, which DLL files are missing
  6. Copy them to those folders

For me, it was the case that python/cv2.pyd searched to all the Qt DLLs in the folder where cv2.pyd is in.

I just copied them there and that was it.

0
votes

For Windows:

Step 1. Download python installer from https://www.python.org/downloads/ ,install python by double clicking this file and check the option for adding python to PATH as in given image.

As shon in image

Step 2. Download file "numpy‑1.15.4+mkl‑cp27‑cp27m‑win32.whl" from unofficial site.

Go to this file's location open command prompt and type-

pip install numpy‑1.15.4+mkl‑cp27‑cp27m‑win32.whl

Now go to python IDLE and type:

import numpy

It should give no error.

Step 3. Download file "scipy‑1.2.1‑cp27‑cp27m‑win32.whl" from unofficial site.

Go to this file's location open command prompt and type-

pip install scipy‑1.2.1‑cp27‑cp27m‑win32.whl

Now go to python IDLE and type:

import scipy

It should give no error.

step 4 : Download file "opencv_python‑2.4.13.7‑cp27‑cp27m‑win32.whl" from unofficial site.

Go to this file's location open command prompt and type-

pip install opencv_python‑2.4.13.7‑cp27‑cp27m‑win32.whl

Now go to python IDLE and type:

import cv2

It should give no error, means opencv installed successfully in windows.