/// <summary> /// Average Pixel Value /// 0 if fully black /// 255 if fully white /// </summary> /// <param name="roi"></param> /// <param name="recipe"></param> /// <returns></returns> private static VisionMapCategory CalculateMapCategory( EROIBW8 roi, MapVisionParameters recipe) { float DiePresentThreshold = recipe.DiePresentThreshold; float averagePixelValue; EasyImage.PixelAverage(roi, out averagePixelValue); VisionMapCategory visionMapCategory = VisionMapCategory.Undefined; //if (averagePixelValue > TakenDieThreshold && averagePixelValue <= 256) visionMapCategory = VisionMapCategory.Taken; //else if (averagePixelValue > GoodDieThreshold && averagePixelValue <= TakenDieThreshold) visionMapCategory = VisionMapCategory.GoodDie; //else if (averagePixelValue > BadDieThreshold && averagePixelValue <= GoodDieThreshold) visionMapCategory = VisionMapCategory.BadDie; if (averagePixelValue > DiePresentThreshold) { visionMapCategory = VisionMapCategory.DieTaken; } else if (averagePixelValue <= DiePresentThreshold) { visionMapCategory = VisionMapCategory.DieRemain; } else { throw new Exception("Invalid vision Map Category"); } return(visionMapCategory); }