OpenCV:计算一组 cv::Mat 的统计模式 [英] OpenCV: compute the statistical mode of a set of cv::Mat

查看:66
本文介绍了OpenCV:计算一组 cv::Mat 的统计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下方法获取一组 cv::Mat 的统计模式:

I am using the following to obtain the statistical mode of a set of cv::Mat:

vector<Mat> imgs(30);
...
...

Mat mode = Mat::zeros(imgRows, imgCols, CV_8U);
for(int i=0;i<mode.rows;i++)
{
    for(int j=0;j<mode.cols;j++)
    {
        vector<int>count(256,0);
        int maxIndex=0, maxCount=0;
        int index;
        for(int n=0;n<imgs.size();n++)
        {
            index = imgs[n].at<uchar>(i,j);
            count[index]++;
            if(count[index] > maxCount)
            {
                maxCount = count[index];
                maxIndex = index;
            }
        }
        mode.at<uchar>(i,j) = maxIndex;
    }
}

是否有其他方法可以更有效地计算模式?

Is there other ways to compute the mode more efficient?

推荐答案

计算直方图并使用直方图中的峰值.可以修改opencv已经提供的代码来计算模式.此页面还介绍了直方图及其不同的使用方式.

Calculate histogram and use the peak value in the histogram. You can modify the code already provided by opencv to calculate mode. This page also explains about histogram and different ways to use it.

这篇关于OpenCV:计算一组 cv::Mat 的统计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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