无法编译OpenCV代码(C ++) [英] Cannot compile OpenCV code (C++)
问题描述
好吧,所以我一直在寻找这个问题一段时间,我仍然没有如何解决它。
我试图运行此处提供的示例代码: http://docs.opencv.org/trunk/d1/dc5/tutorial_background_subtraction.html 。
我理解代码。我只是不能得到它编译!问题出在库包含。这是我的 Makefile
:
CFLAGS =`pkg-config --cflags opencv`
LIBS =`pkg-config --libs opencv`
%:%.cpp
g ++ $(CFLAGS)$(LIBS)-o $ @ $&
以下是错误:
prakhar @ inS4n3〜/ dev /性别识别$ make bs
g ++`pkg-config --cflags opencv``pkg-config --libs opencv` o bs bs.cpp
bs.cpp:2:33:fatal error:opencv2 / imgcodecs.hpp:没有这样的文件或目录
#includeopencv2 / imgcodecs.hpp
^
编译终止。
Makefile:5:目标'bs'失败的食谱
make:*** [bs]错误1
如果我(暂时)注释掉这个文件,我得到类似的错误与 imgproc.hpp
。在我的 OpenCV
代码的另一个下面的编译完全:
#includeopencv2 / core / core.hpp
#includeopencv2 / contrib / contrib.hpp
#includeopencv2 / highgui / highgui.hpp
就我所知,替换 opencv2 / core.hpp
用 opencv2 / core / core.hpp
或替换 opencv2 / imgproc.hpp
opencv2 / imgproc / imgproc.hpp
所以我看起来更深,这是我的 opencv2
资料夹:
prakhar @ inS4n3 / usr / include / opencv2 $ ll
total 84
drwxr-xr-x 2 root root 4096 Nov 14 19:42 calib3d
drwxr-xr-x 2 root root 4096 Nov 14 19:42 contrib
drwxr-xr-x 2 root root 4096 Nov 14 19:42核心
drwxr-xr-x 2 root root 4096 Nov 14 19:42 features2d
drwxr-xr-x 2 root root 4096 Nov 14 19:42 flann
drwxr-xr- x 3 root root 4096 Nov 14 19:42 gpu
drwxr-xr-x 2 root root 4096 Nov 14 19:42 highgui
drwxr-xr-x 2 root root 4096 Nov 14 19:42 imgproc
drwxr-xr-x 2 root root 4096 Nov 14 19:42 legacy
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ml
drwxr-xr-x 2 root root 4096 Nov 14 19:42 nonfree
drwxr-xr-x 2 root root 4096 Nov 14 19:42 objdetect
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ocl
-rw -r - r-- 1 root root 2751 Oct 1 2014 opencv.hpp
-rw-r - r-- 1 root root 672 Nov 12 00:02 opencv_modules.hpp
drwxr-xr- x 2 root root 4096 Nov 14 19:42 photo
drwxr-xr-x 3 root root 4096 Nov 14 19:42 stitching
drwxr-xr-x 2 root root 4096 Nov 14 19:42 superres
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ts
drwxr-xr-x 2 root root 4096 Nov 14 19:42 video
drwxr-xr-x 2 root root 4096 11月14日19:42 videostab
任何人都能告诉我为什么会发生这种情况,我得到 imgcodecs.hpp
和 videoio.hpp
模块?
我使用 OpenCV
2.4.10-2
,在Arch Linux上。
好吧,在@Micka的帮助下,我终于意识到,文档是为OpenCV 3.0 beta
,而不是 2.4.10
。因此,在此中进行更改可以解决问题。
但是,我只是安装了3.0 beta版,效果不错。
这是转换指南,对我来说很难找到(仍然不知道为什么!)。 / p> Okay, so I have been searching for this problem for a while, and I still am clueless as to how to solve it. I am trying to run the sample code available here: http://docs.opencv.org/trunk/d1/dc5/tutorial_background_subtraction.html.
I understand the code. I just cannot get it to compile! The problem is with library includes. Here's my Here's the error: If I (for the time being) comment out this file, I get a similar error with As far as I can tell, replacing So I looked deeper and here's my Can anyone tell me why this is happening, and how do I get the Okay, with help from @Micka, I finally realized that the doc is for OpenCV However, I simply installed the 3.0 beta, and that worked fine. Here's the transtition guide, which for me was hard-to-find (still don't know why!). 这篇关于无法编译OpenCV代码(C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Makefile
:CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`
% : %.cpp
g++ $(CFLAGS) $(LIBS) -o $@ $<
prakhar@inS4n3 ~/dev/gender recognition $ make bs
g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` -o bs bs.cpp
bs.cpp:2:33: fatal error: opencv2/imgcodecs.hpp: No such file or directory
#include "opencv2/imgcodecs.hpp"
^
compilation terminated.
Makefile:5: recipe for target 'bs' failed
make: *** [bs] Error 1
imgproc.hpp
. In another of my OpenCV
code, the following compiles prefectly:#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"
opencv2/core.hpp
with opencv2/core/core.hpp
or replacing opencv2/imgproc.hpp
with opencv2/imgproc/imgproc.hpp
does the job.opencv2
folder:prakhar@inS4n3 /usr/include/opencv2 $ ll
total 84
drwxr-xr-x 2 root root 4096 Nov 14 19:42 calib3d
drwxr-xr-x 2 root root 4096 Nov 14 19:42 contrib
drwxr-xr-x 2 root root 4096 Nov 14 19:42 core
drwxr-xr-x 2 root root 4096 Nov 14 19:42 features2d
drwxr-xr-x 2 root root 4096 Nov 14 19:42 flann
drwxr-xr-x 3 root root 4096 Nov 14 19:42 gpu
drwxr-xr-x 2 root root 4096 Nov 14 19:42 highgui
drwxr-xr-x 2 root root 4096 Nov 14 19:42 imgproc
drwxr-xr-x 2 root root 4096 Nov 14 19:42 legacy
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ml
drwxr-xr-x 2 root root 4096 Nov 14 19:42 nonfree
drwxr-xr-x 2 root root 4096 Nov 14 19:42 objdetect
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ocl
-rw-r--r-- 1 root root 2751 Oct 1 2014 opencv.hpp
-rw-r--r-- 1 root root 672 Nov 12 00:02 opencv_modules.hpp
drwxr-xr-x 2 root root 4096 Nov 14 19:42 photo
drwxr-xr-x 3 root root 4096 Nov 14 19:42 stitching
drwxr-xr-x 2 root root 4096 Nov 14 19:42 superres
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ts
drwxr-xr-x 2 root root 4096 Nov 14 19:42 video
drwxr-xr-x 2 root root 4096 Nov 14 19:42 videostab
imgcodecs.hpp
and videoio.hpp
modules?
I am using OpenCV
2.4.10-2
, on Arch Linux.3.0 beta
, not 2.4.10
. As such, making the changes in this solves the problem.