第一种方法:

Mat img = imread("./1.jpg", 0);
double minVal = 0.0;
double maxVal = 0.0;
minMaxLoc(img, &minVal, &maxVal);
cout << minVal << ", " << maxVal << endl;

  第二种方法:

Mat img = imread("./1.jpg", 0);
	
vector<uchar>pixels;
for (int i = 0; i < img.rows; i++)
{
	uchar* data = img.ptr<uchar>(i);
	for (int j = 0; j < img.cols; j++)
		pixels.push_back(data[j]);
}
sort(pixels.begin(), pixels.end());
cout << int(pixels.at(0)) << ", " << int(pixels.at(pixels.size() - 1)) << endl;

第三种方法:

Mat img = imread("./1.jpg", 0);

uchar* begin = img.ptr<uchar>(0);
uchar* end = img.ptr<uchar>(img.rows - 1);
sort(begin, end + img.cols);
uchar min_value = img.row(0).at<uchar>(0, 0);
uchar max_value = img.row(img.rows - 1).at<uchar>(0, int(img.cols - 1));
cout << int(min_value) << ", " << int(max_value) << endl;