improved color detection

This commit is contained in:
Lars Brubaker 2021-08-25 09:50:20 -07:00
parent 3d2eab94aa
commit a7f2d39e82

View file

@ -274,6 +274,9 @@ namespace MatterHackers.MatterControl.DesignTools
var min = new Vector3(double.MaxValue, double.MaxValue, double.MaxValue);
var max = new Vector3(double.MinValue, double.MinValue, double.MinValue);
var hueCount = new int[10];
var colorPixels = 0;
for(int y = 0; y < sourceImage.Height; y++)
{
int imageOffset = sourceImage.GetBufferOffsetY(y);
@ -292,12 +295,20 @@ namespace MatterHackers.MatterControl.DesignTools
if (saturation > .4 && lightness > .1 && lightness < .9)
{
hueDetected = hue;
return true;
hueCount[(int)(hue * 9)]++;
colorPixels++;
}
}
}
if (colorPixels / (double)(sourceImage.Width * sourceImage.Height) > .1)
{
var indexAtMax = hueCount.ToList().IndexOf(hueCount.Max());
hueDetected = indexAtMax / 10.0;
return true;
}
hueDetected = 0;
return false;
}