# Python and OpenCV local setup
for CityU UR Juneer 2021
with setup for VSCode
## Overview
This setup guide only covers setup for Python deployment of OpenCV in Windows. For installation of OpenCV for other languages such as C++ or C#, please refer to this [set of guides](https://docs.opencv.org/3.4/df/d65/tutorial_table_of_content_introduction.html).
## Tips
Please refer to docs.opencv.org for more information about specific implementation of functions you saw in the tutorial slides. You should know what parameters each function you have used in your program requires, and what do the functions return as a result of its processing. Knowing where the problem might be is a very important step towards becoming a good engineer.
Python
===
#### Before installing OpenCV, you first need a Python environment.
1. Download [Python](https://www.python.org/downloads/) from official release website and install
- We use Python 3 in this case, subversion (3.6 or 3.9) is not important
2. Remember to tick all the checkboxes marked in <span style="color:red;">red</span> as below in the installation page



3. Test installation by opening `cmd` or `powershell` then type `python`

Installation successful!
#### Next, create a ***virtual environment*** in Python using `venv`. Look here for more about [why and how to create it](https://docs.python.org/3/library/venv.html).
1. In `cmd` type `python -m venv C:\Users\<your username>\venv3` or replace the latter path with any location you would like to store your virtual environment.
2. Check if the folder has been created

3. Activate the virtual environment.
command: `C:\Users\<your username>\venv3\Scripts\<activate>`
Replace `<activate>` with:
- In `cmd`: `activate.bat`

- In `powershell`: `Activate.ps1`
(remember to run `powershell` as the administrator)

OpenCV
===
Next, install `opencv-python`, which is the Python wrapper for OpenCV.
Make sure you are in the virtual environment already.
1. In `cmd` or `powershell` type `python -m pip install opencv-python`

2. Test installation by importing the `cv2` library

Visual Studio Code
===
VSCode is the recommended IDE for development. Some other good IDEs include PyCharm by JetBrains, Vim :).