#include C++ header files in opencv

2020-02-26 14:44发布

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.

标签: c++ opencv
3条回答
▲ chillily
2楼-- · 2020-02-26 15:14

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

查看更多
Luminary・发光体
3楼-- · 2020-02-26 15:21
#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.

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

查看更多
看我几分像从前
4楼-- · 2020-02-26 15:27

.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.
查看更多
登录 后发表回答