EMGU Finding the most common value in a UMat


/ Published in: C#
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.