title: How to compute maximum pixel value of Mat in OpenCV
body: <p>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. </p>
  
  <pre><code>double cvMax(cv::Mat&amp; mat)
  {
  float max=0;
  float* pData=(float*)mat.data;
  for(int i=0;i&lt;mat.rows;i++) 
  {
      for(int j=0;j&lt;mat.cols;j++)
      {
          float value = pData[j+i*mat.cols];
          if(value&gt;max) 
          {
              max=value;
          }
      }
  }
  return max;
  }
  </code></pre>