1

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;

  • added the path C:\opencv\opencv4.2.0\opencv-4.2.0\build\install\x64\vc16\lib to the Linker -> Gnereal -> Additional Library Directories.
  • added opencv_world420.lib to Linker -> Input -> Additional Dependencies

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?

Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58
  • 1
    Not sure here, but what happens if you take out the `opencv2/` from the header names in the source files? Look like you already have that directory as part of the "Additional include directories." – Adrian Mole Jan 16 '20 at 15:58
  • 2
    Did you try to compile ? Because the error in the last picture you showed is just about the editor settings, not about the compiler settings. If it compiles, then your files are properly found, and it is just the intelliSense or something like that which is misconfigured. – Fareanor Jan 16 '20 at 16:01
  • 2
    Joining @AdrianMole, but I'd rather remove the opencv2 subpath in one of the additional include paths and drop the other one entirely... – Aconcagua Jan 16 '20 at 16:11
  • @Aconcagua I would agree that's probably the better approach. Just thought that editing the cpp file would be a quicker "test" to see if that's actually the problem. – Adrian Mole Jan 16 '20 at 16:13
  • @Aconcagua See answer - hope it's not too garbled! – Adrian Mole Jan 16 '20 at 16:32
  • Yes that was the problem. I added `C:\opencv\opencv4.2.0\opencv-4.2.0\build\install\include` to **Additional include directories** and the errors went away. – Hadi GhahremanNezhad Jan 16 '20 at 16:32

1 Answers1

2

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

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • Thank you! Adding `OPENCV_DIR\include` to **Additional include directories** solved the problem. – Hadi GhahremanNezhad Jan 16 '20 at 16:34
  • 1
    Always happy to help! Note that, so long as you *consistently* use the `` and/or `` format in your `#include` lines, then you don't need those specific directories in your Additional Includes list. – Adrian Mole Jan 16 '20 at 16:36