/// <summary> /// Forward-only blob search /// </summary> private PixelBlob FindBlob(PixelData data) { PixelBlob blob = null; PixelBlob currentBlob = null; PixelDataList pixels = null; bool isNeighbor = false; for (int b = this.Blobs.Count - 1; b >= 0 && blob == null; b--) { currentBlob = this.Blobs[b]; pixels = null; isNeighbor = false; if (currentBlob.Pixels.Count > 0) { pixels = currentBlob.Pixels[currentBlob.Pixels.Count - 1]; // Same Y-Index as the current pixel if (pixels.Y == data.Y) { if (Math.Abs(pixels[pixels.Count - 1].X - data.X) <= 1) { isNeighbor = true; } } // Previous Y-index as the current pixel else if (pixels.Y == (data.Y - 1)) { // Iterate through the y position for (int x = 0; x < pixels.Count && !isNeighbor; x++) { if (Math.Abs(pixels[x].X - data.X) == 0) { isNeighbor = true; } } } // If the current blob neighbors the current pixel. Check the threshold if (isNeighbor && Math.Abs(data.Red - currentBlob.AverageR) <= this.ToleranceR && Math.Abs(data.Green - currentBlob.AverageG) <= this.ToleranceG && Math.Abs(data.Blue - currentBlob.AverageB) <= this.ToleranceB) { blob = currentBlob; } } } return(blob); }
public void AddPixel(PixelData data) { // Add to pixels if (this.Pixels.Count == 0 || this.Pixels[this.Pixels.Count - 1].Y != data.Y) { PixelDataList yData = new PixelDataList(); yData.Y = data.Y; this.Pixels.Add(yData); } this.Pixels[this.Pixels.Count - 1].Add(data); // Backwards blob reference for the pixel data.Blob = this; this._staticCount++; this._totalR += data.Red; this._totalG += data.Green; this._totalB += data.Blue; // Check for new blob x range if (this.XMin > data.X) { this._xMin = data.X; } else if (this.XMax < data.X) { this._xMax = data.X; } // Check for new blob y range if (this.YMin > data.Y) { this._yMin = data.Y; } else if (this.YMax < data.Y) { this._yMax = data.Y; } }