How to install OpenCV with contrib modules in Windows 10 on Visual Studio 2019

2.5k Views Asked by At

I am trying to install OpenCV with contrib modules for Visual Studio 2019 on a Windows 10 machine.

I previously had a working version in Visual Studio 2017, but have been unable to get either 2019 or 2017 working recently.

I have been using CMake to install this, adding the extra modules path before generating. Once I have built the ALL_BUILD and INSTALL files I am not sure of where I am meant to add the libraries and include paths and I have found conflicting results between tutorials and neither seem to work.

My code won't include the libraries and says that it can't open the source file.

Here is my code:

#include <opencv2/core/core.hpp>

The error is:

Cannot open source file "opencv2/core/core.hpp"

I have reviewed the following materials to attempt to solve this but there are no up to date guides to include contrib modules nor any that work

1

There are 1 best solutions below

1
On

this is a problem of the path to include directory. You can set directly the path in Project setting- C/C++ - General - Additional Include Directory: (c:/opencv/install/include) "Just example". Follow the picture. This will correct the problem with includes.

Additional include directory You have to include additional library Directories as: c:\xxx\xxx\install\x64\vc16\lib x64 depends if you compiled opencv for 64 or 32 bits, vc16 is Visual Studio 2019.

Additional library directories

The Additional dependencies on the following picture provide opencv_MODULE420.lib, where module is core, video, videoio, etc. If you have a problem here, The message symbol is not resolved will occur. Additional dependencies

I recently did a tutorial for this here funvision blog HERE in case you have a problem with installation by CMAKE. The tutorial includes the installation of GSTREAMER as well.