Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get the total of the same number in a MAT

Hi, I have a mat M size -1 X48 M = [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]

How can i seggregate and know that inside the Mat there are 5 frequency for #3, 8 frequency for #2 and 5 frequency of #4.

Example for my code here not able to calculate #2 and only stated 0. Any advice?

 for(int y=0;y< 1;y++){
     for (int x=0;x< 48; x++){

        if (frame_gray.at<uchar>(y,x)==2)
        { two++;}
        else {}

     }  }

cout << "zero =" << zero << endl;
cout << "two =" << two << endl;
cout << "four =" << four << endl;

the output

M = [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, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0]

zero =0 two =0 four =0