简体   繁体   English

#include opencv中的C ++头文件

[英]#include C++ header files in opencv

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. 请原谅我提出这么简单的问题。

.hpp is a convention for C++ language header files. .hppC ++语言头文件的约定 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 . 由于OpenCV有一个与C ++并行的C API的长篇故事,人们可以很容易地理解为什么编写库的人选择了这个扩展来避免混淆

For the global vs. small includes question, you need to recall how things work in C/C++. 对于全局与小型包含问题,您需要回忆起C / C ++中的工作原理。 The header files are just copied into your .c file before compilation. 在编译之前, 头文件只是复制到.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. 当你使用全局包含opencv.hpp (它包含所有其他包含的某种伞)时,所有的库头文件都被包含在内并因此被复制到你的.cpp文件中。 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. 使用本地头文件时,您只需一次添加一个OpenCV模块。 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, eg, -lopencv_core -lopencv_imgproc if you use only the image processing module. 另一个优点是您可以真正了解您在程序中使用的模块 ,这有助于您键入相应的正确链接器选项,例如,如果仅使用图像处理模块, -lopencv_core -lopencv_imgproc
#include <opencv2/opencv.hpp>

This header file include all the other header files in OpenCV in its body. 此头文件包含其正文中OpenCV中的所有其他头文件。 So, if you include that file, it is more than enough. 因此,如果您包含该文件,则绰绰有余。

" .h" is for C and " .hpp" is for C++. .h”代表C,“。 hpp”代表C ++。 This is just the standard. 这只是标准。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM