public static Color GetColorFromHSV(FastPixelHSV pixel) { int R = 0, G = 0, B = 0; HsvToRgb(pixel.GetHue(), pixel.GetSaturation() / 100.0, pixel.GetValue() / 100.0, out R, out G, out B); return(Color.FromArgb(R, G, B)); }
protected void GetAverageChestColor(FastBitmapHSV bitmap, Point chestPos, out int avgHue, out int avgSat) { float scale = 1.0f / (rectChestArea.Width * rectChestArea.Height); float accHue = 0; float accSat = 0; for (int idxX = 0; idxX < rectChestArea.Width; idxX++) { for (int idxY = 0; idxY < rectChestArea.Height; idxY++) { FastPixelHSV testPx = bitmap.GetPixel(chestPos.X + rectChestArea.X + idxX, chestPos.Y + rectChestArea.Y + idxY); accHue += testPx.GetHue(); accSat += testPx.GetSaturation(); } } avgHue = (int)(accHue * scale); avgSat = (int)(accSat * scale); }
public override bool IsMatching(FastPixelHSV pixel) { int Saturation = pixel.GetSaturation(); if ((Saturation < SaturationMin) || (Saturation > SaturationMax) || (pixel.Value < ValueMin) || (pixel.Value > ValueMax)) { return(false); } int Hue = pixel.GetHue(); if (HueMin < 0 && Hue > 200) { Hue -= 360; } return((Hue >= HueMin) && (Hue <= HueMax)); }
public static FastPixelHSV GetAverageColor(FastBitmapHSV bitmap, Rectangle bounds) { float hueAcc = 0.0f; float satAcc = 0.0f; float valAcc = 0.0f; float scale = 1.0f / bounds.Width; for (int idx = 0; idx < bounds.Width; idx++) { FastPixelHSV testPx = bitmap.GetPixel(bounds.X + idx, bounds.Y); hueAcc += testPx.GetHue(); satAcc += testPx.GetSaturation(); valAcc += testPx.GetValue(); } FastPixelHSV avgPx = new FastPixelHSV(); avgPx.SetHSV((int)(hueAcc * scale), (int)(satAcc * scale), (int)(valAcc * scale)); return(avgPx); }