Found 26504 Articles for Server Side Programming

How to reduce the color using Iterator Method in OpenCV?

Ginni
Updated on 10-Mar-2021 08:15:47

310 Views

OpenCV has C++ STL compatible 'Mat iterator' class. Using this 'Mat iterator' class, we can access pixels very easily. We have to create an object of 'Mat iterator' class. We can do it as 'Mat_: : iterator example'. We have to use an underscore after 'Mat' like 'Mat_' because it is a template method. In this method, the return type must be specified while creating an object of 'iterator' class. That is why we have declared the datatype .The following program demonstrates how to reduce the color using Iterator Method in OpenCV.Example#include #include using namespace std;//Declaring std namespace using namespace ... Read More

How to reduce color using Pointer Method in OpenCV?

Ginni
Updated on 10-Mar-2021 08:15:09

551 Views

In image processing, we perform computation on the image. To be more specific, we perform a calculation on pixel so the higher the number of pixels, the more the time consuming the computation becomes. To reduce the computation time, we require to scan the image efficiently. We will learn how to implement an efficient image scanning loop using pointers.Here we will see the pixel scanning process with an example of the color reduction strategy. Color images such as RGB images are composed of 3 channels. Each of these channels has the same number of pixels but with corresponding values. Each ... Read More

How to get the value of a specific pixel in OpenCV using C++?

Ginni
Updated on 10-Mar-2021 08:14:27

5K+ Views

To read the value of a specific pixel, we can use either 'at' or 'direct access' method. Here, we will learn both of the approaches.Let's start with 'at' method. The following program reads the pixel value located at (10, 29) of an RGB image.Example#include #include using namespace std; using namespace cv; int main() {    Mat image;//taking an image matrix//    image = imread("sky.jpg");//loading an image//    int x = image.at(10, 29)[0];//getting the pixel values//    int y = image.at(10, 29)[1];//getting the pixel values//    int z = image.at(10, 29)[2];//getting the pixel values//    cout

How to change Pixel values using Direct Access Method in OpenCV?

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

474 Views

In the previous method (the 'at' method), we need to specify the image type while accessing the pixel values. There is another method which is simpler than 'at' method. It is called direct access method. To access pixel value using this method, we need to specify the Mat type such as Mat, Mat, Mat and so on.The following program demonstrates how to change Pixel Values using Direct Access Method in OpenCV.Example#include #include using namespace cv;//Declaring cv namespace using namespace std; void direct_access(Mat_ &image, int n){ //Declaring the function//    for (int x = 0; x < n; x++){ //initiating a ... Read More

How to change Pixel Values using 'at' Method in OpenCV?

Ginni
Updated on 10-Mar-2021 08:13:14

3K+ Views

In a grayscale image, the pixel value is a single numeric value. But in a color image such as RGB image, the pixel is a vector having three values. These three values represent three channels.Here we will create a function that accesses both the grayscale image and RGB image pixel values and randomly adds noise to image pixels. Then we call the function inside the main() function to observe the result.The following program demonstrates how to change Pixel Values using 'at' method in OpenCV.Example#include #include using namespace cv;//Declaring cv namespace using namespace std; void adding_Noise(Mat& image, int n){ //'adding_Noise' function// ... Read More

How to put a text in an image in OpenCV using 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

How to draw a 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

How to draw an Ellipse in OpenCV using C++?

Ginni
Updated on 10-Mar-2021 08:10:41

857 Views

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

How to 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

How to 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

Advertisements