Reputation: 71
When I compile a simple program : hello_world.cpp
**I get the error-
**fatal error: cv.h: No such file or directory
compilation terminated.****
Solutions I found but didn't work:
I checked for cv.h and highgui.h if they are there, and got these results:
/home/snu/OpenCV-2.4.0/include/opencv/highgui.h
/usr/lib/perl/5.14.2/CORE/cv.h
/home/snu/OpenCV-2.4.0/include/opencv/cv.h
I checked if opencv is correctly installed by using
pkg-config opencv --libs, this is what i got :
-lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
I made some changes in the header files of hello_world.cpp as-
#include "opencv2/highgui/highgui.hpp"
Upvotes: 3
Views: 16835
Reputation: 1365
Welcome to Stack Overflow, the land of the non-answer.
"You are not doing it right, is the problem"
"Do this", with no explanation. Doesn't work.
The cmake answer is ok, but I don't really want to use cmake for the sole purpose of making a single library import.
--- end of roast, my answer:
As per https://answers.opencv.org/question/225224/opencvcvh-not-found/ OpenCV 4 discontinued the C-API in favor of the C++ one, apparently.
So you should install the latest version of OpenCV 3. This can be done using platform specific installer listed below:
https://sourceforge.net/projects/opencvlibrary/files/3.4.10/
For Linux specifically, you want this file from the ones in the link above.
Download and extract it. Then based on these instructions to install it,
opencv-install/opencv-opencv-25a1900
cd opencv-install
rm opencv-opencv-25a1900/CMakeCache.txtls
cmake opencv-opencv-25a1900
make
sudo make install # global install
Then change your import to #include "opencv/cv.h"
Well how about that, you still needed cmake, but at least you don't have to make your project a "cmake project". In fact, if someone else with the same operating system has already done up to step 5, you can simply use their build !
As a little courtesy, and to put my "money" where my "mouth" is, I will provide to you my own build. Understand that using someone else's build assumes a bit more trust than compiling it yourself. I know when I first start with C/Linux compiling OS projects can be kind of daunting so.... here you go! It is for For Debian GNU/Linux 11 (bullseye) x86_64. I think this means it works on Ubuntu, and maybe other OSes that use apt. If you try it and it doesn't work, you should try a different build or make one yourself by starting at step one above.
Upvotes: 2
Reputation: 80
please use the code below for such errors:
#include <opencv/cv.h>
in the place of
#include <cv.h>
Upvotes: 0
Reputation: 1198
Use CMake to link libraries and include directories. It makes your life easier and also for anyone else who will be extending/reading your code in the future. You will not need to add folders specifically into projects as CMake will do that for you automatically.
For example, to link OpenCV, use the follow lines of code:
FIND_PACKAGE( OpenCV REQUIRED )
TARGET_LINK_LIBRARIES( myProject ${OpenCV_LIBS} )
Upvotes: 0
Reputation: 1169
You are probably not compiling correctly. Add the opencv-include folder in the compiler settings.
Upvotes: 0