/// <summary> /// Polls the Gestures API for up to date confidence values. /// </summary> void Update() { if (!MLHands.IsStarted) { return; } if (_statusText != null) { _statusText.text = string.Format( "Current Hand Gestures\nLeft: {0}, {2}% confidence\nRight: {1}, {3}% confidence", MLHands.Left.KeyPose.ToString(), MLHands.Right.KeyPose.ToString(), (MLHands.Left.KeyPoseConfidence * 100.0f).ToString("n0"), (MLHands.Right.KeyPoseConfidence * 100.0f).ToString("n0")); } // If inactive, listen to Activate signal if (!_targetObject.activeSelf && GetKeyPoseConfidence(MLHands.Left, MLHands.Right, _keyPoseToToggleON)) { _statusText.text = string.Format("Hand Gestures {0} Detected !!", _keyPoseToToggleON.ToString()); _targetObject.SetActive(true); } // If active, listen to Deactivate signal if (_targetObject.activeSelf && GetKeyPoseConfidence(MLHands.Left, MLHands.Right, _keyPoseToToggleOFF)) { _statusText.text = string.Format("Hand Gestures {0} Detected !!", _keyPoseToToggleOFF.ToString()); _targetObject.SetActive(false); } }
void Hand_OnKeyPoseBegin(MLHandKeyPose obj) { if (MLHands.IsStarted && mlHand.HandConfidence < 0.85f) { return; } //Debug.Log(name + ": KEY POSE BEGIN: " + obj); SetHandObjectsActive(true); MLHandKeyPose lastPose = currentPose; currentPose = obj; if (currentPose != MLHandKeyPose.NoHand && (!MLHands.IsStarted || mlHand.HandConfidence > 0.85f)) { SetHandObjectsActive(true); } if (textPoseInfo != null) { textPoseInfo.text = "POSE: " + currentPose.ToString(); Debug.Log(textPoseInfo.text); } float poseTime = Time.time - lastPoseTime; //Debug.Log("Check for onhandposebegin: " + OnHandPoseBegin); if (OnHandPoseBegin != null) { //Debug.Log("On hand pose begin: " + obj); OnHandPoseBegin(this, obj); } lastPoseTime = Time.time; }
public static bool IsOpenHand(this MLHandKeyPose keyPose) => keyPose.ToString() == "OpenHandBack";
public static bool IsFist(this MLHandKeyPose keyPose) => keyPose.ToString() == "Fist";
// We subscribe to the event "OnKeyPoseBegin" which basically fires right when a gesture is being detected. //private void OnEnable() //{ // MLHands.Right.OnKeyPoseBegin += HandPoseReaction; // MLHands.Left.OnKeyPoseBegin += HandPoseReaction; //} // Normally you'd put here your reactive code; what would happen when a specific gesture is recognized. Here we simply just print the gesture's name on screen. private void HandPoseReaction(MLHandKeyPose _pose) { Debug.Log(_pose.ToString()); }