find max value in image c++

#include <iostream>
#include <opencv2/opencv.hpp>

int main() {
    cv::Mat image = cv::imread("path_to_your_image.jpg");

    if (image.empty()) {
        std::cerr << "Error loading image" << std::endl;
        return -1;
    }

    cv::Mat grayImage;
    cv::cvtColor(image, grayImage, cv::COLOR_BGR2GRAY);

    double minVal, maxVal;
    cv::Point minLoc, maxLoc;
    cv::minMaxLoc(grayImage, &minVal, &maxVal, &minLoc, &maxLoc);

    std::cout << "Maximum pixel value: " << maxVal << std::endl;
    std::cout << "Location of maximum value: (" << maxLoc.x << ", " << maxLoc.y << ")" << std::endl;

    return 0;
}