Ejemplo n.º 1
0
    void Start()
    {
        Debug.Log("Start(): Initializing nodes.");

        this.context = new Context(SAMPLE_XML_FILE);
        this.depth   = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
        if (this.depth == null)
        {
            Debug.LogError("Viewer must have a depth node!");
        }
        this.hands = context.FindExistingNode(NodeType.Hands) as HandsGenerator;
        if (this.hands == null)
        {
            Debug.LogError("Viewer must have a hands node!");
        }
        this.gestures = context.FindExistingNode(NodeType.Gesture) as GestureGenerator;
        if (this.gestures == null)
        {
            Debug.LogError("Viewer must have a gestures node!");
        }

        this.hands.HandCreate  += new HandsGenerator.HandCreateHandler(hands_HandCreate);
        this.hands.HandUpdate  += new HandsGenerator.HandUpdateHandler(hands_HandUpdate);
        this.hands.HandDestroy += new HandsGenerator.HandDestroyHandler(hands_HandDestroy);

        this.gestures.AddGesture("Wave");
        this.gestures.AddGesture("RaiseHand");
        this.gestures.GestureRecognized += new GestureGenerator.GestureRecognizedHandler(gestures_GestureRecognized);
        this.gestures.StartGenerating();
    }
Ejemplo n.º 2
0
 /// Initializes the list of gestures (from the current version) if it is not yet initialized.
 /// @return true on success and false if it couldn't initialize.
 protected bool InitGestures()
 {
     if (m_currentVersionGestureList != null)
     {
         return(true); // it is already filled.
     }
     // we either succeed of fail so we do all the calculation in one try-catch block.
     try
     {
         // we need the gesture node. So for that we will create a context and a gesture node on it.
         Context          tmpContext = new Context();
         GestureGenerator gesture    = tmpContext.CreateAnyProductionTree(NodeType.Gesture, null) as GestureGenerator;
         m_currentVersionGestureList = gesture.EnumerateAllGestures(); // hold all legal gestures
         // cleanup
         gesture.Dispose();
         tmpContext.Dispose();
     }
     catch (System.Exception ex)
     {
         Debug.Log("FAILED TO INITIALIZE!. Message=" + ex.Message);
         m_currentVersionGestureList = null;
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        public MainWindow()
        {
            InitializeComponent();
            ViewSwitcher.SetMainWindow(this);
            ViewSwitcher.Switch(mainMenu = new Menu(this));

            gestureGenerator = new GestureGenerator();
            // Listen to recognized gestures
            gestureGenerator.GestureRecognized += gestureGenerator_GestureRecognized;

            this.sensorChooser = new KinectSensorChooser();
            //this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
            this.sensorChooser.KinectChanged        += SensorChooserOnKinectChanged;
            this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
            this.sensorChooser.Start();

            var regionSensorBinding = new Binding("Kinect")
            {
                Source = this.sensorChooser
            };

            BindingOperations.SetBinding(this.kinectRegion, KinectRegion.KinectSensorProperty, regionSensorBinding);

            buttonMinus.MouseEnter += this.volumneChanged;
            buttonPlus.MouseEnter  += this.volumneChanged;
            KinectRegion.AddHandPointerEnterHandler(buttonMinus, this.volumneChanged);
            //KinectRegion.AddHandPointerLeaveHandler(buttonMinus, this.volumneChanged);

            KinectRegion.AddHandPointerEnterHandler(buttonPlus, this.volumneChanged);
            //KinectRegion.AddHandPointerLeaveHandler(buttonPlus, this.volumneChanged);
        }
Ejemplo n.º 4
0
        // 初期化
        private void xnInitialize()
        {
            // コンテキストの初期化
            ScriptNode scriptNode;

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

            // 鏡モード(反転)にしない
            context.GlobalMirror = false;

            // イメージジェネレータの作成
            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);
            }

            // ジェスチャーの登録
            gesture.AddGesture("RaiseHand");

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

            // ハンドジェネレータの作成
            hands = context.FindExistingNode(NodeType.Hands) as HandsGenerator;
            if (depth == null)
            {
                throw new Exception(context.GlobalErrorState);
            }

            // ハンドトラッキング用のコールバックを登録する
            hands.HandCreate  += new EventHandler <HandCreateEventArgs>(hands_HandCreate);
            hands.HandUpdate  += new EventHandler <HandUpdateEventArgs>(hands_HandUpdate);
            hands.HandDestroy += new EventHandler <HandDestroyEventArgs>(hands_HandDestroy);

            // ジェスチャーの検出開始
            context.StartGeneratingAll();
        }
Ejemplo n.º 5
0
        private void CleanUp()
        {
            if (FGestureGenerator != null)
            {
                FGestureGenerator.GestureRecognized -= FGesture_GestureRecognized;
                FGestureGenerator.GestureProgress   -= FGesture_GestureProgress;

                FGestureGenerator.Dispose();
                FGestureGenerator = null;
            }
        }
Ejemplo n.º 6
0
        public bool SetConfig(XmlElement xmlconfig)
        {
            // TO-DO: add some configuration parameters if of any use

            this.context = new Context("NiteKinectConfig.xml");
            this.depth   = context.FindExistingNode(NodeType.Depth) as DepthGenerator;
            if (this.depth == null)
            {
                throw new Exception("Viewer must have a depth node!");
            }

            this.userGenerator           = new UserGenerator(this.context);
            this.userGenerator.NewUser  += userGenerator_NewUser;
            this.userGenerator.LostUser += userGenerator_LostUser;
            //
            this.skeletonCapbility = this.userGenerator.SkeletonCapability;
            this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All);
            this.skeletonCapbility.CalibrationEnd += skeletonCapbility_CalibrationEnd;
            //
            this.poseDetectionCapability = this.userGenerator.PoseDetectionCapability;
            this.calibPose = this.skeletonCapbility.CalibrationPose;
            this.poseDetectionCapability.PoseDetected += poseDetectionCapability_PoseDetected;
            //
            this.handsGenerator              = new HandsGenerator(this.context);
            this.handsGenerator.HandCreate  += handsGenerator_HandCreate;
            this.handsGenerator.HandDestroy += handsGenerator_HandDestroy;
            this.handsGenerator.HandUpdate  += handsGenerator_HandUpdate;
            //
            this.gestureGenerator = new GestureGenerator(this.context);
            this.gestureGenerator.AddGesture("Wave");
            this.gestureGenerator.AddGesture("Click");
            this.gestureGenerator.AddGesture("RaiseHand");
            this.gestureGenerator.GestureRecognized += gestureGenerator_GestureRecognized;
            //
            this.joints = new Dictionary <int, Dictionary <SkeletonJoint, SkeletonJointPosition> >();
            //
            this.userGenerator.StartGenerating();
            this.handsGenerator.StartGenerating();
            this.gestureGenerator.StartGenerating();
            //
            this.histogram = new int[this.depth.DeviceMaxDepth];
            MapOutputMode mapMode = this.depth.MapOutputMode;

            //
            this.bitmap                = new Bitmap((int)mapMode.XRes, (int)mapMode.YRes);
            this.shouldRun             = true;
            this.readerThread          = new Thread(ReaderThread);
            this.readerThread.Priority = ThreadPriority.Lowest;
            this.readerThread.Start();
            //
            return(true);
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
        private KinectHandler()
        {
            SensorChooser = new KinectSensorChooser();
            SensorChooser.KinectChanged += SensorChooserOnKinectChanged;


            SensorChooser.Start();

            KinectGestureGenerator = new GestureGenerator();
            KinectGestureGenerator.GestureRecognized += KinectGestureGenerator_GestureRecognized;
            SensorChooser.Kinect.SkeletonFrameReady  += Kinect_SkeletonFrameReady;

            Webserver = WebSocketsHandler.Instance();

            Webserver.Register(this);
        }
Ejemplo n.º 9
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;
            }
        }