//code sample of getting gestures from xtr3d engine. These gestures are defined inside SamplePoses.xml
    private void MyGesturesFrameReady(object sender, GesturesFrameReadyEventArgs e)
    {
        // Opening the received frame
        using (var gesturesFrame = e.OpenFrame() as GesturesFrame)
        {
            if (gesturesFrame != null)
            {
                StringBuilder logLine = new StringBuilder();
                logLine.AppendFormat("Gestures frame: {0}, contains {1} gestures\n", gesturesFrame.FrameKey, gesturesFrame.FirstSkeletonGestures().Length);
                int gestureCounter = 0;
                foreach (BaseGesture gesture in gesturesFrame.FirstSkeletonGestures())
                {
                    string additionalGestureData = "";
                    // Update messages for gesture
                    if (!gestureMessages.ContainsKey(gesture.ID))
                    {
                        gestureMessages.Add(gesture.ID, new GestureMessage(gesture.Description));
                    }
                    gestureMessages[gesture.ID].timeToLiveCounter = gestureTypeToDelay[gesture.Type];
                    switch (gesture.Type)
                    {
                    case BaseGesture.GestureType.HEAD_POSITION:
                    {
                        HeadPositionGesture headPositionGesture = gesture as HeadPositionGesture;
                        gestureMessages[gesture.ID].text = gesture.Description + " " + headPositionGesture.RegionIndex;
                        additionalGestureData            = " (" + headPositionGesture.RegionIndex + ")";
                        break;
                    }

                    case BaseGesture.GestureType.WINGS:
                    {
                        WingsGesture wingsGesture = gesture as WingsGesture;
                        gestureMessages[gesture.ID].text = gesture.Description + " " + wingsGesture.ArmsAngle;
                        additionalGestureData            = " (" + wingsGesture.ArmsAngle + ")";
                        break;
                    }

                    default:
                        break;
                    }
                    logLine.AppendFormat("{0}. Gesture id: {1} -  {2}{3}\n", gestureCounter, gesture.ID, gesture.Description, additionalGestureData);
                    gestureCounter++;
                }
                Debug.Log(logLine);
            }

            // Generate gestures text
            detectedGesturesStreamString = new StringBuilder();
            foreach (int id in gestureMessages.Keys)
            {
                if (gestureMessages[id].timeToLiveCounter > 0)
                {
                    detectedGesturesStreamString.AppendFormat("{0} - {1}\n", id, gestureMessages[id].text);
                    gestureMessages[id].timeToLiveCounter--;
                }
            }
        }
    }
示例#2
0
        private void MyRecognitionFrameReadyEventHandler(object sender, GesturesFrameReadyEventArgs e)
        {
            // Opening the received frame
            using (var gesturesFrame = e.OpenFrame() as GesturesFrame)
            {
                GesturesText.Text = "";
                if (gesturesFrame != null)
                {
                    StringBuilder gesturesString = new StringBuilder();
                    gesturesString.AppendFormat("Gestures frame: {0}, contains {1} gestures",
                                                gesturesFrame.FrameKey.FrameNumberKey, gesturesFrame.FirstSkeletonGestures().Length);
                    Console.WriteLine(gesturesString);
                    int i = 0;
                    foreach (BaseGesture gesture in gesturesFrame.FirstSkeletonGestures())
                    {
                        // Update messages for gesture
                        if (!gestureMessages.ContainsKey(gesture.ID))
                        {
                            gestureMessages.Add(gesture.ID, new GestureMessage(gesture.Description));
                        }
                        gestureMessages[gesture.ID].timeToLiveCounter = gestureTypeToDelay[gesture.Type];
                        switch (gesture.Type)
                        {
                        case BaseGesture.GestureType.HEAD_POSITION:
                        {
                            HeadPositionGesture headPositionGesture = gesture as HeadPositionGesture;
                            gestureMessages[gesture.ID].text = gesture.Description + " (" + headPositionGesture.RegionIndex + ")";
                            break;
                        }

                        case BaseGesture.GestureType.WINGS:
                        {
                            WingsGesture wingsGesture = gesture as WingsGesture;
                            gestureMessages[gesture.ID].text = gesture.Description + " (" + wingsGesture.ArmsAngle + ")";
                            break;
                        }
                        }
                        Console.WriteLine("{0}. Gesture id: {1} - {2}", i, gesture.ID, gestureMessages[gesture.ID].text);//written to console for automatic tests
                        i++;
                    }
                }

                // Generate gestures text
                GesturesText.Text = "";
                foreach (int id in gestureMessages.Keys)
                {
                    if (gestureMessages[id].timeToLiveCounter > 0)
                    {
                        GesturesText.Text += id + " - " + gestureMessages[id].text;
                        GesturesText.Text += "\r\n";
                        gestureMessages[id].timeToLiveCounter--;
                    }
                }
            }
        }