#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
// Read the color image
Mat colorImage = imread("input_color_image.jpg", IMREAD_COLOR);
// Convert the color image to grayscale
Mat grayImage;
cvtColor(colorImage, grayImage, COLOR_BGR2GRAY);
// Save the grayscale image
imwrite("output_gray_image.jpg", grayImage);
return 0;
}
1 ) In these code we explain about the this line includes the OpenCV library, which provides various functions for image processing and computer vision tasks.
2) This line brings the cv namespace into the current scope, allowing us to use OpenCV functions without prefixing them with cv:: .
3) this line reads a color image from the file named "input_color_image.jpg" into a Mat object named colorImage. IMREAD_COLOR specifies that the image should be loaded in color mode.
so these process we Make a color image to gray scale image usingĀ in C++ .