/* 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); } }
/* 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; } else if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { gestureStatusRight += "Right Hand Gesture: " + gestureData.name; } } } 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(); } }
private void ProcessingHandThread() { // 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); // 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; // 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 { gesture = Gesture.Undefined; } // Get alert status for (int i = 0; i < handData.QueryFiredAlertsNumber(); i++) { PXCMHandData.AlertData alertData; if (handData.QueryFiredAlertData(i, out alertData) != pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } //Displaying last alert switch (alertData.label) { case PXCMHandData.AlertType.ALERT_HAND_DETECTED: detectionAlert = "Hand Detected"; detectionStatusOk = true; break; case PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED: detectionAlert = "Hand Not Detected"; detectionStatusOk = false; break; case PXCMHandData.AlertType.ALERT_HAND_CALIBRATED: calibrationAlert = "Hand Calibrated"; calibrationStatusOk = true; break; case PXCMHandData.AlertType.ALERT_HAND_NOT_CALIBRATED: calibrationAlert = "Hand Not Calibrated"; calibrationStatusOk = false; break; case PXCMHandData.AlertType.ALERT_HAND_INSIDE_BORDERS: bordersAlert = "Hand Inside Borders"; borderStatusOk = true; break; case PXCMHandData.AlertType.ALERT_HAND_OUT_OF_BORDERS: bordersAlert = "Hand Out Of Borders"; borderStatusOk = false; break; } } UpdateUI(); if (handData != null) handData.Dispose(); } senseManager.ReleaseFrame(); } }
private void getCursorPositions() { var numHands = mHand.QueryNumberOfHands(); int handId = -1; if (numHands < 1) { mCursor0.transform.localPosition = Vector3.zero; mCursor1.transform.localPosition = Vector3.zero; } if (!UseTwoHands) { mCursor1.transform.localPosition = Vector3.zero; } for (var i = 0; i < numHands; ++i) { mHand.QueryHandId(PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_ID, i, out handId); PXCMHandData.IHand handData; if (mHand.QueryHandDataById(handId, out handData) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { if (handData.HasCursor()) { PXCMHandData.ICursor cursor; if (handData.QueryCursor(out cursor) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { var pos = cursor.QueryPointWorld(); if (MapZ) { var newZ = lmap(pos.z, ZRange.x, ZRange.y, ZRange.z, ZRange.w); pos.z = newZ; } Vector3 newPos = new Vector3(pos.x, pos.y, pos.z) * CursorScale; if (handData.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { mCursor0.transform.localPosition = newPos; if (getGestureState(PXCMHandData.BodySideType.BODY_SIDE_RIGHT)) { mCursor0Active = !mCursor0Active; if (mCursor0Active) { mCursor0.transform.localScale = new Vector3(CursorSize * 3, CursorSize * 3, CursorSize * 3); } else { mCursor0.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize); } } } else if (handData.QueryBodySide() == PXCMHandData.BodySideType.BODY_SIDE_LEFT && UseTwoHands) { mCursor1.transform.localPosition = newPos; if (getGestureState(PXCMHandData.BodySideType.BODY_SIDE_LEFT)) { mCursor1Active = !mCursor1Active; if (mCursor1Active) { mCursor1.transform.localScale = new Vector3(CursorSize * 3, CursorSize * 3, CursorSize * 3); } else { mCursor1.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize); } } } } } else { if (i == 0) { mCursor0.transform.localPosition = Vector3.zero; } else if (i == 1) { mCursor1.transform.localPosition = Vector3.zero; } } } } }
/* Displaying current frame gestures */ private int DisplayGesture(PXCMHandData handAnalysis) { int firedGesturesNumber = handAnalysis.QueryFiredGesturesNumber(); string gestureStatusLeft = string.Empty; string gestureStatusRight = string.Empty; if (firedGesturesNumber == 0) { return -1; } 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 -1; PXCMHandData.BodySideType bodySideType = handData.QueryBodySide(); if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_LEFT) { gestureStatusLeft += gestureData.name; } else if (bodySideType == PXCMHandData.BodySideType.BODY_SIDE_RIGHT) { gestureStatusRight += gestureData.name; } } } int value = -1; if (gestureStatusLeft == "spreadfingers" && gestureStatusRight == "spreadfingers") { value = 0; } else if (gestureStatusLeft == "spreadfingers" && gestureStatusRight == "fist") { value = 1; } else if (gestureStatusLeft == "fist" && gestureStatusRight == "spreadfingers") { value = 2; } else if (gestureStatusLeft == "fist" && gestureStatusRight == "fist") { value = 3; } if (value != -1) { //form.UpdateInfo("Gesture: " + value + "\n", Color.SeaGreen); return value; } return -1; }
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("surfboard2/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("servo?{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; } } } } } }
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; } } } } } }
// 手のデータを更新する private void UpdateHandFrame() { // 手のデータを更新する handData.Update(); // データを初期化する CanvasHandParts.Children.Clear(); // 検出した手の数を取得する var numOfHands = handData.QueryNumberOfHands(); for (int i = 0; i < numOfHands; i++) { // 手を取得する PXCMHandData.IHand hand; var sts = handData.QueryHandData( PXCMHandData.AccessOrderType.ACCESS_ORDER_BY_ID, i, out hand); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } // 指の関節を列挙する for (int j = 0; j < PXCMHandData.NUMBER_OF_JOINTS; j++) { PXCMHandData.JointData jointData; sts = hand.QueryTrackedJoint((PXCMHandData.JointType)j, out jointData); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } AddEllipse(CanvasHandParts, new Point(jointData.positionImage.x, jointData.positionImage.y), 5, Brushes.Green); } } // 認識したジェスチャーの数を取得する var numOfGestures = handData.QueryFiredGesturesNumber(); for (int i = 0; i < numOfGestures; i++) { // 認識したジェスチャーを取得する PXCMHandData.GestureData gesture; var sts = handData.QueryFiredGestureData(i, out gesture); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } // ジェスチャーをした手を取得する PXCMHandData.IHand hand; sts = handData.QueryHandDataById(gesture.handId, out hand); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { continue; } // どちらの手でジェスチャーしたのか var side = hand.QueryBodySide(); if (side == PXCMHandData.BodySideType.BODY_SIDE_LEFT) { ++leftGestureCount; } else { ++rightGestureCount; } } TextLeftGesture.Text = string.Format("Left gesture : {0}", leftGestureCount); TextRightGesture.Text = string.Format("Right gesture : {0}", rightGestureCount); }