26

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.

Simon
  • 6,293
  • 2
  • 28
  • 34
makys
  • 273
  • 1
  • 3
  • 5
  • 1
    What things? You should describe what you are doing with openCV. Depending on that you can decide what to include. Including more than necessary loads a lot of unnecessary code to your program. – Sergio Basurco Oct 04 '13 at 09:16

3 Answers3

32

.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.
morotspaj
  • 1,400
  • 11
  • 26
sansuiso
  • 9,259
  • 1
  • 40
  • 58
  • More info about `.h` vs. `.hpp` may be found in [this questions](http://stackoverflow.com/questions/152555/h-or-hpp-for-your-class-definitions). – ffriend Oct 04 '13 at 09:29
  • Thanks. I think reason 1 in the question that you mention is really the most important one, because OpenCV has had C and C++ APIs in parallel since at least 1.0 (3 or 4 years ago). – sansuiso Oct 04 '13 at 11:35
  • Thank you sansuiso and ffriend – makys Oct 10 '13 at 03:13
7
#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.

SRF
  • 929
  • 1
  • 7
  • 15
3

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

Saikat
  • 1,209
  • 3
  • 16
  • 30
  • 2
    Thanks. I paste the link of opencv.hpp here: [link](https://github.com/Itseez/opencv/blob/master/include/opencv2/opencv.hpp) – makys Oct 10 '13 at 03:14