How do I install Python OpenCV through Conda?

2019-01-03 03:50发布

I'm trying to install OpenCV for Python through Anaconda, but I can't seem to figure this out.

I tried

conda install opencv
conda install cv2

I also tried searching

conda search cv

No cigar. I ran across this which lists opencv as an included package:

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

After running conda info I noticed my version is 3.4.1, but I couldn't seem to find any information about this version online. I'm pretty confused about this.

Am I missing something pretty obvious here? If opencv was available for a previous version of Anaconda, then why wouldn't it be available for the newer version? And why does that link only show me documentation for version 1.9.2?

30条回答
男人必须洒脱
2楼-- · 2019-01-03 04:36

I just wanted to update the brilliant answer by Atlas7.

If you're using OpenCV 3, change the test code to the following:

import cv2
cap=cv2.VideoCapture("input_video.mp4")
print cap.isOpened()   # True = read video successfully. False - fail to read video.

fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output.avi',fourcc, 20.0, (640,480))
print out.isOpened()  # True = write out video successfully. False - fail to write out video.

cap.release()
out.release()
查看更多
虎瘦雄心在
3楼-- · 2019-01-03 04:37

This works for me on Windows

conda install -c conda-forge opencv

conda install -c menpo opencv3

查看更多
我命由我不由天
4楼-- · 2019-01-03 04:38

I entered the following command in the command prompt:

conda install -c menpo opencv=2.4.11

This worked for me!!!

查看更多
叛逆
5楼-- · 2019-01-03 04:38

I think the easiest option that should work cross-platform and across various versions of Anaconda is

#Run Anaconda Prompt as an Administrator (on Windows) & execute the command below
#(you may need to use   sudo   on a Unix-Based or Mac system 
#to have the needed permissions)

conda install -c conda-forge opencv
查看更多
Root(大扎)
6楼-- · 2019-01-03 04:39

Like others, I had issues with Python 3.5.1/Anaconda 2.4.0 on OS X 10.11..

But I found a compatible package here:

https://anaconda.org/menpo/opencv3

It can be installed via the command line like so:

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

Worked like a charm. First time I've ever gotten OpenCV to work on 3.x!

查看更多
你好瞎i
7楼-- · 2019-01-03 04:39

An easy and straight forward solution is to install python3.5 first before installing opencv3

conda install python=3.5

followed by

conda install --channel https://conda.anaconda.org/menpo opencv3 
查看更多
登录 后发表回答