Using OpenCV in Windows 10 with Visual Studio Code

asked 2019-08-17 13:59:22 -0500

JoeP gravatar image

updated 2019-08-17 16:58:55 -0500

berak gravatar image

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: 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.)

edit retag flag offensive close merge delete


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

berak gravatar imageberak ( 2019-08-17 15:36:18 -0500 )edit

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

JoeP gravatar imageJoeP ( 2019-08-17 15:49:34 -0500 )edit

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.

berak gravatar imageberak ( 2019-08-17 16:24:57 -0500 )edit

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.

JoeP gravatar imageJoeP ( 2019-08-18 06:39:15 -0500 )edit

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

berak gravatar imageberak ( 2019-08-18 06:48:45 -0500 )edit

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?

JoeP gravatar imageJoeP ( 2019-08-18 07:03:06 -0500 )edit

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 ?

berak gravatar imageberak ( 2019-08-18 07:08:19 -0500 )edit

Okay. The new thread is here:

JoeP gravatar imageJoeP ( 2019-08-18 10:19:07 -0500 )edit