convert image to grayscale opencv

#include <opencv2/opencv.hpp>

int main() {
    // Read the input image
    cv::Mat inputImage = cv::imread("input.jpg");

    // Check if the image is successfully loaded
    if (inputImage.empty()) {
        std::cerr << "Error: Unable to load the input image." << std::endl;
        return -1;
    }

    // Convert the input image to grayscale
    cv::Mat grayscaleImage;
    cv::cvtColor(inputImage, grayscaleImage, cv::COLOR_BGR2GRAY);

    // Save the grayscale image
    cv::imwrite("output_grayscale.jpg", grayscaleImage);

    return 0;
}