This should be obvious, I thought. But I can’t find easy way to find maximum among all pixels in a Mat of OpenCV. Of course, I can do following for each pixel type. But general max function would be still useful.
double cvMax(cv::Mat& mat)
{
float max=0;
float* pData=(float*)mat.data;
for(int i=0;i<mat.rows;i++)
{
for(int j=0;j<mat.cols;j++)
{
float value = pData[j+i*mat.cols];
if(value>max)
{
max=value;
}
}
}
return max;
}
You could always use the std max_element function with iterators from opencv