Search code examples
c++visual-studioopencvcmakeinclude

Visual Studio C++ cannot find OpenCV-Contrib modules


I am trying to use OpenCV multi-target tracker, but cannot include the header files. I have built OpenCV with extra modules by providing the path to opencv_contrib-4.2.0\modules in OPENCV_EXTRA_MODULES_PATH in CMake GUI. However, I cannot include the trackers in the project:


code:

#include <opencv2/tracking.hpp>

error:

cannot open source file "opencv2/tracking.hpp"


code:

#include "samples_utility.hpp"

error:

Cannot open include file: 'samples_utility.hpp': No such file or directory


What should I do to add all the modules of OpenCV-contrib to the default OpenCV directory?


Solution

  • You don't have to add all the modules. Only the modules you need, and in this case the tracking module. You will need to add the corresponding folder to the include directory and the code should compile properly.(your folder might be in different location but the relative path should be the same)

    {location_of_opencv_contrib}\modules\tracking\include

    {location_of_opencv_contrib}\modules\tracking\samples

    For visual studio, you can add the folder path above to Project Properties-> VC++ Directories -> Include Directories

    If you are building using gcc, add -I option followed by the directory of the folder mentioned.