我试图通过Anaconda为Python安装OpenCV,但我似乎无法解决这个问题。

我试着

conda install opencv
conda install cv2

我也试着搜索

conda search cv

没有雪茄。我无意中看到这个列出了opencv作为一个包含包:

http://docs.continuum.io/anaconda/pkgs.html

在运行conda info后,我注意到我的版本是3.4.1,但我似乎在网上找不到任何关于这个版本的信息。我对此很困惑。

我是不是遗漏了一些很明显的东西?如果opencv可用于Anaconda的以前版本,那么为什么它不能用于新版本呢?为什么这个链接只显示版本1.9.2的文档?


当前回答

你链接的页面好像不再包含opencv了。(有趣的是,我确实记得它在之前也被包括在内。)

在任何情况下,安装OpenCV到Anaconda,虽然无法通过conda,是相当微不足道的。你只需要下载一个文件。

Download OpenCV from https://opencv.org/releases/ and extract From the extracted folder, copy the file from the extracted directory: opencv/build/python/2.7/(either x86 or x64, depending on your Anaconda version)/cv2.pyd to your Anaconda site-packages directory, e.g., C:\Anaconda\Lib\site-packages To get FFmpeg within opencv to work, you'll have to add the directory that FFmpeg is located in to the path (e.g., opencv/sources/3rdparty/ffmpeg). Then you'll have to find the DLL file in that folder (e.g., opencv_ffmpeg_64.dll) and copy or rename it to a filename that includes the opencv version you are installing, (e.g., opencv_ffmpeg249_64) for 2.4.9.

现在在Python提示符下,你应该可以输入“import cv2”…要验证它是否有效,输入“print cv2”。__version__”,它应该打印出你下载的OpenCV版本。

其他回答

虽然不是通过Conda,这是Ubuntu特有的,安装OpenCV的所有贡献模块,如SIFT和SURF,最简单的方法是使用:

PIP安装opencv-contrib-python

它支持Python2.7+和Python 3.4+

如果你选择不内置contribs,你可以这样做:

PIP安装opencv-python

在运行这些命令之前,你需要安装以下依赖项:

Sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

这是一个关于在Ubuntu上设置OpenCV的好教程: https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961

我试着按照命令,它工作得很好

Conda install -c Conda -forge opencv

一旦你点击命令,它就会询问yes或no

如果选择“是”,它将继续安装所有所需的软件包

我是这样安装的:

$ conda install --channel https://conda.anaconda.org/conda-forge opencv

我尝试conda直接安装opencv,但它不适合我,因为我使用的是Python 3.5,这是conda中默认opencv库的更高版本。后来,我尝试了“anaconda/opencv”,但它也不工作。我最终发现conda-forge/opencv适用于Python 3.5。

在Anaconda窗口中安装当前版本OpenCV 3.3的正确命令:

conda install -c conda-forge opencv

or

conda install -c conda-forge/label/broken opencv

3.2使用这个:

conda install -c menpo opencv3

你链接的页面好像不再包含opencv了。(有趣的是,我确实记得它在之前也被包括在内。)

在任何情况下,安装OpenCV到Anaconda,虽然无法通过conda,是相当微不足道的。你只需要下载一个文件。

Download OpenCV from https://opencv.org/releases/ and extract From the extracted folder, copy the file from the extracted directory: opencv/build/python/2.7/(either x86 or x64, depending on your Anaconda version)/cv2.pyd to your Anaconda site-packages directory, e.g., C:\Anaconda\Lib\site-packages To get FFmpeg within opencv to work, you'll have to add the directory that FFmpeg is located in to the path (e.g., opencv/sources/3rdparty/ffmpeg). Then you'll have to find the DLL file in that folder (e.g., opencv_ffmpeg_64.dll) and copy or rename it to a filename that includes the opencv version you are installing, (e.g., opencv_ffmpeg249_64) for 2.4.9.

现在在Python提示符下,你应该可以输入“import cv2”…要验证它是否有效,输入“print cv2”。__version__”,它应该打印出你下载的OpenCV版本。