I am trying to find the maximum pixel value of a cv::Mat
.
The Problem : *maxValue
is always returning 0
.
From this S.O. thread, I understand that 'max_element
return iterators, not values. This is why I use *maxValue
'
cv::Mat imageMatrix; double sigmaX = 0.0; int ddepth = CV_16S; // ddepth – The desired depth of the destination image cv::GaussianBlur( [self cvMatFromUIImage:imageToProcess], imageMatrix, cv::Size(3,3), sigmaX); cv::Laplacian(imageMatrix, imageMatrix, ddepth, 1); std::max_element(imageMatrix.begin(),imageMatrix.end()); std::cout << "The maximum value is : " << *maxValue << std::endl;
Note : If min_element
is substituted in place of max_element
, and minValue
in place of maxValue
, *minValue
will always return 0
.
You should use the OpenCV built-in function minMaxLoc
instead of std
function.
Mat m; //Initialize m double minVal; double maxVal; Point minLoc; Point maxLoc; minMaxLoc( m, &minVal, &maxVal, &minLoc, &maxLoc ); cout << "min val: " << minVal << endl; cout << "max val: " << maxVal << endl;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With