- Install opencv with conda
- Installing opencv 3.1 with anaconda python3?
- 7 Answers 7
- Anaconda opencv install python 3
- Working with Images — Getting Started
- Working with Images — Image Processing
- Working with Images — Feature Detection and Description
- Working with Images — Drawing Functions
- Working with Videos
- Applications and Projects
- OpenCV Projects
Install opencv with conda
This question is different from «How do I install Python OpenCV through Conda?» because that question was asked more than 5 years ago, when all packages had different versions. I tried ALL answers to that question, and neither worked. See the text of question for details. How to install opencv with conda now, in July 2019? On a freshly installed anaconda, I did conda update conda (succesfully) then tried the following:
(base) C:\Users\mlearning>python Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv2' >>> import cv Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv' (base) C:\Users\mlearning>conda install -c menpo opencv3 Collecting package metadata (repodata.json): done Solving environment: (goes into infinite loop, after 10 minutes I pressed ^C) (base) C:\Users\mlearning>conda install opencv Collecting package metadata (repodata.json): done Solving environment: failed Initial quick solve with frozen env failed. Unfreezing env and trying again. Solving environment: failed UnsatisfiableError: The following specifications were found to be incompatible with each other: Package zipp conflicts for: importlib_metadata -> zipp[version='>=0.3.2'] path.py -> importlib_metadata[version='>=0.5'] -> zipp[version='>=0.3.2'] anaconda==2019.03=py37_0 -> importlib_metadata==0.8=py37_0 -> zipp[version='>=0.3.2'] zipp Package importlib_metadata conflicts for: anaconda==2019.03=py37_0 -> importlib_metadata==0.8=py37_0 path.py -> importlib_metadata[version='>=0.5'] Package hdf5 conflicts for: anaconda==2019.03=py37_0 -> h5py==2.9.0=py37h5e291fa_0 -> hdf5[version='>=1.10.4, hdf5[version='>=1.10.2,=1.8.18,=1.8.20, hdf5[version='>=1.10.1,=1.10.2,=1.10.4,=1.8.18, hdf5[version='>=1.10.1,=1.8.18,=1.8.18, mkl-service==1.1.2=py37hb782905_5 (base) C:\Users\mlearning>conda install -c conda-forge opencv Collecting package metadata (repodata.json): done Solving environment: failed Initial quick solve with frozen env failed. Unfreezing env and trying again. Solving environment: failed UnsatisfiableError: The following specifications were found to be incompatible with each other: Package hdf5 conflicts for: anaconda==2019.03=py37_0 -> hdf5==1.10.4=h7ebc959_0 h5py -> hdf5[version='1.10.1,1.8.17|1.8.17.*,1.8.18|1.8.18.*,>=1.10.2,=1.10.3,=1.8.20, hdf5[version='1.8.18|1.8.18.*,>=1.10.4,=1.8.18,=1.8.18, importlib_metadata[version='>=0.5']
Installing opencv 3.1 with anaconda python3?
But after installing it I can’t import cv2 within python3 of anaconda. I can however import cv2 from builtin python2 command. So I suppose it build for the python2 version as stated in the last line. How do I build for anaconda python3 ?
7 Answers 7
I think you don’t need to build OpenCV for anaconda, there is this very handy tool called ‘conda’ that is available in your terminal once you have installed the Anaconda python distribution.
I found this site which gives instruction on how to install opencv3
https://anaconda.org/menpo/opencv3
I personally installed it myself so just try follow along with these instructions.
If you have the Anaconda python distribution installed in your system, you can issue this command (assuming you are working on linux) fire up the terminal:
conda install -c menpo opencv
If the version of python install in your Anaconda is 2.7, the command above should install OpenCV 3.1, but if the version of your python is 3.5, then you should change ‘opencv’ in the last line to ‘opencv3’
conda install -c menpo opencv3
This should install OpenCV in your Anaconda. To see if you have installed it successfully, fire up your Python and issue the following command:
import cv2 # import the opencv library cv2.__version__ # this will print the version of your opencv3
I think the support for cuda is already in OpenCV. I found this link that says something about Cuda Module in OpenCV. You might wanna check it out. Here is the link: docs.opencv.org/3.1.0/d2/dbc/cuda_intro.html
If you are getting an error like the following:
UnsatisfiableError: The following specifications were found to be in conflict: opencv 2.4.11* -> numpy 1.9* -> python 2.6* -> openssl 1.0.1* python 3.6* Use "conda info " to see the dependencies for each package.
Just install python 3.5 and try again.
conda install python=3.5 conda install -c menpo opencv # whichever conda install -c menpo opencv3 # you need
Try this method it worked for me. Anaconda3-4
conda create -n opencv activate opencv conda install -c https://conda.binstar.org/menpo opencv3
None of the methods above worked for me. However, I found that this one liner works for me:
conda install -c conda-forge opencv
With conda v4.3.16 and python v3.6 this command worked for me:
conda install -c anaconda opencv
If you want to compile opencv against a specific anaconda environment, you can specify the PYTHON_EXECUTABLE, PYTHON_INCLUDE and PYTHON_LIBRARY, PYTHON_PACKAGES_PATH, PYTHON_NUMPY_INCLUDE_DIR variables in cmake .
In the following example I have an opencv340 anaconda environment located in /home/yourself/anaconda3/envs/opencv340 and so I’ll specifiy the above variables for cmake as follows:
-DPYTHON_EXECUTABLE=/home/yourself/anaconda3/envs/opencv340/bin/python3 \ -DPYTHON_INCLUDE=/home/yourself/anaconda3/envs/opencv340/include \ -DPYTHON_LIBRARY=/home/yourself/anaconda3/envs/opencv340/lib/libpython3.6m.so \ -DPYTHON_PACKAGES_PATH=/home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages \ -DPYTHON_NUMPY_INCLUDE_DIR=/home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages/core/include
You’ll then see that opencv pick the correct python, the one in the anaconda environment of which you gave the path of.
You then copy the cv2*.so from your opencv build directory to the site-packages of your anaconda environment.
Your site-packages directory should be located somewhere like:
You can get the actual location from a python console with:
>>> import sys >>> print(next(p for p in sys.path if 'site-packages' in p))
Then (adapt accordingly to your case and cv2*.so actual name):
cp /path/to/your/opencv/build/directory/lib/python3.6/site-packages/cv2.cpython-36m-x86_64-linux-gnu.so /home/yourself/anaconda3/envs/opencv340/lib/python3.6/site-packages/.
And you should be able to import cv2 from a python console.
I’ve just done so (ubuntu 16.04).
conda: 4.7.10, python: 3.7.3, channel: default
Installing opencv from the default channel worked for me. I installed into a clean environment and had no conflicts.
The following NEW packages will be INSTALLED: blas pkgs/main/osx-64::blas-1.0-mkl bzip2 pkgs/main/osx-64::bzip2-1.0.8-h1de35cc_0 cairo pkgs/main/osx-64::cairo-1.14.12-hc4e6be7_4 ffmpeg pkgs/main/osx-64::ffmpeg-4.0-h01ea3c9_0 fontconfig pkgs/main/osx-64::fontconfig-2.13.0-h5d5b041_1 freetype pkgs/main/osx-64::freetype-2.9.1-hb4e5f40_0 gettext pkgs/main/osx-64::gettext-0.19.8.1-h15daf44_3 glib pkgs/main/osx-64::glib-2.56.2-hd9629dc_0 graphite2 pkgs/main/osx-64::graphite2-1.3.13-h2098e52_0 harfbuzz pkgs/main/osx-64::harfbuzz-1.8.8-hb8d4a28_0 hdf5 pkgs/main/osx-64::hdf5-1.10.2-hfa1e0ec_1 icu pkgs/main/osx-64::icu-58.2-h4b95b61_1 intel-openmp pkgs/main/osx-64::intel-openmp-2019.4-233 jasper pkgs/main/osx-64::jasper-2.0.14-h636a363_1 jpeg pkgs/main/osx-64::jpeg-9b-he5867d9_2 libgfortran pkgs/main/osx-64::libgfortran-3.0.1-h93005f0_2 libiconv pkgs/main/osx-64::libiconv-1.15-hdd342a3_7 libopencv pkgs/main/osx-64::libopencv-3.4.2-h7c891bd_1 libopus pkgs/main/osx-64::libopus-1.3-h1de35cc_0 libpng pkgs/main/osx-64::libpng-1.6.37-ha441bb4_0 libtiff pkgs/main/osx-64::libtiff-4.0.10-hcb84e12_2 libvpx pkgs/main/osx-64::libvpx-1.7.0-h378b8a2_0 libxml2 pkgs/main/osx-64::libxml2-2.9.9-hf6e021a_1 mkl pkgs/main/osx-64::mkl-2019.4-233 mkl_fft pkgs/main/osx-64::mkl_fft-1.0.12-py37h5e564d8_0 mkl_random pkgs/main/osx-64::mkl_random-1.0.2-py37h27c97d8_0 numpy pkgs/main/osx-64::numpy-1.16.4-py37hacdab7b_0 numpy-base pkgs/main/osx-64::numpy-base-1.16.4-py37h6575580_0 opencv pkgs/main/osx-64::opencv-3.4.2-py37h6fd60c2_1 pcre pkgs/main/osx-64::pcre-8.43-h0a44026_0 pixman pkgs/main/osx-64::pixman-0.38.0-h1de35cc_0 py-opencv pkgs/main/osx-64::py-opencv-3.4.2-py37h7c891bd_1 zstd pkgs/main/osx-64::zstd-1.3.7-h5bba6e5_0
$python Python 3.7.3 (default, Mar 27 2019, 16:54:48) [Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import cv2 >>> cv2.__version__ '3.4.2' >>>
Anaconda opencv install python 3
Working with Images — Getting Started
Working with Images — Image Processing
- Image Resizing using OpenCV | Python
- Python OpenCV | cv2.erode() method
- Python | Image blurring using OpenCV
- Python OpenCV | cv2.copyMakeBorder() method
- Python | Grayscaling of Images using OpenCV
- Image Processing in Python (Scaling, Rotating, Shifting and Edge Detection)
- Erosion and Dilation of images using OpenCV in python
- OpenCV Python Program to analyze an image using Histogram
- Histograms Equalization in OpenCV
- Python | Thresholding techniques using OpenCV | Set-1 (Simple Thresholding)
- Python | Thresholding techniques using OpenCV | Set-2 (Adaptive Thresholding)
- Python | Thresholding techniques using OpenCV | Set-3 (Otsu Thresholding)
- OpenCV: Segmentation using Thresholding
- Python OpenCV | cv2.cvtColor() method
- Filter Color with OpenCV
- Python | Denoising of colored images using opencv
- Python | Visualizing image in different color spaces
- Find Co-ordinates of Contours using OpenCV | Python
- Python | Bilateral Filtering
- Image Inpainting using OpenCV
- Python | Intensity Transformation Operations on Images
- Python | Image Registration using OpenCV
- Python | Background subtraction using OpenCV
- Background Subtraction in an Image using Concept of Running Average
- Python | Foreground Extraction in an Image using Grabcut Algorithm
- Python | Morphological Operations in Image Processing (Opening) | Set-1
- Python | Morphological Operations in Image Processing (Closing) | Set-2
- Python | Morphological Operations in Image Processing (Gradient) | Set-3
- Image segmentation using Morphological operations in Python
- Image Translation using OpenCV | Python
- Image Pyramid using OpenCV | Python
Working with Images — Feature Detection and Description
Working with Images — Drawing Functions
Working with Videos
Applications and Projects
- Python | Program to extract frames using OpenCV
- Displaying the coordinates of the points clicked on the image using Python-OpenCV
- White and black dot detection using OpenCV | Python
- Python | OpenCV BGR color palette with trackbars
- Draw a rectangular shape and extract objects using Python’s OpenCV
- Invisible Cloak using OpenCV | Python Project
- ML | Unsupervised Face Clustering Pipeline
- Saving Operated Video from a webcam using OpenCV
- Face Detection using Python and OpenCV with webcam
- Opening multiple color windows to capture using OpenCV in Python
- Python | Play a video in reverse mode using OpenCV
- Template matching using OpenCV in Python
- Cartooning an Image using OpenCV – Python
- Vehicle detection using OpenCV Python
- Count number of Faces using Python – OpenCV
- Live Webcam Drawing using OpenCV
- Detect and Recognize Car License Plate from a video in real time
OpenCV Projects
- Build GUI Application Pencil Sketch from Photo in Python
- Python OpenCV – Drowsiness Detection
- Face Alignment with OpenCV and Python
- Age Detection using Deep Learning in OpenCV
- Right and Left Hand Detection Using Python
- OpenCV Python: How to detect if a window is closed?
- Save frames of live video with timestamps – Python OpenCV
- Detecting low contrast images with OpenCV, scikit-image, and Python
- Animate image using OpenCV in Python
- Drawing a cross on an image with OpenCV
- Blur and anonymize faces with OpenCV and Python
- Face detection using Cascade Classifier using OpenCV-Python
- Real time object color detection using OpenCV
- Python – Writing to video with OpenCV
- Add image to a live camera feed using OpenCV-Python
- Face and Hand Landmarks Detection using Python – Mediapipe, OpenCV
- Emotion Based Music Player – Python Project
- Realtime Distance Estimation Using OpenCV – Python
- Webcam QR code scanner using OpenCV
- Color Identification in Images using Python – OpenCV
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- Opencv Python program for Face Detection