Set Visual Studio Code for OpenCV Python

AiPhile
5 min readJan 31, 2022

--

how to setup dev environment for OpenCV python in, Visual Studio Code. we will discus here what are tools required to get things started, few of my tips, tricks that will make things easier and faster.

bit about OpenCV

OpenCV is an open-source library, it contains more than 2500 algorithms for computer vision and machine learning It has support for languages Python, C++, Java, JavaScript etc. since it is one of the most famous computer vision libraries out there, you will find lots of resources and guidance from the OpenCV dev community, here can find OpenCV Tutorials from Read The Docs, to get started.

Requirements

  1. Python
  2. Opencv-python
  3. Visual Studio Code

Installation

Python (python interpreter)

First of All, you need python, you can get this from the official site if you are on windows, but for mac 🍎 or Linux 🐧 you, probably already have this, make sure that the ⚠ version of python must stand greater than 3.6, which highly recommend.

while installing the python on Windows, make sure to install PIP(Python Package Manager) and add the path to the environmental variables, so pip will allow downloading and installation of different packages(modules) from the internet, like OpenCV-python, NumPy, pygame etc.

just Tick ✅ the pip Box while installing Python, which is included optional features.

install PIP Screenshot

Pip installation for Linux 🐧

sudo apt install python3-pip python-dev

Add Path Python to environment variables so your machine will be able to recognize it, and Visual Studio Code as well.

Adding Path to environment Variables

now you are done with Python Installation.

Install Packages(libraries) with PIP

Now it's pretty simple, just open the terminal and type pip install package-name

pip install opencv-contrib-python
Installation Opencv python

Visual Studio Code (Vs Code)

Visual studio code is simple text(code) editor, powered by the tones of extension available online(Vs code marketplace) most of them are free and open-source.

Vs Code comes with Git source control, debugger and Extension Manager, for more Offical Guide Vs Code,

Requirements

  1. Python Interpreter (Installed earlier)
  2. Python Extension
  3. Pylance Extension
  4. Path Intellisense
  5. Visual Studio IntelliCode

VS code Available for Linux 🐧, mac🍎 and Windows, download it here, and install it, which is quite simple for each OS.

Install Extension on Vs Code

here is how can you install Extension in VS code.

Extension Installation

When you Python Extension, by default to other Extension are installed as well, Pylance and Jupyter, Pylance provide python code IntelliSense experience with rich type information, which will help a lot to write better and faster code. you will see that in action next GIF, Jupyter extension allows working Jupyter notebook in VS code.

Pylance

Pylance provides lots of help, displaying the docs, like parameters, flags, functions, which will help to write faster code, shown 👇

Pylance

Path Intellisense

The extension adds the functionality of grabbing file is easier, instead of typing it out, it produces Intellisense for files📁 paths, shown👇

Path Intellisense

Visual Studio IntelliCode

The extension is favourite(star⭐)the function that you have used recently, making them available on the top when you are working. shown👇

Visual Studio IntelliCode

Raspberry Pi Developer

If you are the one who works on Raspberry Pi then I will Highly recommend you to install, Remote Development Extension, it is a pack of multiple extensions, one of them Remote SSH extension, This extension allows you to connect to a remote device over SSH, and run VS Code as if you were running on that remote device. You see the remote file system, the VS Code terminal runs on the remote device, and you access the remote device’s hardware. When you are debugging, the debug session runs on the remote device, but VS Code runs on the host machine, but you have one problem when working with OpenCV since SSH does not allow show(view) a window when you working with Opencv Window while showing the image, but still, I love it when I am working on Pi ❤

here is VS code Keyboard shortcuts, PDF file.

The last thing that Would like to mention, like to work in a clean environment, I mean like, don’t want to see those GUI menus that are present here and there, then their way to Avoid then in VS code, with Zen Mode (CRT + K Z)

Zend Mode

all the settings for vs code is stored in a JSON file you get the settings.json that I am using here

Final words

we are going through the installation of python, OpenCV and VS code, we have disused a few important extension, that is important when going to work on python-development in VS code, If you think that I have missed something then please mention them in a comment.

here is Video Tutorial you can check out that as well.

Video Tutorial

Reference:

--

--