/// <summary> /// Initializes a new instance of the <see cref="NormalizedHands"/> class. /// </summary> /// <param name="left">The normalized left hand.</param> /// <param name="right">The normalized right hand.</param> public NormalizedHands(NormalizedHand left, NormalizedHand right) { this.Left = left; this.Right = right; double centerX = (left.X + right.X) / 2; double centerY = (left.Y + right.Y) / 2; this.Center = new PointD(centerX, centerY); this.RatioOfLeftWeightToRightWeight = left.Weight / right.Weight; }
private HandsDetectorResult DetectHandsInternally(BgrImage image) { int handAreaWidth = image.Width / DIVISOR_TO_GET_HAND_AREA_WIDTH_FROM_IMAGE_WIDTH; NormalizedHand left = this.EvaluatePixels(image, 0, handAreaWidth, this.tuning.HandsColorMaps.Left, this.neutralHands?.Left); NormalizedHand right = this.EvaluatePixels(image, image.Width - handAreaWidth, handAreaWidth, this.tuning.HandsColorMaps.Right, this.neutralHands?.Right); int radius = image.Width * image.Height / DIVISOR_TO_GET_HAND_MARKER_CIRCLE_RADIUS_FROM_IMAGE_SIZE; if (this.Tuned && this.neutralHands != null) { image.DrawLineSegment(left.X, left.Y, this.neutralHands.Center.X, this.neutralHands.Center.Y, Color.Yellow, radius); image.DrawLineSegment(this.neutralHands.Center.X, this.neutralHands.Center.Y, right.X, right.Y, Color.Yellow, radius); } image.DrawCircle(left.X, left.Y, Color.Blue, radius, BgrImage.FILL_DRAWING); image.DrawCircle(right.X, right.Y, Color.Blue, radius, BgrImage.FILL_DRAWING); NormalizedHands normalizedHands = new NormalizedHands(left, right); return(new HandsDetectorResult(normalizedHands, image)); }
private NormalizedHand EvaluatePixels(BgrImage image, int startX, int width, ColorMap colorMap, NormalizedHand neutralHand) { HandBuilder handBuilder = new HandBuilder(); for (int y = 0; y < image.Height; y++) { for (int x = startX; x < startX + width; x++) { BgrPixel pixel = image.GetPixel(x, y); if (this.IsBackground(pixel, x, y)) { image.SetPixel(this.backgroundPixel, x, y); } else if (!colorMap.Satisfies(pixel)) { image.SetPixel(this.unknownPixel, x, y); } else { image.SetPixel(this.skinPixel, x, y); handBuilder.Append(x, y); } } } NormalizedHand detectedHand = new HandNormalizer(image.Width, image.Height).Normalize(handBuilder.Build()); if (this.Tuned && neutralHand != null && detectedHand.Weight < neutralHand.Weight / DIVISOR_TO_GET_VALID_HAND_WEIGHT_LOWER_BOUND_FROM_NEUTRAL_HAND_WEIGHT) { // after tuning the neutral hands are cached // if the weight of the hand is under a threshold // (which probably means that there is no hand on the image but noise) // then we're going to use the cached neutral hand instead of the freshly detected (wrong) one detectedHand = new NormalizedHand(neutralHand.X, neutralHand.Y, neutralHand.Weight); } return(detectedHand); }