Reading Images

Header files and namespaces

Header files in C++ are used to declare functions, classes, and variables that are defined in a separate source file. These header files provide a way to separate the interface of a program from its implementation, making it easier to organize and maintain large code bases. We’ll use only one header file, opencv.hpp, for this lesson. This header file contains all the necessary functions used in OpenCV.

To include the code, we need to use the include keyword and also include the path to the file. In the code below, the header file is located in the opencv2 folder.

 #include <opencv2/opencv.hpp>

Namespaces are the declarations that provide scope to variables, functions, etc. In each scope, a name can represent only one variable. There can’t be two variables with the same name in the same scope. Using namespaces can solve this problem. We can create two variables or functions that have the same name, in two different namespaces.

In this lesson, we will use two namespaces, cv and std.

In this lesson, we’ll read an image, display it, and manage the display time. But first, we need to import the header files for reading and handling the media files.

Get hands-on with 1200+ tech skills courses.