#include opencv 中的 C++ 头文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19177456/
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-27 22:34:18  来源:igfitidea点击:

#include C++ header files in opencv

c++opencv

提问by makys

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?

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

Excuse me for asking for such simple questions.

不好意思问这么简单的问题。

回答by sansuiso

.hppis 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.

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

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

对于 global vs. small includes 问题,您需要回忆一下 C/C++ 中的工作原理。该头文件只是复制到编译之前你.c文件。

  • 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 usein your program, which helps you in typing the corresponding correct linkeroptions, e.g., -lopencv_core -lopencv_imgprocif you use only the image processing module.
  • 当您使用全局包含opencv.hpp(这是某种保护伞,因为它包含所有其他内容)时,所有库头文件都被包含在内,因此被复制到您的 .cpp 文件中。这意味着您的输入更少,但最终编译器的文件更大。因此,编译时间更长
  • 当您使用本地头文件时,您一次只需添加一个 OpenCV 模块。因此,如果您将自己限制在实际需要的模块上,您的编译速度会更快。另一个优点是您可以真正了解您在程序中使用的模块,这有助于您键入相应的正确链接器选项,例如,-lopencv_core -lopencv_imgproc如果您只使用图像处理模块。

回答by SRF

#include <opencv2/opencv.hpp>

This header file include all the other header files in OpenCV in its body. So, if you include that file, it is more than enough.

该头文件在其主体中包含 OpenCV 中的所有其他头文件。因此,如果您包含该文件,那就足够了。

".h" is for C and ".hpp" is for C++. This is just the standard.

.h”代表C,“.hpp”代表C++。这只是标准。

回答by Saikat

just open opencv2/opencv.hpp file and I think you will get your answer.

只需打开 opencv2/opencv.hpp 文件,我想您就会得到答案。