To draw an ellipse, we need a center, major axis and minor axis. That means we need three parameters for the ellipse. We need a matrix where we will draw the ellipse, and we need to declare line thickness and line color.When we want to draw an ellipse using OpenCV, we have to mention the angle of rotation, and there are two additional parameter starting point and ending point. To call 'ellipse()' function, we need to include header file.The basic syntax of this method is as follows −Syntaxellipse(whiteMatrix, center, xy, angle, starting_point, ending_point, line_Color, thickness);The following program shows how to ... Read More
Here, we will understand how to save the OpenCV image to any location on your computer. OpenCV provides imwrite() function to save an image to a specified file. The file extension represents the image format. The actual format of the function is −imwrite("Destination/Name of the image with extension", Source Matrix)Here, "Destination" is where we want to save the image. In this program, we save the image as "Lakshmi.jpg". We can give any name to the image. The "Source Matrix" is the matrix where the image has been loaded. In this program, the image is loaded as "myImage" matrix.Example#include #include using namespace ... Read More
A binary image is just a digital image that represents two colors, black and white. From an image processing perspective, a binary image contains pixels with two possible values- zero and one. When the value of a pixel is 0, it represents a pure black color. When the value of the pixel is 1, it means pure white color.In a grayscale image, there are 256 different possible values for each. But in Binary Image, there are only two possible values. Binary images have different types of applications. For example, morphological transformation requires a binary image, object shape extraction from background ... Read More
Inverting a binary image means inverting the pixel values. From a visual perspective, when we invert a binary image, white pixels will be converted to black, and black pixels will be converted to white.The basic form of this function is −cvtColor(original_image, grayscale_image, COLOR_BGR2GRAY);The next line is converting the grayscale image into a binary image and storing the converted image into 'binary_image' matrix.threshold(grayscale_image, binary_image, 100, 255, THRESH_BINARY);Here 'grayscale_image' is the source matrix, 'binary_image' is the destination matrix. After that, there are two values 100 and 255. These two values represent the threshold range. In this line, the threshold range represents the ... Read More
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
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
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
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
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
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
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP