[英]How to link the correct directory for OpenCV on raspberry?
我按照本教程将 openCV 安装到我的 Raspberry 中,但文件进入目录:usr/local/include/ opencv4/opencv2而不是 usr/local/include/ opencv2
现在编译失败,即使我使用 #include <opencv4/opencv2/opencv.hpp>
这有点令人困惑。 在“旧”时代,OpenCV 将其目录默认放置在 /usr/local/inculde/opencv2 目录中。 但是,随着自 OpenCV 4 以来的主要版本更改,当您在同一台机器上安装 OpenCV 2 和 4 时,它会产生很多潜在的冲突。 为了克服这个问题 OpenCV 现在将头文件默认放置在 opencv4 文件夹中。
你现在可以选择你想要的版本(当然,如果你都安装了):
#include /usr/local/include
将指向“旧”版本 2,或
#include /usr/local/include/opencv4
指向版本 4。
大多数情况下,您不会包含像 opencv.hpp 这样的单个标题。 请看下面的代码片段。
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
int main(int argc,char ** argv)
{
VideoCapture cap(0);
if (!cap.isOpened()) {
cerr << "ERROR: Unable to open the camera" << endl;
return 0;
}
Mat frame;
cout << "Start grabbing, press a key on Live window to terminate" << endl;
while(1) {
cap >> frame;
if (frame.empty()) {
cerr << "ERROR: Unable to grab from the camera" << endl;
break;
}
imshow("Live",frame);
int key = cv::waitKey(20);
key = (key==255) ? -1 : key;
if (key>=0) break;
}
cout << "Closing the camera" << endl;
cap.release();
destroyAllWindows();
return 0;
}
在编译期间,您只需提供一次位置。 这是 Code::Block 项目文件的一部分。 使用的机制是明确的; 只需提供一次您的中心位置。
此外,通过链接整个 package,您不必将单个 object 文件与令人沮丧的相互依赖关系链接起来。
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
<Add directory="/usr/local/include/opencv4" />
</Compiler>
<Linker>
<Add option="`pkg-config --libs --cflags opencv4`" />
</Linker>
我已经在 GitHub 上的 Raspberry Pi 上放置了一些(深度学习)示例,说明如何在OpenCV 4 上使用。 在这里您将看到如何使用 C++ OpenCV。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.