Posted By

markt22 on 03/28/17


Tagged

hsv hue opencv emgu


Versions (?)

EMGU Finding the most common value in a UMat


 / Published in: C#
 

Given a UMat we sometimes need to find the most common value in that UMat. This code does it the unsafe (fast) way.

  1. UMat umat = new UMat();
  2. byte mostCommonValue;
  3.  
  4. fixed (byte* buffer = umat.Bytes)
  5. {
  6. byte* end = buffer + umat.Bytes.Length;
  7.  
  8. int[] counters = new int[256];
  9.  
  10. for (byte* pointer = buffer; pointer != end; pointer++)
  11. {
  12. counters[*pointer]++;
  13. }
  14.  
  15. mostCommonValue = (byte)Array.IndexOf(counters, counters.Max());
  16. }

Report this snippet  

You need to login to post a comment.