[英]Getting OpenCV headers to work correctly on install in Linux
I have an OpenCV installation on Ubuntu Linux.我在 Ubuntu Linux 上安装了 OpenCV。 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我可以找到 OpenCV 的位置
pkg-config --cflags --libs opencv
which outputs as follow:输出如下:
"Package opencv was not found"
When I try pkg-config --cflags --libs opencv2
当我尝试
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:只有当我使用
pkg-config --cflags --libs opencv4
时,我才能获得路径:
-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:当然在有问题的
hpp
文件中它是:
#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.
问题是,当您构建 OpenCV 时,它会将 header 文件放在 /usr/local/include/opencv4/ 中,然后在其下方您将看到 opencv2/opencv.hpp 以及您引用的所有其他文件。 To fix your issue you will need to run in bash:
要解决您的问题,您需要在 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.这为我解决了这个问题,如果它对您有用,请务必将其标记为答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.