Ask Your Question

How do I know which header file I should use for my OpenCV C++ program?

asked 2018-12-22 10:26:24 -0500

Dear OpenCV community,

This might be a noob question. I have been an OpenCV Python user previously. Now I am switching to C++. I wonder how should I determine which header files I should use for my program. For example, I want to use the function "imread", which header files I should include in my program? I tried to look up on but found no clue. Thank you.

Best regards,


edit retag flag offensive close merge delete


there is a (working !) search box on the docs page (top right). try it !

(it will show you the module, your function is in)

berak gravatar imageberak ( 2018-12-22 21:02:41 -0500 )edit

Sorry, I tried but I think I did not get what you mentioned. Say I put "imread" in the search box, then click on "imread" in the drop-down list. I don't see any word "imgcodecs" there.

Lei Mao gravatar imageLei Mao ( 2018-12-23 09:53:49 -0500 )edit

group__imgcodecs (in the url) should give it away, already, no ?

berak gravatar imageberak ( 2018-12-23 09:58:08 -0500 )edit

Orz. It could have been more standing out to the users. Thank you anyway.

Lei Mao gravatar imageLei Mao ( 2018-12-23 09:59:11 -0500 )edit

ofc. you're right ;)

berak gravatar imageberak ( 2018-12-23 10:04:51 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-22 11:08:43 -0500

LBerger gravatar image

updated 2018-12-22 11:39:28 -0500

First take a look at "OpenCV modules" in Documentation :

header for core. Core functionality module is # include<opencv2/core.hpp>

header for imgproc. Image Processing module is # include<opencv2/imgproc.hpp>

header for highgui. High-level GUI module is #include <opencv2/highgui.hpp>


and so on.

Then read for example documentation of function findcontours It is in imgproc module (read link or at the beginning of the page it is written Image Processing)

or you can use only #include <opencv2/opencv.hpp> all module in opencv will be included and opencv only.

For opencv_contrib apply first recipe

edit flag offensive delete link more


Thank you. I got used to the documentation style that CPP references uses. For example,, for each function, it specifically tells you where you could find the declaration of the function. It will be beneficial for Googlers if we have this :)

Lei Mao gravatar imageLei Mao ( 2018-12-22 11:57:54 -0500 )edit

you can create a new issue if you believe this is a feature request

sturkmen gravatar imagesturkmen ( 2018-12-22 12:12:41 -0500 )edit

Well, it's personal preference. Somebody may like it somebody may not :) I am not sure I am professional enough in the OpenCV community to request certain features.

Lei Mao gravatar imageLei Mao ( 2018-12-22 12:15:11 -0500 )edit

"I am a perfectionist. I want to solve the problems in my hands in perfect ways, which is, however, not achievable in many situations." i liked it. why not.i think the documentation needs many improvements.

sturkmen gravatar imagesturkmen ( 2018-12-22 12:23:53 -0500 )edit

Haha. Thank you. I will propose it on GitHub issues soon.

Lei Mao gravatar imageLei Mao ( 2018-12-22 12:25:18 -0500 )edit

OpenCV 4.0.1 released today. I suggest you to build it with examples (set BUILD_EXAMPLES to build all examples)

sturkmen gravatar imagesturkmen ( 2018-12-22 12:51:02 -0500 )edit

Question Tools

1 follower


Asked: 2018-12-22 10:26:24 -0500

Seen: 2,053 times

Last updated: Dec 22 '18