How To Install OpenCV Python in Visual Studio Code (Windows 11)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys in this video I'm going to show you how you can install and use python opencv on your Visual Studio code editor on your Windows operating system so let's get started so first of all we need to create your project folder so let's create that so I'm going to create a new uh project folder with the name opencv app for example and then I'm going to open this folder in my visual studio code editor which is simple you can just click on open folder or click on file and then click on open folder and then just navigate to your opencv app folder so I'm going to just select this folder and then I'm going to just open this folder in my visual studio code editor I'm going to just say yes I trust this app and then to test my opencv code I'm going to create a very simple python script so let me create a python file first of all I'm going to name my file as test Dot py and then press enter which is going to create the script and then I'm going to just write a very simple opencv script which Imports CV2 library and then you can see it creates some shapes on the image so right now you can see when I import CV2 it says import CV2 could not be resolved so to solve this problem just open your terminal so click on Terminal and then open a new terminal and then first of all we are going to create a new virtual environment in our project so that we can just install opencv libraries locally in our project so just type this command which is python but first of all you can see that I have opened Powershell here I want to open the command prompt terminal and not the Powershell you can use Powershell if you want but for now I'm going to be using command prompt so just make sure that command prompt terminal is open you can just click on this icon and then click on command prompt and the command prompt terminal will be opened now just type python hyphen m v n and the name of your virtual environment I'm going to name my virtual environment as my n you can name your virtual environment as anything so this name can be given by you once you uh have written your command press enter which is going to create your virtual environment in your project you can see this directory is created once you have given the command also Visual Studio code is going to give you this kind of message window which says we noticed a new environment has been created do you want to select it for the workspace folder I can say yes for visual studio code and it will be uh saved for your Visual Studio code so now your environment is created but you need to activate it so when you open your my and or whatever is the name of your virtual environment folder you will see a script directly under it and there is this activate file here we need to run this to activate our virtual environment to run this just type the name of your virtual environment folder which is my end in my case then forward slash then write scripts and then forward slash activate just type this command and then press enter which is going to activate your virtual environment and to verify if your virtual environment has been activated you can see that the name of your virtual environment is now visible in front of your path right so if you see this path that means your virtual environment has been activated for your project before running this command I was not seeing this virtual environment name in front of the path right once that's done in order to install opencv in your project you can give this command so just write pip install and then write open CV hyphen python okay you don't need to install CV2 package because in order to import this Library you just need to install opencv hyphen python package right not CV2 package just type pip install opencv hyphen Python and then press enter which is going to install this pip package in your project and once this command is successful you will see this message which says successfully installed numpy which is the dependency of opencb and opencv python right you can also see this warning and this appears when your pick is older right so in order to upgrade your pip version you can give this command if you want but for now I don't want to do this so once opencv python is installed successfully you can just run your script so now you will see that these squiggly lines are gone from the import I just need to import numpy also in my uh script because I'm using numpy for creating my images now I can just run this script by just typing Python and the name of the script which is test.py in my case and then press enter once I press enter you can see there is the output of my script and I was just creating some shapes in my uh opencv code so it's just creating those shapes here and this is how you can install and use opencv in your Visual Studio code editor right so that's it for this video I hope you've enjoyed this video and I will see you in the next video
Info
Channel: ProgrammingKnowledge
Views: 57,084
Rating: undefined out of 5
Keywords: visual studio code opencv c++ windows, install opencv visual studio code python, install opencv visual studio python, how to use opencv-python in visual studio code, how to install cv2 in python, pip install cv2, install opencv windows c++, how to import cv2 in python
Id: fclTFQQvQFQ
Channel Id: undefined
Length: 7min 7sec (427 seconds)
Published: Wed May 10 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.