Ask Your Question

Should I include opencv2/opencv.hpp?

asked 2017-02-06 10:31:49 -0600

mddrill gravatar image

updated 2017-02-06 10:32:44 -0600

Most of the OpenCV tutorials I've watching have only one include statement #include opencv2/opencv.hpp

But I'm not sure if this is the best way to do things or just the easy way, it seems like this include statement just includes everything whether I need it or not. Would it speed up my program if I only added the header files that I needed? If so, how can I find out what header files the functions in my program are in? The OpenCV documentation doesn't seem to give that information.

Thank You

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-06 10:38:40 -0600

LBerger gravatar image

updated 2017-02-06 10:39:59 -0600

With this include

#include <opencv2/opencv.hpp>

your compiler will include everything you have selected in CMake (except opencv_contrib modules) :

// File that defines what modules where included during the build of OpenCV
// These are purely the defines of the correct HAVE_OPENCV_modulename values
#include "opencv2/opencv_modules.hpp"

// Then the list of defines is checked to include the correct headers
// Core library is always included --> without no OpenCV functionality available
#include "opencv2/core.hpp"
// Then the optional modules are checked
#include "opencv2/calib3d.hpp"
#include "opencv2/features2d.hpp"
#include "opencv2/flann.hpp"

If you don't care of time compliation you can do like that. If you want to compile faster you should do like this :

#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"

You have to choose now

edit flag offensive delete link more



I don't care about compilation time, but I do care about how fast the program runs. So I can just leave `#include "opencv2/opencv.hpp", right?

mddrill gravatar imagemddrill ( 2017-02-06 11:08:31 -0600 )edit

yes you are right that does not matter

LBerger gravatar imageLBerger ( 2017-02-06 11:10:59 -0600 )edit

Question Tools

1 follower


Asked: 2017-02-06 10:31:49 -0600

Seen: 13,031 times

Last updated: Feb 06 '17