Found 184 Articles for OpenCV

How to Change Contrast in OpenCV using C++?

Ginni
Updated on 10-Mar-2021 08:20:19

951 Views

Changing brightness and contrast are frequent editing effect in image processing.Here, we will learn how to change the contrast of images. Contrast controls the sharpness of the image. Higher the contrast the sharper the image, lower the contrast the smother the image.Changing the contrast means increasing the weight of the pixels. More the contrast, sharper the image is. To change the contrast, multiply the pixel values with some constant. For example, if multiply all the pixel values of an image by 2, then the pixel's value will be doubled, and the image will look sharper.The following program demonstrates how to ... Read More

How to decrease the Brightness of an image in OpenCV using C++?

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

299 Views

The way of decreasing brightness is very similar to increasing brightness. The only difference is subtracting the 'Scalar (B, G, R)' from the image. Here, we are subtracting the scalar value to decrease the brightness.The following program shows how to decrease the brightness of an image in OpenCV.Example#include #include using namespace cv; using namespace std; int main() {    Mat original; //Declaring a matrix to load the original image//    Mat dimmer;//Declaring a matrix to load the image after changing the brightness//    namedWindow("Original");//Declaring window to show the original image//    namedWindow("Dimmer");//Declaring window to show the brighter image//    original ... Read More

How to change the brightness of an image in OpenCV using C++?

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

2K+ Views

Changing the brightness means changing the value of pixels. It means adding or subtracting value some integer value with the current value of each pixel. When you add some integer value with every pixel, it means you are making the image brighter. When you subtract some constant value from all of the pixels, you are reducing the brightness. First, we will learn how to increase the brightness and second we will learn how to reduce the brightness.Increasing the BrightnessIncreasing the Brightness using OpenCV is very easy. To increase the brightness, add some additional values with each channel, and the brightness ... Read More

How to reduce the color using Iterator Method in OpenCV?

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

158 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

338 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

4K+ 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

331 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

2K+ 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

3K+ 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

852 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

Advertisements