c++visual-studioopencvincludeopencv-contrib

C++ cannot open source file "opencv2/tracking.hpp"


I am trying to use OpenCV multi-tracker, but it doesn't find tracking.hpp. I have built OpenCV with OpenCV-contrib modules based on these instructions. Now in Visual Studio, I have done this:

enter image description here

where $OPENCV_DIR is a user variable:

enter image description here

I also have;

Now the problem is that opencv.hpp and tracking.hpp aren't detected:

enter image description here

Both opencv.hpp and tracking.hpp exist in C:\opencv\opencv4.2.0\opencv-4.2.0\build\install\include\opencv2. What should I do to make the program recognize OpenCV-contrib modules?


Solution

  • Note: This answer has been formed largely by combining and expanding on comments made by myself and others:

    The problem is a 'conflict' between your specified "Additional Include Directories" and the specified name of the header(s) in your #include lines, in that you have specified the folder, "opencv2" twice.

    For example, the line:

    #include <opencv2/tracking.hpp>
    

    Looks for the file tracking.hpp in a sub-directory called opencv2 in each of the defined search paths. In your case, this is looking for:

    OPENCV_DIR\include\opencv2\opencv2\tracking.hpp

    … and that file (in fact, the folder) doesn't exist.

    So, just specify this as your (single) "Additional Include Directory:"

    OPENCV_DIR\include

    … then, when the compiler 'constructs' the path for the header, it will append /opencv2/tracking.hpp to (each of) the specified search directories, and will be able to find: OPENCV_DIR\include + / + opencv2/tracking.hpp, as this will evaluate to:

    OPENCV_DIR\include\opencv2\tracking.hpp