如何计算Mat在OpenCV中的最大像素值 [英] How to compute maximum pixel value of Mat in OpenCV

查看:1518
本文介绍了如何计算Mat在OpenCV中的最大像素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是显而易见的,我想。但我找不到简单的方法来找到最大的所有像素在Mat的OpenCV。当然,我可以为每个像素类型做以下。但一般max函数仍然有用。

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;
}


推荐答案

使用opencv中的迭代器的 max_element 函数

You could always use the std max_element function with iterators from opencv

std::max_element(Mat.begin<double>(),Mat.end<double>());

这篇关于如何计算Mat在OpenCV中的最大像素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆