[opencv]统计每个像素值的数目


 

int histo[256] = { 0 };//直方图统计每个像素值的数目
    int width = img.cols, height = img.rows;
    int num_of_pixels = width*height;
    
    //统计每个像素值的数目
    for (int y = 0; y < height; ++y)
    {
        auto *data = new uchar[width * height * 3];
        for (int x = 0; x < width; ++x)
        {
            histo[data[x]] += 1;
        }
    }

    //统计当前像素值和之前像素值的总数
    for (int i = 1; i < 256; ++i)
        histo[i] = histo[i] + histo[i - 1];

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM