How do I resolve debug/release conflict after inst

2019-08-07 14:34发布

问题:

Tried to get started with OpenCV under Python today, although I have no experience with the former and very little experience with the latter. Since I am inexperienced, I followed a canned approach for the install, as detailed below. Now I am trying to figure out if I need to install from source.

Started by downloading and installing Anaconda with Python 2.7.

Downloaded OpenCV 3.1.0 for Windows and moved the cv2.pyd file into C:\Anaconda2\Lib\site-packages. I believe this means I installed a binary rather than from source. Didn't tinker with any pathnames or environmental variables at this point.

Used Anaconda Launcher to start Spyder. import cv2 ran in the Spyder console without complaint. print cv2.__version__ returned 3.1.0, which I interpreted as a successful install.

Trouble began when I tried to do something. cv2.imread is returning a None value. The obvious explanation for this is that I am supplying the wrong filename but I don't think that's it. I ran os.listdir('.') and then cv2.imread() to eliminate this possibility. The more sinister explanation is that I have mixed Debug and Release libraries (see this thread OpenCV imread(filename) fails in debug mode when using release libraries).

My question is: how do I check if a release / debug conflict is indeed causing the problem? I see some advice that references changing CMake parameters and rebuilding but since I just dropped a binary into a folder, that doesn't really relate to how I installed OpenCV. This brings me back to the question I started with: do I need to abandon the binary and reinstall from the source? That is a daunting prospect for me. I ran cv2.getBuildInformation() and it dumped a bunch of text on my console but I couldn't figure out what it meant. It seemed to reference both Release and Debug modes.

EDIT: I'm running 64 bit Windows 7 Pro

回答1:

You might want to install OpenCV via conda packages which downloads the binaries and does all the configuration for you. Open a command window (cmd.exe) and type:

conda update conda
conda install --channel https://conda.anaconda.org/menpo opencv

BUT, since you are starting I would recommend you to use Python 3. If you prefer not to do a fresh installation, you can create a conda environment with python 3.4 which runs independently and will not mesh up any of your installations:

conda create -n OpenCVenv python=3.4

To activate this environment you will need to run the following command every time you want to use opencv or install new packages

activate OpenCVenv

Once you have activated the environment you can install opencv3:

conda install --channel https://conda.anaconda.org/menpo opencv3

Notice that if you want to install the different packages such as Spyder you can do so:

conda install spyder

That's because Spyder is supported within Anaconda. For example you can install all the packages included en Anaconda

conda install anaconda