Draw a Line in OpenCV using C++

Ginni
Updated on 10-Mar-2021 08:06:58

2K+ Views

To draw a line we need two points-the starting point and ending point. We also require a canvas to draw the line.Using OpenCV, the matrix in our canvas, we need to define the line's starting and ending points. We require to assign a color to the line as well. The thickness of the line has to be explained too. If we want to draw a line using OpenCV, we need to declare a matrix, two points, and color and line thickness.Using OpenCV we have to include header because line() function is defined in this header.The basic syntax of this ... Read More

Draw a Circle in OpenCV Using C++

Ginni
Updated on 10-Mar-2021 08:06:17

8K+ Views

A circle has a center and a radius. To draw a circle using OpenCV, we have to define the center and the radius. In OpenCV we have to include header because 'circle()' function is defined in this header.The basic syntax of this method is as follows −Syntaxcircle(whiteMatrix, center, radius, line_Color, thickness);The following program represents how to draw a circle in OpenCV.Example#include #include #include using namespace cv; using namespace std; int main() {    Mat whiteMatrix(200, 200, CV_8UC3, Scalar(255, 255, 255));//Declaring a white matrix    Point center(100, 100);//Declaring the center point    int radius = 50; //Declaring the radius   ... Read More

Put Text in an Image using OpenCV and C++

Ginni
Updated on 10-Mar-2021 08:03:35

5K+ Views

In OpenCV, we can put some text in the image by using puttext() function. This function is defined in header. To put text in an image, we first need to declare the matrix which will load the image.Instead of loading an image in our program, we have filled matrix with white color, and then we put the text in that matrix. We need to define the text's starting point in the matrix, the text's font, the font's color and the font's weight.The basic syntax of this method is as follows −SyntaxputText(image, "Text in Images", text_position, FONT_HERSHEY_COMPLEX, font_size, font_Color, font_weight);The ... Read More

Draw Rectangle in OpenCV Using C++

Ginni
Updated on 10-Mar-2021 08:02:55

1K+ Views

To draw a rectangle, we need four points. Look at the following figure.In the figure, there are four points x1, x2, y1 and y2. These four points are forming the four coordinates. To draw a rectangle using OpenCV, we have to define these points and show the rectangle we need a matrix. We have to declare other relevant values like the color of the line and line width.The basic syntax of this method is as follows −Syntaxrectangle(whiteMatrix, starting, ending, line_Color, thickness);The following program represents how to draw a rectangle in OpenCV.Example#include #include #include using namespace cv; using namespace std; int ... Read More

Read Pixel Value of Single Channel Image in OpenCV Using C++

Ginni
Updated on 10-Mar-2021 07:57:00

2K+ Views

Digital images are made of pixels. Using OpenCV, it is easy to read the value of pixels. However, if we want to get the pixel values, we have to handle a single channel separately.Here we are loading an image in the matrix named 'cimage', and then it converts the image using 'cvtColor(cimage, img, COLOR_BGR2GRAY); ' and store it in the matrix named 'img'.The following program read the pixel value of an image and shows the values in console window.Example#include #include #include using namespace std; using namespace cv; int main() {    int x;//Declaring an integer variable to hold values of pixels// ... Read More

Convert Color Spaces in OpenCV Using C++

Ginni
Updated on 10-Mar-2021 07:53:48

2K+ Views

Color space is the model of representing colors. There are different ways of describing colors. For example, RGB, CYMK, HSV, Grayscale etc.Here, we used a new header named 'imgproc.hpp'. This 'imgproc.hpp' is the abbreviation of Image Processing. To convert color spaces, we need to use 'cvtColor()' function of OpenCV. This function is defined in 'imgproc' header file. That's why we have included 'imgproc.hpp'.Firstly, we declared two matrices and two windows. These are for loading and showing the images. Then we loaded our image named 'cat.jpg' into 'myImage' matrix.  After that we used 'cvtColor(myImage, myImage_Converted, COLOR_RGB2GRAY)'. This line converts the RGB color space ... Read More

Split Images into Different Channels in OpenCV using C++

Ginni
Updated on 10-Mar-2021 07:50:14

4K+ Views

There are three channels in an RGB image- red, green and blue. The color space where red, green and blue channels represent images is called RGB color space. In OpenCV, BGR sequence is used instead of RGB. This means the first channel is blue, the second channel is green, and the third channel is red. To split an RGB image into different channels, we need to define a matrix of 3 channels. We use 'Mat different_Channels[3]' to define a three-channel matrix.Next, we split the loaded image using OpenCV 'split()' function. The format of this function is 'split(Source Matrix, Destination Matrix)'. This function ... Read More

Calculate Number of Channels of an Image in OpenCV Using C++

Ginni
Updated on 10-Mar-2021 07:49:54

2K+ Views

In this topic, we will understand how to find out the number of channels of an image. After running the program, the number of the channel will be shown in the console window.To get the number of the channel, we have used a class of OpenCV named 'channels()'. When we pass the image matrix as an object of the class 'channels()', it gives the channel an integer value.The following program counts the number of the channels and show it in the console window.Example#include #include using namespace std; using namespace cv; int main(int argc, char** argv) {    Mat image_load;//Declaring a ... Read More

What is Image Array in C++? Explained with Example

Ginni
Updated on 10-Mar-2021 07:49:32

850 Views

An array is a convenient method to store and retrieve the collection of data. In OpenCV, we can use this concept to load multiple images in an image array and show them using the array's index number.The following program loads multiple images in a matrix array and shows the array's images called by the index number.Example#include #include using namespace cv; using namespace std; int main(int argc, const char** argv) {    Mat myImage_array[3];//declaring a matrix named myImage//    namedWindow("PhotoFrame1");//declaring the window to show the image//    namedWindow("PhotoFrame2");//declaring the window to show the image//    namedWindow("PhotoFrame3");//declaring the window to show the ... Read More

Load and Show Image in OpenCV Using C++

Ginni
Updated on 10-Mar-2021 07:45:51

3K+ Views

In this topic, we will determine how to load and show images using OpenCV in C++. There are the following functions required for loading and showing an image in OpenCV. Mat: Mat is not a function. It is a data structure, a type of variable. Like int, char, string variable types in C++, Mat is a variable of OpenCV, which creates a matrix data structure to load images inside it. In this program, we wrote 'Mat myImage;'. That means we are declaring a matrix variable named 'myImage'. namedWindow(): It allocates some memory and creates a window to show the image. It works like a ... Read More

Advertisements