Here you will find a step-by-step example of installing the OpenCV library in Python.
- Python installation
- Virtual environment setup
- Install OpenCV + jupiterlab, numpy, matplotlib
- Testing
I tested everything on a Microsoft Surface tablet, Windows 10 Pro, with a 64-bit operating system.
Suppose your device isnβt installed in advance.
- First install Python .
Download the desired version and run the .exe file. Do not forget to check the add path box. I installed Python 3.7.3 from March 25, 2019, because the new version of Python 3.7.4 from July 8, 2019 was not working correctly, namely, some commands were hanging in the terminal. Open the command line. - Install virtualenv.
We need a virtual environment so that each individual project has its own βroomβ with its own versions of installed libraries, which will not depend on other projects and get confused with each other.
We will install packages using pip. It has been running immediately with Python recently, but usually it needs to be updated with the command:
python -m pip install --upgrade pip
Updated pip, now install the virtual environment : With the
pip install virtualenv
command, cd
go to the folder in which you want to create the environment and enter the command:
mkdir opencvtutorial_env
- this is how we created an environment called opencvtutorial_env.
Next, enter the command virtualenv opencvtutorial_env
and to activate, go to the environment folder and then use Tab to activate.
.\opencvtutorial_env\Scripts\activate
- OpenCV-Python, Numpy Matplotlib, opencv.
. :
pip install opencv-python
opencv-python numpy. matplotlib: pip install matplotlib
. pip install jupyterlab
jupyter notebook
.
. Python 3 , :
import cv2 as cv
print( cv.__version__ )
opencv, , c . .