#includeusing namespace cv; int main() { //Create a Mat object of size 320x240 with 3 channels Mat image(240, 320, CV_8UC3); //Display the image namedWindow("Image", WINDOW_AUTOSIZE); imshow("Image", image); waitKey(0); return 0; }
#includeIn this example, an image is loaded and then converted to grayscale using the cvtColor function. The COLOR_BGR2GRAY parameter specifies that the conversion should be from the BGR (blue, green, red) color space to grayscale. Package library: OpenCV (Open Source Computer Vision) Library.using namespace cv; int main() { //Load the original image Mat image = imread("image.jpg"); //Convert the image to grayscale Mat grayImage; cvtColor(image, grayImage, COLOR_BGR2GRAY); //Display the grayscale image namedWindow("Grayscale Image", WINDOW_AUTOSIZE); imshow("Grayscale Image", grayImage); waitKey(0); return 0; }