Linux 即使其他程序可以运行 OpenCV,程序也无法运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10858397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:37:47  来源:igfitidea点击:

Program cannot run OpenCV even though others can

c++linuxubuntuopencv

提问by clifgray

I am trying to run a program that uses OpenCV and I have gotten it to run on other machines, and other programs on my machine run using it, but this one returns:

我正在尝试运行一个使用 OpenCV 的程序,我已经让它在其他机器上运行,我机器上的其他程序使用它运行,但这个返回:

programname.cpp:  fatal error: opencv/cv.h: No such file or directory

Anyone know how to fix the path or what might be going wrong? I am running Ubuntu 12.04 and OpenCV-2.4.0

任何人都知道如何修复路径或可能出现什么问题?我正在运行 Ubuntu 12.04 和 OpenCV-2.4.0

采纳答案by Samuel Gosselin

On my Ubuntu 11.04, the headers are in: */usr/include/opencv-2.3.1/*, I assume it should be */usr/include/opencv-2.4.0/*for you.

在我的 Ubuntu 11.04 上,标题在: 中*/usr/include/opencv-2.3.1/*,我认为它应该*/usr/include/opencv-2.4.0/*适合您。

You have two solutions:

您有两种解决方案:

  • When you compile, use the -Ioption: g++ -o [name] [src] -I/usr/include/opencv-2.4.0
  • Create symbolic links to opencv-2.4.0/opencvand opencv-2.4.0/opencv2in /usr/include.
  • 编译时,使用-I选项:g++ -o [name] [src] -I/usr/include/opencv-2.4.0
  • /usr/include 中创建指向opencv-2.4.0/opencvopencv-2.4.0/opencv2 的符号链接。

The second solution is useful if you're using CMake, because FindOpenCV2 does not look for OpenCV in /usr/include/opencv-2.4.0. I hope this (ugly) hack will solve your problem.

如果您使用 CMake,则第二种解决方案很有用,因为 FindOpenCV2 不会在/usr/include/opencv-2.4.0. 我希望这个(丑陋的)hack 能解决你的问题。

回答by jag2kn

Change from:

更改自:

#include <opencv/cv.h>

#include <opencv/cv.h>

to:

到:

#include <opencv2/opencv.hpp>

#include <opencv2/opencv.hpp>