Пример #1
0
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
            ScriptNode scriptNode;

            context = Context.CreateFromXmlFile(CONFIG_XML_PATH, out scriptNode);

            // イメージジェネレータの作成
            image = context.FindExistingNode(NodeType.Image) as ImageGenerator;
            if (image == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // デプスジェネレータの作成
            depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (depth == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // デプスの座標をイメージに合わせる
            depth.AlternativeViewpointCapability.SetViewpoint(image);

            // ジェスチャージェネレータの作成
            gesture = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
            if (depth == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // ジェスチャーの作成と登録
            gestures = gesture.EnumerateAllGestures();
            gesture.AddGesture(gestures[gestureIndex]);
            string[] activeGestures = gesture.GetAllActiveGestures();

            // ジェスチャーの機能確認
            foreach (string name in gestures)
            {
                Trace.WriteLine(name + ":" +
                                "Available:" + gesture.IsGestureAvailable(name) +
                                " ProgressSupported:" + gesture.IsGestureProgressSupported(name));
            }

            // ジェスチャー用のコールバックを登録
            gesture.GestureRecognized += new EventHandler <GestureRecognizedEventArgs>(gesture_GestureRecognized);
            gesture.GestureProgress   += new EventHandler <GestureProgressEventArgs>(gesture_GestureProgress);
            gesture.GestureChanged    += new EventHandler(gesture_GestureChanged);

            // ジェスチャーの検出開始
            context.StartGeneratingAll();
        }
Пример #2
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            if (FContextChanged)
            {
                if (FContextIn.PluginIO.IsConnected)
                {
                    if (FContextIn[0] != null)
                    {
                        try
                        {
                            FGestureGenerator = new GestureGenerator(FContextIn[0]);

                            FGestureGenerator.GestureRecognized += FGesture_GestureRecognized;
                            FGestureGenerator.GestureProgress   += FGesture_GestureProgress;

                            //Write all possible gestures to the Output Pin
                            var gestures = FGestureGenerator.EnumerateAllGestures();
                            EnumManager.UpdateEnum("OpenNIGestures", gestures[0], gestures);

                            FGestureGenerator.StartGenerating();

                            FContextChanged = false;
                        }
                        catch (Exception ex)
                        {
                            FLogger.Log(ex);
                        }
                    }
                }
                else
                {
                    CleanUp();
                    FContextChanged = false;
                }
            }

            if (FActiveGestureIn.IsChanged)
            {
                FUpdateGestures = true;
            }

            if (FGestureGenerator != null)
            {
                if (FEnabledIn.IsChanged)
                {
                    if (FEnabledIn[0])
                    {
                        FGestureGenerator.StartGenerating();
                    }
                    else
                    {
                        FGestureGenerator.StopGenerating();
                    }
                }

                if (FGestureGenerator.IsDataNew)
                {
                    //Check the Incomming gestures and try to add them to the Gesture generator
                    if (FUpdateGestures)
                    {
                        //first remove all active gestures
                        string[] ActiveGesture = FGestureGenerator.GetAllActiveGestures();
                        if (ActiveGesture.Length > 0)
                        {
                            foreach (string Gesture in ActiveGesture)
                            {
                                try
                                {
                                    FGestureGenerator.RemoveGesture(Gesture);
                                }
                                catch (StatusException ex)
                                {
                                    FLogger.Log(LogType.Error, String.Format("Cannot Remove Gesture: {0}", Gesture));
                                    FLogger.Log(LogType.Message, ex.Message);
                                }
                            }
                        }

                        //add all gestures to the Gesture Generator
                        foreach (var gesture in FActiveGestureIn)
                        {
                            try
                            {
                                FGestureGenerator.AddGesture(gesture.Name);
                            }
                            catch (StatusException ex)
                            {
                                FLogger.Log(LogType.Error, String.Format("Cannot Add Gesture: {0}", gesture));
                                FLogger.Log(LogType.Message, ex.Message);
                            }
                        }

                        FUpdateGestures = false;
                    }

                    // Handle the Output Pins
                    FGesturesRegOut.SliceCount     = FGestureRecognized.Count;
                    FGesturePositionOut.SliceCount = FGestureRecognized.Count;
                    int Slice = 0;

                    // Write the received Gestures with their endposition to the output
                    foreach (KeyValuePair <Vector3D, string> item in FGestureRecognized)
                    {
                        FGesturesRegOut[Slice]     = item.Value;
                        FGesturePositionOut[Slice] = item.Key / 1000;
                        Slice++;
                    }

                    FGestureRecognized.Clear();
                }
            }
            else
            {
                FGesturesRegOut.SliceCount     = 0;
                FGesturePositionOut.SliceCount = 0;
            }
        }