c# - Calculating Center Of many blobs with aforge and manualy -


I am trying to get the center of all the detected blops in an image, so I changed it to two different Tried in ways, and I got two different results!
has been followed as the first one:

  BlankConverterBlobCounter = NewBlackConverter (); BlobCounter.ObjectsOrder = ObjectsOrder.Area; BlobCounter.ProcessImage (image); Blob [] blobs = blobCounter.GetObjectsInformation (); AForge.Point Center = New AForge.Point (); If (blobs.Length> gt; {center.x = blobs.Average (c => c.CenterOfGravity.X); center. Y = Blobs Avg (C => c.CenterOfGravity.Y); }   

and followed in another way:

  System.Drawing.Point Center = new System.Drawing.Point (); Int count = 0; Int sum x = 0; Int'l = 0; For (int i = 0; i & lt; image.Width; i ++) for (int j = 0; j & lt; image.Height; j ++) {var p = image.GetPixel (i, J); If (! P.Name.ToLower (.) Equals ("ff000000") {sumX + = i; Sumy + = j; Count ++; }} If (calculation> 0) {center.x = sumX / count; center. Y = sumy / count; } Return center;   

Where

 ! P.Name.ToLower () Equivalent ("ff000000")   

This means that pixels are not black (i.e. it is from some blob).
But I do not understand why I get different results! Can someone help me and tell me why?

average of average is not equal to the average of their parts

e.g.

  • 5
  • 7
  • I can take these numbers:
  • Together, their average (1 + 3 + 5 + 7 + 9) / 5 = 5 but , if I list the {5,3} (Average 4) and {1.7,9} (average 5.66 ...), then the average {4, 5.66 ..}, I will find something near, but will not equal to 5.

    In this case, the center of the gravity method of Afras, is likely to return to the average position of the object which you average on average, while

    unrelated: the operation of more efficient image Check it out.

  • Comments

    Popular posts from this blog

    excel vba - How to delete Solver(SOLVER.XLAM) code -

    github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

    ios - Replace text in UITextView run slowly -