Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#include C++ header files in opencv

Tags:

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.

like image 247
makys Avatar asked Oct 04 '13 09:10

makys


1 Answers

.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.
like image 70
sansuiso Avatar answered Oct 04 '22 09:10

sansuiso