Complete guide to install OpenCV-4.2.0 in Windows 10
This post will guide you through all the steps for installing and configuring OpenCV-4.2.0 in Windows 10 (64-bit) for python use inside the Anaconda environment.
- OpenCV with Anaconda, for Python 3.6.0+ development
I will focus here on OpenCV for python 3.6.0+, my previous post for VC++ integration can be found here.
Note: To follow along with the tutorial, I will assume that you already have Anaconda and Python 3.6.0 installed. If not, please feel free to install these tools before continuing to read further.
The steps for installing OpenCV through Anaconda are pretty easy and straight forward. Don’t forget to add Anaconda to your path, so you can easily access conda
command from the prompt.
Step 1: Create a conda virtual environment for OpenCV
conda create --name opencv-env python=3.6
opencv-env
refers to the virtual environment name, you can name it as you like, but remember to pick a meaningful name.
- Create a folder for your project where you will put your python scripts.
- Head to your folder through the command line
cd C:\Users\<username>\my_folder
, and activate the virtual environment you just created, with the following command: conda activate opencv-env
Note: if you use bash as your default terminal in windows,
conda activate opencv-env
might not work as expected. The reason for it is that bash is not, by default, properly configured to run anaconda scripts, so you may give it a workaround:
- Edit your .bashrc file
c:\Users\<username>\.bash_profile
adding the following line of code:
2. Whenever you want to lunch your bash terminal add the following arguments: --login -i
, therefore you will lunch your custom bash profile which has been granted access to conda scripts.
Now your conda environment is activated and perfectly available.
Step2: Install OpenCV and the required packages
To use OpenCV you have to install some important packages that go alongside:
pip install numpy scipy matplotlib scikit-learn
pip install opencv-contrib-python
pip install dlib
Step3: Test your installation
And you should get the latest OpenCV version available in the python repo.
And that’s all, have fun with OpenCV.