OpenCV计算图像像素最大值、最小值
生活随笔
收集整理的這篇文章主要介紹了
OpenCV计算图像像素最大值、最小值
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? 第一種方法:
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;?
總結
以上是生活随笔為你收集整理的OpenCV计算图像像素最大值、最小值的全部內容,希望文章能夠幫你解決所遇到的問題。