1 | initial version |
i think, you want a histogram here. one could use calcHist for this, but it's probably overkill.
// demo data: Mat_<uchar> data(1,48); data << 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0;
// uchar Mat's can hold 256 distinct values: Mat_<int> hist(256, 1); hist = 0; // all set to 0 initially
for (int i=0; i<data.cols; i++)="" {="" uchar="" v="data(0,i);" hist(v)="" ++;="" increase="" bin="" for="" number="" }<="" p="">
cerr << hist(0) << " zeros." << endl; cerr << hist(2) << " twos." << endl; cerr << hist(4) << " fours." << endl;
// output 35 zeros. 8 twos. 5 fours.
2 | No.2 Revision |
i think, you want a histogram here. one could use calcHist for this, but it's probably overkill.
// demo data:
Mat_<uchar> data(1,48);
data << 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2,