private bool getGestureState(PXCMHandData.BodySideType pSide) { var numGestures = mHand.QueryFiredGesturesNumber(); for (int j = 0; j < numGestures; ++j) { PXCMHandData.GestureData gestData; if (mHand.QueryFiredGestureData(j, out gestData) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMHandData.IHand hand; if (mHand.QueryHandDataById(gestData.handId, out hand) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { var gestName = gestData.name; if (gestName.Contains("cursor_click")) { if (hand.QueryBodySide() == pSide) { return(true); } } } } } return(false); }
/* Displaying current frame gestures */ private void DisplayGesture(PXCMHandData handAnalysis, int frameNumber) { int firedGesturesNumber = handAnalysis.QueryFiredGesturesNumber(); string gestureStatusLeft = string.Empty; string gestureStatusRight = string.Empty; if (firedGesturesNumber == 0) { return; } for (int i = 0; i < firedGesturesNumber; i++) { PXCMHandData.GestureData gestureData; if (handAnalysis.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMHandData.IHand handData; if (handAnalysis.QueryHandDataById(gestureData.handId, out handData) != pxcmStatus.PXCM_STATUS_NO_ERROR) { return; } PXCMHandData.BodySideType bodySideType = handData.QueryBodySide(); if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_LEFT) { gestureStatusLeft += "Left Hand Gesture: " + gestureData.name; NextPageGesture.Check(gestureData.name, Hand.LeftHand, form.GetInterval()); PreviousPageGesture.Check(gestureData.name, Hand.LeftHand, form.GetInterval()); FirstPageGesture.Check(gestureData.name, Hand.LeftHand, form.GetInterval()); EndPageGesture.Check(gestureData.name, Hand.LeftHand, form.GetInterval()); } else if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { gestureStatusRight += "Right Hand Gesture: " + gestureData.name; NextPageGesture.Check(gestureData.name, Hand.RightHand, form.GetInterval()); PreviousPageGesture.Check(gestureData.name, Hand.RightHand, form.GetInterval()); FirstPageGesture.Check(gestureData.name, Hand.RightHand, form.GetInterval()); EndPageGesture.Check(gestureData.name, Hand.RightHand, form.GetInterval()); } } } if (gestureStatusLeft == String.Empty) { form.UpdateInfo("Frame " + frameNumber + ") " + gestureStatusRight + "\n", Color.SeaGreen); } else { form.UpdateInfo("Frame " + frameNumber + ") " + gestureStatusLeft + ", " + gestureStatusRight + "\n", Color.SeaGreen); } }
public void ProcessingThread() { // Start AcquireFrame/ReleaseFrame loop while (senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { hand = senseManager.QueryHand(); if (hand != null) { // Retrieve the most recent processed data handData = hand.CreateOutput(); handData.Update(); // Get number of tracked hands nhands = handData.QueryNumberOfHands(); if (nhands > 0) { // Retrieve hand identifier handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_TIME, 0, out handId); // Retrieve hand data handData.QueryHandDataById(handId, out ihand); PXCMHandData.BodySideType bodySideType = ihand.QueryBodySide(); if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_LEFT) { leftHand = true; } else if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { leftHand = false; } // Retrieve all hand joint data for (int i = 0; i < nhands; i++) { for (int j = 0; j < 0x20; j++) { PXCMHandData.JointData jointData; ihand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData); nodes[i][j] = jointData; } } // Get world coordinates for tip of middle finger on the first hand in camera range handTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.x; handTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.y; handTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionWorld.z; swipehandTipX = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.x; swipehandTipY = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.y; swipehandTipZ = nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].positionImage.z; //Console.Out.WriteLine("Before x={0}", swipehandTipX); //Console.Out.WriteLine("Before speed={0}", nodes[0][Convert.ToInt32(PXCMHandData.JointType.JOINT_MIDDLE_TIP)].speed.x); // Retrieve gesture data if (handData.IsGestureFired("spreadfingers", out gestureData)) { gesture = Gesture.FingerSpread; } else if (handData.IsGestureFired("two_fingers_pinch_open", out gestureData)) { gesture = Gesture.Pinch; } else if (handData.IsGestureFired("wave", out gestureData)) { gesture = Gesture.Wave; } else if (handData.IsGestureFired("swipe_left", out gestureData)) { gesture = Gesture.SwipeLeft; } else if (handData.IsGestureFired("swipe_right", out gestureData)) { gesture = Gesture.SwipeRight; } else if (handData.IsGestureFired("fist", out gestureData)) { gesture = Gesture.Fist; } else if (handData.IsGestureFired("thumb_up", out gestureData)) { gesture = Gesture.Thumb; } } else { gesture = Gesture.Undefined; } UpdateUI(); if (handData != null) { handData.Dispose(); } } senseManager.ReleaseFrame(); } }
public RealSenseGestureEventArgs(PXCMHandData.GestureData gestureData, PXCMHandData.BodySideType bodySide) : this() { this.gestureData = gestureData; this.bodySide = bodySide; }
private static void ProcessHands(PXCMHandData handData) { // Querying how many hands were detected int numberOfHands = handData.QueryNumberOfHands(); //Console.WriteLine("{0} hand(s) were detected.", numberOfHands); // Querying the information about detected hands for (int i = 0; i < numberOfHands; i++) { // Querying hand id int handId; pxcmStatus queryHandIdStatus = handData.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_NEAR_TO_FAR, i, out handId); if (queryHandIdStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) { Console.WriteLine("Failed to query the hand Id."); continue; } //Console.WriteLine("Hand id: {0}", handId); // Querying the hand data PXCMHandData.IHand hand; pxcmStatus queryHandStatus = handData.QueryHandDataById(handId, out hand); if (queryHandStatus == pxcmStatus.PXCM_STATUS_NO_ERROR && hand != null) { // Querying the body side (Left/Right) PXCMHandData.BodySideType bodySide = hand.QueryBodySide(); //Console.WriteLine("Body Side: {0}", bodySide); // Querying the hand openness int handOpenness = hand.QueryOpenness(); //Console.WriteLine("Hand openness: {0}", handOpenness); SendMqttMessage(String.Format("red?{0}", (255 * handOpenness) / 100)); // Querying Hand 2D Position PXCMPointF32 massCenterImage = hand.QueryMassCenterImage(); //Console.WriteLine("Hand position on image: {0} | {1}", massCenterImage.x, massCenterImage.y); PXCMPoint4DF32 palmOrientation = hand.QueryPalmOrientation(); rotationHelper.SetFromQuaternion(palmOrientation); PXCMPoint3DF32 rotationEuler = rotationHelper.QueryEulerAngles(); double angleInDegrees = (180 * rotationEuler.y / Math.PI) + 180; Console.WriteLine("Angle in degrees: {0}", angleInDegrees); SendMqttMessage(String.Format("red?{0}", (int)angleInDegrees)); // Console.WriteLine("Rotation x:{0},y:{1},z:{2}", rotationEuler.x, rotationEuler.y, rotationEuler.z); // Querying Hand 3D Position PXCMPoint3DF32 massCenterWorld = hand.QueryMassCenterWorld(); //Console.WriteLine("Hand position on world: {0} | {1} | {2}", massCenterWorld.x, massCenterWorld.y, massCenterWorld.z); /* * // Querying Hand Joints * if (hand.HasTrackedJoints()) * { * foreach (PXCMHandData.JointType jointType in Enum.GetValues(typeof(PXCMHandData.JointType))) * { * PXCMHandData.JointData jointData; * pxcmStatus queryStatus = hand.QueryTrackedJoint(jointType, out jointData); * * if (queryStatus == pxcmStatus.PXCM_STATUS_NO_ERROR && jointData != null) * { * // Printing joint label and tracking confidence * Console.WriteLine("Joint {0} with confidence {1}", jointType, jointData.confidence); * * // Printing the 2D position (image) * Console.WriteLine("\t2D Position: {0} | {1}", jointData.positionImage.x, jointData.positionImage.y); * * // Printing the 3D position (depth) * Console.WriteLine("\t3D Position: {0} | {1} | {2}", jointData.positionWorld.x, jointData.positionWorld.y, jointData.positionWorld.z); * } * } * }*/ } //Console.WriteLine("----------"); //Console.Clear(); } }
private static void ProcessGestures(PXCMHandData handData) { // Processing gestures // Querying how many gestures were detected int firedGesturesNumber = handData.QueryFiredGesturesNumber(); // Querying which gestures were detected for (int i = 0; i < firedGesturesNumber; i++) { PXCMHandData.GestureData gestureData; if (handData.QueryFiredGestureData(i, out gestureData) == pxcmStatus.PXCM_STATUS_NO_ERROR) { // Getting the gesture name String gestureName = gestureData.name; // Getting the gesture state PXCMHandData.GestureStateType gestureState = gestureData.state; // Getting the gesture timestamp long timestamp = gestureData.timeStamp; // Getting the hand information about which hand fired the gesture PXCMHandData.IHand handInfo; if (handData.QueryHandDataById(gestureData.handId, out handInfo) != pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } // Getting which hand fired the gesture PXCMHandData.BodySideType bodySideHand = handInfo.QueryBodySide(); if (gestureState == PXCMHandData.GestureStateType.GESTURE_STATE_START) { Console.WriteLine("Gesture \"{0}\" was detected. State:{1}, Timestamp:{2}, BodySide:{3}", gestureName, gestureState, timestamp, bodySideHand); Console.WriteLine("--------------------"); if (gestureName.CompareTo(GESTURE_FIST) == 0) { if (currentGesture.CompareTo(GESTURE_FIST) != 0) { //SendMqttMessage("surfboard2/relay?0"); String target = (String)iot_form.comboTarget.SelectedItem; String hclosed = (String)iot_form.comboHandsClosed.SelectedItem; //if (target.Equals("")) target = "*"; //SendMqttMessage(target + "/" + hclosed); SendMqttMessage(hclosed); currentGesture = GESTURE_FIST; } } else if (gestureName.CompareTo(GESTURE_SPREADFINGERS) == 0) { if (currentGesture.CompareTo(GESTURE_SPREADFINGERS) != 0) { String target = (String)iot_form.comboTarget.SelectedItem; String hopen = (String)iot_form.comboGive5Action.SelectedItem; //if (target.Equals("")) target = "*"; SendMqttMessage(hopen); //SendMqttMessage(target + "/" + hopen); //System.Diagnostics.Process.Start("http://www.globalcode.com.br"); //SendMqttMessage("surfboard2/relay?1"); currentGesture = GESTURE_SPREADFINGERS; } } else if (gestureName.CompareTo(GESTURE_CLICK) == 0) { if (currentGesture.CompareTo(GESTURE_CLICK) != 0) { SendMqttMessage("green?255"); currentGesture = GESTURE_CLICK; } } else if (gestureName.CompareTo(GESTURE_VSIGN) == 0) { if (currentGesture.CompareTo(GESTURE_VSIGN) != 0) { //System.Diagnostics.Process.Start("https://www.youtube.com/watch?v=MVm5hcQYJ-U"); SendMqttMessage("green?0"); keepLooping = false; currentGesture = GESTURE_VSIGN; } } } } } }