我试图通过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的文档?


当前回答

在Linux上,正如这里所讨论的,目前获得opencv的最佳方法是在conda-forge的loopbio:

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

如果你有一个“现代CPU”,也会有一个编译版本“支持所有现代CPU指令集扩展[…]]和反对libjpeg-turbo":

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo`

其他答案中提到的两个解决方案并不无条件有效:

The conda you get through conda install opencv or pip install opencv-python doesn't have gtk2 support, so you can't display images through imshow. Conda built by Menpo (conda install -c menpo opencv3) has gtk2 support, but they have only built OpenCV 3.2 for Python 3.5, not Python 3.6 Ubuntu 16.10 has deprecated libpng12, leading to a missing dependency and the following error when trying to import cv2: ImportError: libpng12.so.0: cannot open shared object file: No such file or directory, as discussed here

编辑:@Yamaneko指出,截至2017年6月14日,“loopbio的OpenCV 3.2.0版本存在一个问题。无声地读写视频失败。这是由于上游OpenCV问题与旧GCC的结合。详情请点击这里。有一个公关正在解决这个问题。”

其他回答

你链接的页面好像不再包含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版本。

Windows 7, conda 4.4.10 python 2.7.6 从非官方的Windows二进制文件下载了opencv包用于python扩展包。(选择python 2.4 AMD 64) 光盘下载 PIP install opencv_python Python run_some.py (import cv2…)似乎可以工作。 YMMV

Windows专用解决方案。OpenCV 3。为Python 3.x安装pip

下载.whl文件(cpMN,其中有Python M.N)。contrib包含opencv额外包。例如,假设你有Python 3.6和Windows 64位,你可以下载opencv_python - 3.2.0+contrib - cp36 - cp36m - win_amd64.whl

从命令提示符类型:

pip install opencv_python‑3.2.0+contrib‑cp36‑cp36m‑win_amd64.whl

你的conda列表中会有一个包:opencv-python 3.2.0+contrib <pip>

现在你可以测试它(没有错误):

>>> import cv2
>>>

原始的源代码页面,我采取的信息是在这里。

它在anaconda3 windows 10上工作,我已经在2019年12月5日下载了它。

首先,使用这个命令:

PIP安装opencv-contrib-python

之后,Windows将请求许可并重试:

PIP安装opencv-contrib-python——user

看看这个,它工作了!!

在Linux上,正如这里所讨论的,目前获得opencv的最佳方法是在conda-forge的loopbio:

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv

如果你有一个“现代CPU”,也会有一个编译版本“支持所有现代CPU指令集扩展[…]]和反对libjpeg-turbo":

conda install -c loopbio -c conda-forge -c pkgw-forge ffmpeg-feature ffmpeg gtk2 opencv-turbo`

其他答案中提到的两个解决方案并不无条件有效:

The conda you get through conda install opencv or pip install opencv-python doesn't have gtk2 support, so you can't display images through imshow. Conda built by Menpo (conda install -c menpo opencv3) has gtk2 support, but they have only built OpenCV 3.2 for Python 3.5, not Python 3.6 Ubuntu 16.10 has deprecated libpng12, leading to a missing dependency and the following error when trying to import cv2: ImportError: libpng12.so.0: cannot open shared object file: No such file or directory, as discussed here

编辑:@Yamaneko指出,截至2017年6月14日,“loopbio的OpenCV 3.2.0版本存在一个问题。无声地读写视频失败。这是由于上游OpenCV问题与旧GCC的结合。详情请点击这里。有一个公关正在解决这个问题。”