#includeusing namespace cv; int main() { Mat image = imread("example.jpg"); namedWindow("My Image", WINDOW_NORMAL); imshow("My Image", image); waitKey(0); return 0; }
#includeIn this example, we are accessing each pixel in the image using the at function and using a Vec3b object to represent the color values of the pixel. We then invert the red component of each pixel and update it back to the Mat object. Package library: OpenCVusing namespace cv; int main() { Mat image = imread("example.jpg"); for (int i = 0; i < image.rows; i++) { for (int j = 0; j < image.cols; j++) { Vec3b pixel = image.at (i, j); pixel[2] = 255 - pixel[2]; image.at (i, j) = pixel; } } namedWindow("My Image", WINDOW_NORMAL); imshow("My Image", image); waitKey(0); return 0; }