[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