int handID = -1; float TIMER = 1; float comparisonValue = 0.7f; enum CustomGestures { None, Closing, Opening } ; float storedSphereRadius = -1; DateTime afterGesture = DateTime.MaxValue; CustomGestures detectedGesture = CustomGestures.None; void FirstAttempt(Frame frame) { Hand hand; bool knownHand = false; detectedGesture = CustomGestures.None; double seconds = ((TimeSpan)(DateTime.Now - then)).TotalSeconds; //if timer expired if (seconds >= TIMER) { //Reset Timer and stored values in order to retrieve new ones resetValues(); } // get hand if (handID == -1) hand = frame.Hands[0]; else { knownHand = true; hand = frame.Hand(handID); } // is hand invalid? if (!hand.IsValid) { resetValues(); return; } else { handID = hand.Id; } // if it's the same hand, then we have a sphereRadius value // from which we can do a comparison if (knownHand && seconds < TIMER) { //Console.WriteLine(storedSphereRadius.ToString() + "::::" + hand.SphereRadius.ToString()); // if actual hand's sphere radius is around 65% from stored one, // then we can assume the that the hand is closed if (hand.SphereRadius < storedSphereRadius * comparisonValue) { detectedGesture = CustomGestures.Closing; SafeWriteLine("Closing"); //Console.WriteLine(storedSphereRadius.ToString() + "::::" + hand.SphereRadius.ToString()); } else if (hand.SphereRadius * comparisonValue > storedSphereRadius) { detectedGesture = CustomGestures.Opening; SafeWriteLine("Opening"); //Console.WriteLine(storedSphereRadius.ToString() + "::::" + hand.SphereRadius.ToString()); } } // in this case, it means we have a new Hand object, // hence the need to restore sphereRadius value else if (!knownHand) { storedSphereRadius = hand.SphereRadius; } // reset since we detected either a closing or an opening gesture if (detectedGesture != CustomGestures.None) { resetValues(); } } void resetValues() { then = DateTime.Now; handID = -1; storedSphereRadius = -1; } #endregion