#include opencv中的C ++头文件 [英] #include C++ header files in opencv

查看:517
本文介绍了#include opencv中的C ++头文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是使用

  #include< opencv2 / opencv.hpp> 

我可以问为什么我们应该这样做:

  #include< opencv2 / imgproc / imgproc.hpp> 
#include< opencv2 / objdetect / objdetect.hpp>
#include< opencv2 / highgui / highgui.hpp>

为什么这里有* .hpp文件,而不是* .h文件?

$ b对于请求这样简单的问题,请原谅我。

解决方案

hpp 是C ++ 语言头文件的约定。由于OpenCV有一个与C ++ 并行的 C API的长篇故事,人们可以很容易地理解为什么编写库的人选择此扩展来避免混淆

对于全局vs.小包括问题,你需要回忆一下C / C ++中的工作原理。




  • 当您使用全局include opencv.hpp (这是一种伞,因为它包括所有其他),所有的库头文件被包括,从而复制到您的.cpp文件。这意味着更少的输入,但最终一个更大的文件为编译器。因此,编译时间较长

  • 使用本地头文件时,您只需一次添加一个OpenCV模块。因此,如果您将自己局限于实际需要的模块,则会有更快的编译。另一个优点是,您可以在程序中真正了解您使用的模块,这有助于您键入相应的正确链接器选项,例如 -lopencv_core -lopencv_imgproc 如果只使用图像处理模块。


I just use

#include <opencv2/opencv.hpp>

and things worked. May I asked why we should do like:

#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>

And why here are *.hpp files but not *.h files?

Excuse me for asking for such simple questions.

解决方案

.hpp is a convention for C++ language header files. Since OpenCV has a long story of a C API in parallel of the C++ one, one can easily understand why the people writing the library chose this extension to avoid confusion.

For the global vs. small includes question, you need to recall how things work in C/C++. The header files are just copied into your .c file before compilation.

  • When you use the global include opencv.hpp (which is some kind of umbrella since it includes all the others), all the library header files are included and thus copied into your .cpp file. This means less typing for you but in the end a bigger file for the compiler. Hence, compilation times are longer.
  • When you use the local header files, you just add one OpenCV module at a time. Thus, if you limit yourself to the modules that you actually need, you have a faster compilation. Another advantage is that you can really be aware of what modules you use in your program, which helps you in typing the corresponding correct linker options, e.g., -lopencv_core -lopencv_imgproc if you use only the image processing module.

这篇关于#include opencv中的C ++头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆