C++ – compiler error – opencv2/highgui.hpp: No such file or directory

copencv

I am a "very" beginner of OpenCV. I just downloaded it for my Windows and extracted.

I have read this post: http://opencv-srf.blogspot.ro/2011/09/capturing-images-videos.html about how to read webcam and I copied and pasted the code in a C++ file I created in "include" folder of OpenCV extracted archive.

When I try to run the program I get this error: Error in: /opencv/build/include/opencv2/highgui/highgui.hpp – opencv2/highgui.hpp: No such file or directory.

What should I do?

Thank you all!

EDIT

I opened: "/opencv/build/include/opencv2/highgui/highgui.hpp" and I can see that it includes this path "opencv2/highgui.hpp". If I change it to "../highgui.hpp" it works but I get other errors like this for other files… What should I do?

Best Answer

The problem is that you are not supposed to create your "cpp" file in the OpenCV "include" directory. You need to create it in a separate directory and then add OpenCV "include" as additional include directory for the compilation step.

The way to achieve this depends on your C++ development environment. If you are using Visual Studio, then you need to open project property pages, go to "C/C++ -> General" and add the path to OpenCV "include" directory to "Additional Include Directories". In case of some other compiler/IDE, you can find out how to do this by reading the corresponding documentation.