在Anaconda下安装OpenCV后如何解决调试/发布冲突 [英] How do I resolve debug/release conflict after installing OpenCV under Anaconda

查看:312
本文介绍了在Anaconda下安装OpenCV后如何解决调试/发布冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管我对前者没有任何经验,而对后者却很少有经验,但是今天尝试在Python下开始使用OpenCV.由于我没有经验,因此我按照固定的方式进行安装,如下所述.现在,我试图确定是否需要从源代码安装.

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.

首先下载并安装带有Python 2.7的Anaconda.

Started by downloading and installing Anaconda with Python 2.7.

下载了适用于Windows的OpenCV 3.1.0,并将 cv2.pyd 文件移动到了 C:\ Anaconda2 \ Lib \ site-packages 中.我相信这意味着我安装了二进制文件,而不是源代码.此时尚未修改任何路径名或环境变量.

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.

使用Anaconda Launcher启动Spyder. import cv2在Spyder控制台中运行而没有任何抱怨. print cv2.__version__返回了3.1.0,我认为安装成功.

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.

当我尝试做某事时,麻烦就开始了. cv2.imread返回一个None值.对此的明显解释是我提供了错误的文件名,但我认为不是那样.我先运行os.listdir('.'),然后运行cv2.imread(),以消除这种可能性.更险恶的解释是,我混合使用了Debug和Release库(请参见以下线程

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).

我的问题是:如何检查发布/调试冲突是否确实引起了问题?我看到一些有关更改CMake参数和重建的建议,但是由于我只是将二进制文件放入了文件夹中,因此与我安装OpenCV的方式无关.这使我回到最初的问题:是否需要放弃二进制文件并从源代码重新安装?对我来说,这是一个艰巨的前景.我运行cv2.getBuildInformation(),它在控制台上转储了一堆文本,但我不知道这是什么意思.似乎同时引用了发布和调试模式.

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.

我正在运行64位Windows 7 Pro

I'm running 64 bit Windows 7 Pro

推荐答案

您可能希望通过 conda软件包安装OpenCV 下载二进制文件并为您完成所有配置.打开命令窗口(cmd.exe)并输入:

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

但是,由于您是从入门开始,所以我建议您使用Python3.如果您不想进行全新安装,则可以使用python 3.4创建一个conda环境,该环境可以独立运行并且不会与您的任何安装组合在一起:

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

要激活此环境,您每次需要使用opencv或安装新软件包时都需要运行以下命令

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

一旦激活了环境,就可以安装opencv3:

Once you have activated the environment you can install opencv3:

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

请注意,如果要安装不同的软件包(例如Spyder),可以执行以下操作:

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

conda install spyder

那是因为Anaconda支持Spyder.例如,您可以安装Anaconda随附的所有软件包

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

conda install anaconda

这篇关于在Anaconda下安装OpenCV后如何解决调试/发布冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆