I have an OpenCV installation on Ubuntu Linux. From any example the headers are:
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
When I compile with these includes I get the error:
fatal error: opencv2/imgcodecs.hpp: No such file or directory
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
I can find out where OpenCV is located with
pkg-config --cflags --libs opencv
which outputs as follow:
"Package opencv was not found"
When I try pkg-config --cflags --libs opencv2
I get:
"Package opencv2 was not found"
Only when I use pkg-config --cflags --libs opencv4
do I get the path:
-I/usr/local/include/opencv4/opencv2
so I thought that by changing the includes to:
#include <opencv4/imgcodecs.hpp>
#include <opencv4/highgui.hpp>
it would work. But I get:
fatal error: opencv4/imgcodecs.hpp: No such file or directory
#include <opencv4/imgcodecs.hpp>
so when I try the full path:
#include <opencv4/opencv2/imgcodecs.hpp>
I get:
imgcodecs.hpp:46:10: fatal error: opencv2/core.hpp: No such file or directory
#include "opencv2/core.hpp"
and of course in the hpp
file in question it is:
#include "opencv2/core.hpp"
Is there a simple way to fix all this?
I actually ran into this issue recently. The issue is that when you build OpenCV it places the header files in /usr/local/include/opencv4/ then underneath that you will see opencv2/opencv.hpp and all the other files you're referencing. To fix your issue you will need to run in bash:
sudo ln -s /usr/local/include/opencv4/opencv2 /usr/local/include/opencv2
This resolved the issue for me, if it works for you please be sure to mark this as the answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.