Visual Studio Code Opencv Python



Installation of OpenCV in Visual Studio Environment.Originally was created for Image Processing class, Robotics Department, Nazarbayev University, Kazakhstan. We will learn to setup OpenCV-Python in your Windows system. Below steps are tested in a Windows 7-64 bit machine with Visual Studio 2010 and Visual Studio 2012. The screenshots shows VS2012. Installing OpenCV from prebuilt binaries. Below Python packages are to be downloaded and installed to their default locations. Python in Visual Studio Code Working with Python in Visual Studio Code, using the Microsoft Python extension, is simple, fun, and productive. The extension makes VS Code an excellent Python editor, and works on any operating system with a variety of Python interpreters.

I'm having a nightmare trying to get OpenCV to work. I've installed it with no issues, but when I try running an example code it can't find the include files. I'm using Visual Studio Code (different from Visual Studios), but all the tutorials for setting it up are for Visual Studios. I don't know whether that's what's causing the problem.

I've tried installing it in two ways, first with the pre-built libraries, and then with git-bash and cmake as described here: https://docs.opencv.org/master/d3/d52.... VScode can't see the include files for either. I have tried adding the directory to the 'opencv2' directory to the Path environment variable, and also to the VScode includePath.

Is there a better way of installing it that isn't specific to VS? I only need the C++ bits, if that's any easier. Also, if anyone knows how to configure VScode properly that would be helpful.

(I can't get Visual studios because I don't have enough space on my hard drive, and I can't replace the hard drive.)

editretagflag offensiveclosemergedelete

Comments

VS Code is an ide, but which compiler did you install ? and which opencv version ?

Compiler is MinGW-32, opencv version 4.1.1. I've updated my post.

this means, you have to build the opencv libs from src (using mingw), before you can use them (the prebuild libs are for vs only), irrespectably of the ide you want to use later.

Okay. I've followed the instructions for building my own libraries, but I think I must have gone wrong somewhere. The bin folder only has one file in it (opencv_videoio_ffmpeg411.dll) which doesn't seem right. Also, it isn't clear what to do next. The instructions say 'Now you need to build both the Release and the Debug binaries', but I don't know how to do that.

if all went well, after mingw32-make install your new stuff should be in opencv/build/install

I don't seem to have an install folder in build. I have an install folder in build/CMakeFiles, but that only contains one cmd file. I remember CMake said something about putting the new stuff in build/install, but it seems like it didn't. Should I delete the build folder and try generating it again with CMake?

maybe put this question on hold for a minute, and ask a 2nd one, how to build with mingw ?

show your cmake / build output, and let's see from there ?

Okay. The new thread is here: https://answers.opencv.org/question/2...

1. Install Python3

1.1 In Windows

Scientific programming in Python requires multiple third-party packages (like numpy), whose installing procedure needs complicated compiling tools. Those compiling tools are tricky in Windows. Anaconda is the most popular Python data science platform, which includes essential pre-compiled third-package packages. Thus, in Windows platform, we suggest installing Python by Anaconda.

Download and install Anaconda Python 3.7 from official website. Plase check adding to system path while installing.

In order to test the Anaconda. Open command line PowerShell. If the installed Anaconda is the only Python version in your operating system. Type python. In If it shows:

Then type exit() and enter. Type pip -V. If the screen shows:

Congratulations! Your Anaconda environment is successfully installed in your Windows.

If you have another version of Python, try python3 / py3 and pip3 instead.

1.2 In Linux (like Ubuntu)

Code

In general, Python is pre-installed in Ubuntu. For Ubuntu 18.04, in Terminal, you can type python3 to enter python console mode.

If your Ubuntu does not have Python3, please try:

to install Python3.

We also need pip to maintain Python third-party packages. Use

to install pip3.

Vs Code Not Recognizing Python

You can also install Anaconda in Linux if you want.

Vs Code Python 3

2. Install OpenCV3

OpenCV is the most popular open source computer vision libraries. We will use pip to install OpenCV for Python. Please type pip -V in command line to check the current pip is matched to your target Python version. You may use pip3 instead (In Ubuntu 18.04).

In command line, type pip install opencv-python.

To test OpenCV, in python consle mode, type the following codes in order.

Opencv Vs Code

You will see an empty window shon then disappeared.

Install Python Vscode

3. Install Visual Studio Code

Download and install Visual Studio Code from official website.

Visual Studio Code Opencv Python Free

Now, you can write your code in VS Code and run the code in command line. You can also open command line in VS Code by Ctrl + `.

If you want to set up a debug environment for Python, please follow this official tutorial. There are two tips:

  1. Check the Python intepretor in the left bottom of VS Code is correct or not.
  2. Add attribute 'args': ['--arg1', '--arg2'] in launch.json file to set up program arguments.