// Use this for initialization
    void Start()
    {
        rotationType = RotationType.Pinch;

        //sm = PXCMSession.CreateInstance();
        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm != null)
        {
            /* Enable hand tracking and configure the hand module */
            pxcmStatus sts = sm.EnableHand();
            if (sts == pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                /* Hand module interface instance */
                hand = sm.QueryHand();
                /* Hand data interface instance */
                hand_data = hand.CreateOutput();

                // Create hand configuration instance and configure
                hcfg = hand.CreateActiveConfiguration();
                hcfg.EnableAllAlerts();
                hcfg.SubscribeAlert(OnFiredAlert);
                hcfg.EnableNormalizedJoints(true);
                hcfg.ApplyChanges();
                hcfg.Dispose();

                /* Initialize the execution pipeline */
                if (sm.Init() != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    OnDisable();
                }
            }
        }
    }
Beispiel #2
0
	private int weightsNum = 15; //smoothing factor

	// Use this for initialization
	void Start () {
		hands = new HandsModel ();
		MaxHands = hands.MaxHands;
		MaxJoints = hands.MaxJoints;
		handList = new Hashtable ();

		senseManager = PXCMSenseManager.CreateInstance ();
		if (senseManager == null)
			Debug.LogError ("SenseManager Initialization Failed");
		
		/* Enable hand tracking and retrieve an hand module instance to configure */
		status = senseManager.EnableHand ();
		handAnalyzer = senseManager.QueryHand ();
		if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
			Debug.LogError ("PXCSenseManager.EnableHand: " + status);
		
		/* Initialize the execution pipeline */
		status = senseManager.Init ();
		if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
			Debug.LogError ("PXCSenseManager.Init: " + status);

		/* Retrieve the the DataSmoothing instance */
		senseManager.QuerySession ().CreateImpl<PXCMDataSmoothing> (out dataSmoothing);
		smoother3D = new PXCMDataSmoothing.Smoother3D[MaxHands][];

		/* Configure a hand - Enable Gestures and Alerts */
		PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration ();
		hcfg.EnableAllGestures ();
		hcfg.EnableAlert (PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
		hcfg.ApplyChanges ();
		hcfg.Dispose ();

		InitObject ();
	}
Beispiel #3
0
        private void startCamera()
        {
            session = PXCMSession.CreateInstance();
            manager = session.CreateSenseManager();

            if (manager == null)
            {
                Console.WriteLine("Failed");
            }
            manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 30);
            manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 60);
            manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480, 60);
            manager.EnableHand();

            PXCMHandConfiguration config = manager.QueryHand().CreateActiveConfiguration();

            config.EnableAllAlerts();
            config.EnableSegmentationImage(true);
            config.EnableTrackedJoints(true);
            config.LoadGesturePack("navigation");
            config.EnableAllGestures(true);

            config.ApplyChanges();
            config.Dispose();

            manager.Init();

            thread = new Thread(new ThreadStart(updateThread));
            thread.Start();
        }
        public MainWindow()
        {
            InitializeComponent();
            handWaving  = false;
            handTrigger = false;
            msgTimer    = 0;

            //Instantiate and initialize the SenseManager
            senseManager = PXCMSenseManager.CreateInstance();
            senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30);
            senseManager.EnableHand();
            senseManager.Init();

            //Configure the Hand Module
            hand       = senseManager.QueryHand();
            handConfig = hand.CreateActiveConfiguration();
            handConfig.EnableGesture("v_sign");
            handConfig.EnableAllAlerts();
            handConfig.ApplyChanges();



            // Start the worker thread
            processingThread = new Thread(new ThreadStart(ProcessingThread));
            processingThread.Start();
        }
        public MainWindow()
        {
            InitializeComponent();

            _senseManager = PXCMSenseManager.CreateInstance();

            _senseManager.EnableHand();

            var handManager = _senseManager.QueryHand();

            _handConfig = handManager.CreateActiveConfiguration();
            _handConfig.EnableGesture("thumb_up");
            _handConfig.EnableGesture("thumb_down");
            //_handConfig.EnableGesture("fist");
            //_handConfig.EnableGesture("spreadfingers");
            _handConfig.EnableAllAlerts();
            _handConfig.ApplyChanges();

            var status = _senseManager.Init();

            if (status >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                _cancellationTokenSource = new CancellationTokenSource();
                _task = Task.Factory.StartNew(x => ProcessInput(_cancellationTokenSource.Token),
                                              TaskCreationOptions.LongRunning,
                                              _cancellationTokenSource.Token);
            }
        }
        public override void Start()
        {
            _cancellationToken = new CancellationTokenSource();
            _manager.EnableEmotion();
            _manager.EnableFace();

            using (var faceModule = _manager.QueryFace()) {
                using (var moduleConfiguration = faceModule.CreateActiveConfiguration()) {
                    moduleConfiguration.detection.maxTrackedFaces = 1;
                    var expressionCofig = moduleConfiguration.QueryExpressions();
                    expressionCofig.Enable();
                    expressionCofig.EnableAllExpressions();

                    var desc = new PXCMFaceConfiguration.RecognitionConfiguration.RecognitionStorageDesc();
                    desc.maxUsers     = 10;
                    desc.isPersistent = true;
                    var recognitionConfiguration = moduleConfiguration.QueryRecognition();
                    recognitionConfiguration.CreateStorage(StorageName, out desc);
                    recognitionConfiguration.UseStorage(StorageName);
                    recognitionConfiguration.SetRegistrationMode(PXCMFaceConfiguration.RecognitionConfiguration.RecognitionRegistrationMode.REGISTRATION_MODE_CONTINUOUS);

                    if (File.Exists(StorageFileName))
                    {
                        var bytes = File.ReadAllBytes(StorageFileName);
                        recognitionConfiguration.SetDatabaseBuffer(bytes);
                    }
                    recognitionConfiguration.Enable();
                    moduleConfiguration.ApplyChanges();
                }
            }

            _manager.EnableHand();
            using (var handModule = _manager.QueryHand()) {
                using (var handConfig = handModule.CreateActiveConfiguration()) {
                    //handConfig.EnableAllAlerts();
                    int numGestures = handConfig.QueryGesturesTotalNumber();
                    for (int i = 0; i < numGestures; i++)
                    {
                        string name;
                        handConfig.QueryGestureNameByIndex(i, out name);
                        Debug.WriteLine("Gestures: " + name);
                    }
                    handConfig.EnableAllGestures();
                    handConfig.SubscribeGesture(OnGesture);
                    handConfig.EnableTrackedJoints(true);
                    handConfig.ApplyChanges();
                }
            }
            Debug.WriteLine("Initializing Camera...");

            var status = _manager.Init();

            if (status != NoError)
            {
                throw new CameraException(status.ToString());
            }
            Task.Factory.StartNew(Loop,
                                  TaskCreationOptions.LongRunning,
                                  _cancellationToken.Token);
        }
Beispiel #7
0
        //RealSenseメソッド-------------------------------------------------------------------

        /// <summary> 機能の初期化 </summary>
        private bool InitializeRealSense()
        {
            try
            {
                //SenseManagerを生成
                senseManager = PXCMSenseManager.CreateInstance();

                //カラーストリームの有効
                var sts = senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, COLOR_WIDTH, COLOR_HEIGHT, COLOR_FPS);
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("Colorストリームの有効化に失敗しました");
                }

                // Depthストリームを有効にする
                sts = senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,
                                                DEPTH_WIDTH, DEPTH_HEIGHT, DEPTH_FPS);
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("Depthストリームの有効化に失敗しました");
                }

                // 手の検出を有効にする
                sts = senseManager.EnableHand();

                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("手の検出の有効化に失敗しました");
                }

                //パイプラインを初期化する
                //(インスタンスはInit()が正常終了した後作成されるので,機能に対する各種設定はInit()呼び出し後となる)
                sts = senseManager.Init();
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("パイプラインの初期化に失敗しました");
                }

                //ミラー表示にする
                senseManager.QueryCaptureManager().QueryDevice().SetMirrorMode(
                    PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL);

                //デバイスを取得する
                device = senseManager.captureManager.device;

                //座標変換オブジェクトを作成
                projection = device.CreateProjection();

                // 手の検出の初期化
                InitializeHandTracking();

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
        }
Beispiel #8
0
        // Initialise all the things
        public override void Init(PXCMSenseManager sManager)
        {
            senseManager = sManager;
            senseManager.EnableHand();
            module = senseManager.QueryHand();
            PXCMHandConfiguration config = module.CreateActiveConfiguration();

            config.SetTrackingMode(PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND);
            config.ApplyChanges();
            config.Update();
        }
        private void Initialize()
        {
            try {
                // SenseManagerを生成する
                senseManager = PXCMSenseManager.CreateInstance();

                // カラーストリームを有効にする
                var sts = senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,
                                                    COLOR_WIDTH, COLOR_HEIGHT, COLOR_FPS);
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("カラーストリームの有効化に失敗しました");
                }

                // Depthストリームを有効にする
                sts = senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,
                                                DEPTH_WIDTH, DEPTH_HEIGHT, DEPTH_FPS);
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("Depthストリームの有効化に失敗しました");
                }

                // 手の検出を有効にする
                sts = senseManager.EnableHand();
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("手の検出の有効化に失敗しました");
                }

                // パイプラインを初期化する
                sts = senseManager.Init();
                if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    throw new Exception("初期化に失敗しました");
                }

                // デバイスを取得する
                var device = senseManager.QueryCaptureManager().QueryDevice();

                // ミラー表示にする
                device.SetMirrorMode(
                    PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL);

                // 座標変換オブジェクトを作成
                projection = device.CreateProjection();

                // 手の検出の初期化
                InitializeHandTracking();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
                Close();
            }
        }
        // Use this for initialization
        void Start()
        {
            // Creates an instance of the sense manager to be called later
            session = PXCMSenseManager.CreateInstance();

            //Output an error if there is no instance of the sense manager
            if (session == null)
            {
                Debug.LogError("SenseManager Init Failed!");
            }

            // Enables hand tracking
            sts = session.EnableHand();
            handAnalyzer = session.QueryHand();

            sts2 = session.EnableFace();
            faceAnalyzer = session.QueryFace();

            if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
                Debug.LogError("PXCSenseManager.EnableHand: " + sts);

            if (sts2 != pxcmStatus.PXCM_STATUS_NO_ERROR)
                Debug.LogError("PXCSenseManager.EnableFace: " + sts2);

            // Creates the session
            sts = session.Init();

            sts2 = session.Init();

            if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
                Debug.LogError("PXCSenseManager.Init: " + sts);

            if (sts2 != pxcmStatus.PXCM_STATUS_NO_ERROR)
                Debug.LogError("PXCSenseManager.Init: " + sts2);

            // Creates a hand config for future data
            PXCMHandConfiguration handconfig = handAnalyzer.CreateActiveConfiguration();

            PXCMFaceConfiguration faceconfig = faceAnalyzer.CreateActiveConfiguration();

            //If there is handconfig instance
            if (handconfig != null)
            {
                handconfig.EnableAllAlerts();
                handconfig.ApplyChanges();
                handconfig.Dispose();
            }
            if (faceconfig != null)
            {
                faceconfig.EnableAllAlerts();
                faceconfig.ApplyChanges();
                faceconfig.Dispose();
            }
        }
Beispiel #11
0
 public void Init()
 {
     var session = PXCMSession.CreateInstance();
     _manager = session.CreateSenseManager();
     _manager.EnableHand();
     var status = _manager.Init();
     if (status != NoError) {
         throw new Exception(status.ToString());
     }
     Task.Factory.StartNew(Loop,
         TaskCreationOptions.LongRunning);
 }
Beispiel #12
0
        private void StartRealSense()
        {
            bool useHead = bool.Parse(ConfigurationManager.AppSettings["UseHead"]);

            // Instantiate and initialize the SenseManager
            senseManager = PXCMSenseManager.CreateInstance();

            // Configure the Hand Module
            if (useHead)
            {
                senseManager.EnableFace();

                face       = senseManager.QueryFace();
                faceConfig = face.CreateActiveConfiguration();
                faceConfig.detection.isEnabled = true;
                faceConfig.QueryExpressions().Enable();

                faceConfig.ApplyChanges();
            }
            else
            {
                // Enable cursor tracking
                senseManager.EnableHand();

                // Get an instance of the hand cursor module
                hand = senseManager.QueryHand();

                // Get an instance of the cursor configuration
                var cursorConfig = hand.CreateActiveConfiguration();

                // Make configuration changes and apply them
                cursorConfig.DisableAllAlerts();
                cursorConfig.EnableTrackedJoints(true);
                cursorConfig.EnableStabilizer(true);
                cursorConfig.ApplyChanges();
            }

            senseManager.Init();

            // Create an instance of PXCMSmoother
            senseManager.session.CreateImpl <PXCMSmoother>(out smoother);
            smoother2D  = smoother.Create2DQuadratic(.5F);
            smoother2D2 = smoother.Create2DQuadratic(1);

            // Start the worker thread
            processingThread = new Thread(new ThreadStart(ProcessingThread));
            processingThread.Start();
        }
        public HandsRecognition(int mod)
        {
			try
			{
				session = PXCMSession.CreateInstance();
				mode = mod;
				if (mod == 0)
				{
					rightcp = new checkPiano();
					leftcp = new checkPiano();
				}
				else if (mod == 1)
				{
					rightcp = new checkDrum();
					leftcp = new checkDrum();
				}

				_disconnected = false;

				instance = session.CreateSenseManager();
				if (instance == null)
				{
					MessageBox.Show("Failed creating SenseManager", "OnAlert");
					return;
				}

				/* Set Module */
				pxcmStatus status = instance.EnableHand();//form.GetCheckedModule());
				handAnalysis = instance.QueryHand();

				if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null)
				{
					MessageBox.Show("Failed Loading Module", "OnAlert");
					return;
				}

				handler = new PXCMSenseManager.Handler();
				handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame);

				handData = handAnalysis.CreateOutput();
			}
			catch
			{
				MessageBox.Show("Init Failed.");
				Environment.Exit(0);
			}
        }
Beispiel #14
0
    void Start()
    {
        // Initialise a PXCMSenseManager instance
        psm = PXCMSenseManager.CreateInstance();
        if (psm == null)
        {
            Debug.LogError("SenseManager Init Failed");
            return;
        }

        // Enable the depth and colour streams
        psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
        psm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480);

        // Enable hand analysis
        pxcmStatus sts = psm.EnableHand();

        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager Hand Init Failed");
            OnDisable();
            return;
        }
        handModule = psm.QueryHand();

        // Initialise the execution pipeline
        sts = psm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager Pipeline Init Failed");
            OnDisable();
            return;
        }

        handData = handModule.CreateOutput();

        handConfig = handModule.CreateActiveConfiguration();
        handConfig.EnableAllGestures();
        handConfig.ApplyChanges();

        foreach (CapsuleCollider capsule in GetComponentsInChildren <CapsuleCollider>())
        {
            hands.Add(capsule.gameObject);
        }

        mainCamera = GetComponentInChildren <Camera>();
    }
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands][];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        InitializeGameobjects();
    }
Beispiel #16
0
        public Form1(PXCMSession session)
        {
            InitializeComponent();

            //_timer = null;

            thread = new MyBeautifulThread(DoRecognition);
            flagThread = 0;

            LightState = 0;
            flagLight = 0;
            WindState = 0;
            flagWind = 0;
            SendState = 0;

            sm = PXCMSenseManager.CreateInstance();
            sm.EnableHand();
            PXCMHandModule hand = sm.QueryHand();
            sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 320, 240, 60);
            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler
            {
                onModuleProcessedFrame = OnModuleProcessedFrame
            };

            sm.Init(handler);

            PXCMHandConfiguration handConfiguration = sm.QueryHand().CreateActiveConfiguration();
            handConfiguration.EnableGesture("wave");
            handConfiguration.EnableGesture("swipe_up");
            handConfiguration.EnableGesture("thumb_up");
            handConfiguration.EnableGesture("tap");
            handConfiguration.ApplyChanges();

            if (handConfiguration == null)
            {
                Console.WriteLine("Failed Create Configuration");
                Console.WriteLine("That`s all...");
                Console.ReadKey();
            }
            logTextBox.Text = DateTime.Now.ToString("hh:mm:ss") + " Started" + "\n" + logTextBox.Text;
        }
Beispiel #17
0
        public Form1()
        {
            InitializeComponent();
            vol = new float[6] { 1F, 1F, 0F, 1F, 0.5F, 0F };
            textVolume.Text = vol[3].ToString();
            textSpeed.Text = vol[0].ToString();
            textPanorama.Text = vol[4].ToString();
            thread = new System.Threading.Thread(DoRecognition);
            flag = 0;
            oscManager1 = new OscManager();
            oscManager1.DestIP = "127.0.0.1";

            // Create the SenseManager instance
            sm = PXCMSenseManager.CreateInstance();
            // Enable hand tracking
            sm.EnableHand();
            // Get a hand instance here for configuration
            PXCMHandModule hand = sm.QueryHand();
            // Initialize and stream data.
            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler
            {
                onModuleProcessedFrame = OnModuleProcessedFrame
            };
            sm.Init(handler);

            PXCMHandConfiguration handConfiguration = sm.QueryHand().CreateActiveConfiguration();
            handConfiguration.EnableGesture("thumb_down");
            handConfiguration.EnableGesture("thumb_up");
            handConfiguration.EnableGesture("v_sign");
            handConfiguration.EnableGesture("spreadfingers");
            handConfiguration.EnableGesture("fist");
            handConfiguration.EnableGesture("full_pinch");
            handConfiguration.ApplyChanges();
            if (handConfiguration == null)
            {
                Console.WriteLine("Failed Create Configuration");
                Console.WriteLine("That`s all...");
                Console.ReadKey();
            }
            logTextBox.Text = DateTime.Now.ToString("hh:mm:ss") + " Started" + "\n" + logTextBox.Text;
        }
        public MainWindow()
        {
            InitializeComponent();

            // Instantiate and initialize the SenseManager
            _senseManager = PXCMSenseManager.CreateInstance();
            _senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30);
            _senseManager.EnableHand();
            _senseManager.Init();

            // Configure the Hand Module
            _hand       = _senseManager.QueryHand();
            _handConfig = _hand.CreateActiveConfiguration();
            _handConfig.EnableGesture("wave");
            _handConfig.EnableAllAlerts();
            _handConfig.ApplyChanges();

            // Start the worker thread
            _processingThread = new Thread(new ThreadStart(ProcessingThread));
            _processingThread.Start();
        }
 public override void Listen()
 {
     // attach the controller to the PXCM sensor
     _senseManager = Session.CreateSenseManager();      
     _senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30);
     _senseManager.EnableHand();
     _handModule = _senseManager.QueryHand();
     _handData = _handModule.CreateOutput();
     _handConfiguration = _handModule.CreateActiveConfiguration();
     _handConfiguration.SubscribeGesture(_handGestureHandler);
     _handConfiguration.SubscribeAlert(_handAlertHandler);
     _handConfiguration.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_TRACKED);
     _handConfiguration.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_CALIBRATED);
     _handConfiguration.EnableGesture("full_pinch");
     _handConfiguration.EnableGesture("thumb_up");
     _handConfiguration.ApplyChanges();
     _senseManager.Init(_handler);
     sensorActive = true;
     _senseManager.StreamFrames(true);
     _senseManager.Close();           
     }
Beispiel #20
0
        public Model()
        {
            width        = 640;
            height       = 480;
            framerate    = 30;
            senseManager = PXCMSenseManager.CreateInstance();
            senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, width, height, framerate);
            // Enable Face detection
            senseManager.EnableFace();
            senseManager.EnableHand();
            senseManager.Init();

            face       = senseManager.QueryFace();
            faceConfig = face.CreateActiveConfiguration();
            faceConfig.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR);
            faceConfig.detection.isEnabled = true;
            faceConfig.QueryExpressions();
            PXCMFaceConfiguration.ExpressionsConfiguration expc = faceConfig.QueryExpressions();
            expc.Enable();
            expc.EnableAllExpressions();
            faceConfig.ApplyChanges();
            faceConfig.Update();

            //faceData = face.CreateOutput();
            //faceData.Update();

            hand = senseManager.QueryHand();
            PXCMHandConfiguration config = hand.CreateActiveConfiguration();

            config.SetTrackingMode(PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND);
            config.ApplyChanges();
            config.Update();
            //handData = hand.CreateOutput();
            //handData.Update();

            modules = new List <RSModule>();
        }
        private void Initialize()
        {
            try {
                // SenseManagerを生成する
                senseManager = PXCMSenseManager.CreateInstance();

                // Depthストリームを有効にする
                var sts = senseManager.EnableStream( PXCMCapture.StreamType.STREAM_TYPE_DEPTH,
                    DEPTH_WIDTH, DEPTH_HEIGHT, DEPTH_FPS );
                if ( sts < pxcmStatus.PXCM_STATUS_NO_ERROR ) {
                    throw new Exception( "Depthストリームの有効化に失敗しました" );
                }

                // 手の検出を有効にする
                sts = senseManager.EnableHand();
                if ( sts < pxcmStatus.PXCM_STATUS_NO_ERROR ) {
                    throw new Exception( "手の検出の有効化に失敗しました" );
                }

                // パイプラインを初期化する
                sts = senseManager.Init();
                if ( sts < pxcmStatus.PXCM_STATUS_NO_ERROR ) {
                    throw new Exception( "初期化に失敗しました" );
                }

                // ミラー表示にする
                senseManager.QueryCaptureManager().QueryDevice().SetMirrorMode(
                    PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL );

                // 手の検出の初期化
                InitializeHandTracking();
            }
            catch ( Exception ex ) {
                MessageBox.Show( ex.Message );
                Close();
            }
        }
    // Use this for initialization
    void Start()
    {
        // Set up the reference to the aeroplane controller.
        m_Aeroplane = GetComponent <AeroplaneController>();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm != null)
        {
            /* Enable hand tracking and configure the hand module */
            pxcmStatus sts = sm.EnableHand();
            if (sts == pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                /*init hand data structure*/
                handData = new PXCMHandData.IHand[2];

                /* Hand module interface instance */
                hand = sm.QueryHand();
                /* Hand data interface instance */
                hand_data = hand.CreateOutput();

                // Create hand configuration instance and configure
                hcfg = hand.CreateActiveConfiguration();
                hcfg.EnableAllAlerts();
                hcfg.SubscribeAlert(OnFiredAlert);
                hcfg.EnableNormalizedJoints(true);
                hcfg.ApplyChanges();
                hcfg.Dispose();

                /* Initialize the execution pipeline */
                if (sm.Init() != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    OnDisable();
                }
            }
        }
    }
		public MainWindow()
		{
			InitializeComponent();
			
			_senseManager = PXCMSenseManager.CreateInstance();

			_senseManager.EnableHand();

			var handManager = _senseManager.QueryHand();
			_handConfig = handManager.CreateActiveConfiguration();
			_handConfig.EnableGesture("thumb_up");
			_handConfig.EnableGesture("thumb_down");
			_handConfig.EnableAllAlerts();
			_handConfig.ApplyChanges();

			var status = _senseManager.Init();
			if (status >= pxcmStatus.PXCM_STATUS_NO_ERROR)
			{
				_cancellationTokenSource = new CancellationTokenSource();
				_task = Task.Factory.StartNew(x => ProcessInput(_cancellationTokenSource.Token), 
					TaskCreationOptions.LongRunning,
					_cancellationTokenSource.Token);
			}
		}
        public MainWindow()
        {
            InitializeComponent();

            //set the current date and time
            currentDateTime = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            //set total timer count to 0 and init vars
            highPerformanceTimer = new HiPerfTimer();
            totalHighPerfTimeElapsed = 0;
            numLinesWritten = 0; //set the total number of lines written to 0 so we can track when to start the timer

            //init pipe stuff
            pipeClient = new MyClient(PIPE_NAME);
            pipeClient.SendMessage("I Am Intel RealSense");

            //Debug.WriteLine("Server Ready");

            //initialise combobox
            populateComboBox();
            //init the exprToDisplay global var
            exprToDisplay = "";

            //Work on the file

            //create paths
            string dirToCreate = "data";
            string dirToCreateFull = System.IO.Path.GetFullPath(dirToCreate);
            Directory.CreateDirectory(dirToCreateFull);

            dirToCreate = "video";
            dirToCreateFull = System.IO.Path.GetFullPath(dirToCreate);
            Directory.CreateDirectory(dirToCreateFull);

            //create the csv file to write to
            file = new StreamWriter("data/" + currentDateTime + "data" + ".csv");

            //initialise global expressions array - faster to add the keys here?
            var enumListMain = Enum.GetNames(typeof(PXCMFaceData.ExpressionsData.FaceExpression));
            exprTable = new Hashtable();
            string initLine = "";

            //Add the column schema

            //Initial line: timestamp and high prec time
            initLine += "TIMESTAMP,HIGH_PRECISION_TIME_FROM_START,STIMCODE";

            //add all the expression data columns
            for (int i = 0; i < enumListMain.Length; i++)
            {
                exprTable.Add(enumListMain[i], 0);
                initLine += "," + enumListMain[i];

            }

            //add the bounding rectangle column
            initLine += "," + "BOUNDING_RECTANGLE_HEIGHT" + "," + "BOUNDING_RECTANGLE_WIDTH" + "," + "BOUNDING_RECTANGLE_X" + "," + "BOUNDING_RECTANGLE_Y";
            //add the average depth column
            initLine += "," + "AVERAGE_DEPTH";
            //add landmark points column
            for (int i = 0; i < LANDMARK_POINTS_TOTAL; i++)
            {
                initLine += "," + "LANDMARK_" + i + "_X";
                initLine += "," + "LANDMARK_" + i + "_Y";
            }
            //add euler angles columns
            initLine += "," + "EULER_ANGLE_PITCH" + "," + "EULER_ANGLE_ROLL" + "," + "EULER_ANGLE_YAW";
            initLine += "," + "QUATERNION_W" + "," + "QUATERNION_X" + "," + "QUATERNION_Y" + "," + "QUATERNION_Z";

            //write the initial row to the file
            file.WriteLine(initLine);

            //configure the camera mode selection box
            cbCameraMode.Items.Add("Color");
            cbCameraMode.Items.Add("IR");
            cbCameraMode.Items.Add("Depth");
            //configure initial camera mode
            cameraMode = "Color";

            //initialise global vars

            numFacesDetected = 0;

            handWaving = false;
            handTrigger = false;
            handResetTimer = 0;

            lEyeClosedIntensity = 0;
            lEyeClosed = false;
            lEyeClosedTrigger = false;
            lEyeClosedResetTimer = 0;

            rEyeClosed = false;
            rEyeClosedTrigger = false;
            rEyeClosedResetTimer = 0;
            rEyeClosedIntensity = 0;

            emotionEvidence = 0;

            blinkTrigger = false;
            blinkResetTimer = 0;

            //global fps vars
            prevTime = 0;
            stopwatch = new Stopwatch();

            // Instantiate and initialize the SenseManager
            senseManager = PXCMSenseManager.CreateInstance();
            if (senseManager == null)
            {
                MessageBox.Show("Cannot initialise sense manager: closing in 20s, report to Sriram");
                Thread.Sleep(20000);
                Environment.Exit(1);
            }

            //capture samples
            senseManager.captureManager.SetFileName("video/" + currentDateTime + ".raw", true);
            //Enable color stream
            senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, STREAM_WIDTH, STREAM_HEIGHT, STREAM_FPS);
            senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, STREAM_WIDTH, STREAM_HEIGHT, STREAM_FPS);
            senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, STREAM_WIDTH, STREAM_HEIGHT, STREAM_FPS);
            //Enable face and hand tracking AND EMOTION TRACKING
            senseManager.EnableHand();
            senseManager.EnableFace();
            senseManager.EnableEmotion();

            //Initialise the senseManager - begin collecting data
            senseManager.Init();

            // Configure the Hand Module
            hand = senseManager.QueryHand();
            handConfig = hand.CreateActiveConfiguration();
            handConfig.EnableGesture("wave");
            handConfig.EnableAllAlerts();
            handConfig.ApplyChanges();

            //Configure the Face Module
            face = senseManager.QueryFace();
            faceConfig = face.CreateActiveConfiguration();
            faceConfig.EnableAllAlerts();
            faceConfig.detection.isEnabled = true; //enables querydetection function to retrieve face loc data
            faceConfig.detection.maxTrackedFaces = 1; //MAXIMUM TRACKING - 1 FACE
            faceConfig.ApplyChanges();
            //Configure the sub-face-module Expressions
            exprConfig = faceConfig.QueryExpressions();
            exprConfig.Enable();
            exprConfig.EnableAllExpressions();
            faceConfig.ApplyChanges();

            // Start the worker thread that processes the captured data in real-time
            processingThread = new Thread(new ThreadStart(ProcessingThread));
            processingThread.Start();
        }
Beispiel #25
0
        void OnEnable()
        {
            Initialized = false;

            /* Create a SenseManager instance */
            SenseManager = PXCMSenseManager.CreateInstance();

            if (SenseManager == null)
            {
                print("Unable to create the pipeline instance");
                return;
            }

            if (_speechCommandsRef.Count != 0)
            {
                SetSenseOption(SenseOption.SenseOptionID.Speech);
            }

            int numberOfEnabledModalities = 0;

            //Set mode according to RunMode - play from file / record / live stream
            if (RunMode == MCTTypes.RunModes.PlayFromFile)
            {
                //CHECK IF FILE EXISTS
                if (!System.IO.File.Exists(FilePath))
                {
                    Debug.LogWarning("No Filepath Set Or File Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, false);
                    Debug.Log("SenseToolkitManager: Playing from file: " + FilePath);
                }
            }

            if (RunMode == MCTTypes.RunModes.RecordToFile)
            {
                //CHECK IF PATH
                string PathOnly = FilePath;
                while (!PathOnly[PathOnly.Length - 1].Equals('\\'))
                {
                    PathOnly = PathOnly.Remove(PathOnly.Length - 1, 1);
                }

                if (!System.IO.Directory.Exists(PathOnly))
                {
                    Debug.LogWarning("No Filepath Set Or Path Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, true);
                    Debug.Log("SenseToolkitManager: Recording to file: " + FilePath);
                }
            }

            /* Enable modalities according to the set options*/
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                SenseManager.EnableFace();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Enabled     = true;
                SetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                _sts = SenseManager.EnableHand();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                _sts = SenseManager.EnableTracker();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                if (!SpeechManager.IsInitialized)
                {
                    if (SpeechManager.InitalizeSpeech())
                    {
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                        numberOfEnabledModalities++;
                    }
                    else
                    {
                        UnsetSenseOption(SenseOption.SenseOptionID.Speech);
                    }
                }
                else
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                    numberOfEnabledModalities++;
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoDepthStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoIRStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoColorStream, true))
            {
                //SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Enabled     = true;
                numberOfEnabledModalities++;
            }


            /* Initialize the execution */
            _sts = SenseManager.Init();
            if (_sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                if (numberOfEnabledModalities > 0)
                {
                    print("Unable to initialize all modalities");
                }
                return;
            }
            //Set different configurations:

            //SenseManager.QueryCaptureManager().device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED);

            // Face
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                var faceModule        = SenseManager.QueryFace();
                var faceConfiguration = faceModule.CreateActiveConfiguration();
                if (faceConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                faceConfiguration.Update();

                faceConfiguration.detection.isEnabled      = true;
                faceConfiguration.detection.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.landmarks.isEnabled      = true;
                faceConfiguration.landmarks.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.pose.isEnabled      = true;
                faceConfiguration.pose.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.DisableAllAlerts();

                faceConfiguration.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_APPEARANCE_TIME;

                faceConfiguration.detection.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.landmarks.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.pose.maxTrackedFaces      = NumberOfDetectedFaces;

                PXCMFaceConfiguration.ExpressionsConfiguration expressionConfig = faceConfiguration.QueryExpressions();
                expressionConfig.Enable();
                expressionConfig.EnableAllExpressions();


                faceConfiguration.ApplyChanges();
                faceConfiguration.Dispose();

                FaceModuleOutput = faceModule.CreateOutput();

                UnsetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
            }

            // Hand
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                PXCMHandModule handAnalysis = SenseManager.QueryHand();

                PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
                if (handConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                handConfiguration.Update();
                handConfiguration.EnableAllGestures();
                handConfiguration.EnableAllAlerts();
                handConfiguration.EnableSegmentationImage(true);
                handConfiguration.ApplyChanges();
                handConfiguration.Dispose();

                HandDataOutput = handAnalysis.CreateOutput();
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled != true)
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled = true;
                    OnDisable();
                    OnEnable();
                    Start();
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                UpdateSpeechCommands();
                SpeechManager.Start();
            }

            // Create an instance for the projection
            if (_projection == null)
            {
                _projection = SenseManager.QueryCaptureManager().QueryDevice().CreateProjection();
            }

            // Set initialization flag
            Initialized = true;
        }
Beispiel #26
0
        public static void start(IoT_RealSense_Surfing frm)
        {
            keepLooping = true;
            iot_form    = frm;
            InitializeMqqtClient();
            PXCMSession session = PXCMSession.CreateInstance();

            // Querying the SDK version
            Console.WriteLine(frm.comboTarget.SelectedText);
            if (session != null)
            {
                // Optional steps to send feedback to Intel Corporation to understand how often each SDK sample is used.
                PXCMMetadata md = session.QueryInstance <PXCMMetadata>();
                if (md != null)
                {
                    string sample_name = "Emotion Viewer CS";
                    md.AttachBuffer(1297303632, System.Text.Encoding.Unicode.GetBytes(sample_name));
                }
                //Application.Run(new MainForm(session));
                //session.Dispose();
            }
            //PXCMSession.ImplVersion version = session.QueryVersion();
            //Console.WriteLine("RealSense SDK Version {0}.{1}", version.major, version.minor);

            session.CreateImpl <PXCMRotation>(out rotationHelper);

            // Creating the SenseManager
            PXCMSenseManager senseManager = session.CreateSenseManager();

            if (senseManager == null)
            {
                Console.WriteLine("Failed to create the SenseManager object.");
                return;
            }

            // Enabling Emotion Module
            pxcmStatus enablingModuleStatus = senseManager.EnableEmotion();

            if (enablingModuleStatus != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to enable the Emotion Module");
                return;
            }

            // Getting the instance of the Emotion Module
            PXCMEmotion emotionModule = senseManager.QueryEmotion();

            if (emotionModule == null)
            {
                Console.WriteLine("Failed to query the emotion module");
                return;
            }

            // Initializing the camera
            if (senseManager.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to initialize the SenseManager");
                return;
            }

            // Enabling the Hand module
            pxcmStatus enablingModuleStatus1 = senseManager.EnableHand("Hand Module");

            if (enablingModuleStatus1 != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("Failed to enable the Hand Module");
                return;
            }

            // Getting the instance of the Hand Module
            PXCMHandModule handModule = senseManager.QueryHand();

            if (handModule == null)
            {
                Console.WriteLine("Failed to get the HandModule object.");
                return;
            }

            // Creating an active configuration
            PXCMHandConfiguration handConfiguration = handModule.CreateActiveConfiguration();

            if (handConfiguration == null)
            {
                Console.WriteLine("Failed to create the HandConfiguration object.");
                return;
            }

            // Listing the available gestures
            int supportedGesturesCount = handConfiguration.QueryGesturesTotalNumber();

            if (supportedGesturesCount > 0)
            {
                Console.WriteLine("Supported gestures:");
                for (int i = 0; i < supportedGesturesCount; i++)
                {
                    string gestureName = string.Empty;

                    if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) == pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        Console.WriteLine("\t" + gestureName);
                    }
                }
            }

            // Enabling some gestures
            String[] enabledGestures = { GESTURE_CLICK, GESTURE_VSIGN, GESTURE_FIST, GESTURE_SPREADFINGERS };
            foreach (String gesture in enabledGestures)
            {
                if (!handConfiguration.IsGestureEnabled(gesture))
                {
                    handConfiguration.EnableGesture(gesture);
                }
            }
            handConfiguration.ApplyChanges();

            // Creating a data output object
            PXCMHandData handData = handModule.CreateOutput();

            if (handData == null)
            {
                Console.WriteLine("Failed to create the HandData object.");
                return;
            }

            // Initializing the SenseManager
            if (senseManager.Init() != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine(senseManager.Init());
                return;
            }

            // Looping to query the hands information
            while (keepLooping)
            {
                // Acquiring a frame
                if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                // Updating the hand data
                if (handData != null)
                {
                    handData.Update();
                }
                //ProcessHands(handData);
                ProcessGestures(handData);
                ProcessEmotions(emotionModule);
                // Releasing the acquired frame
                senseManager.ReleaseFrame();

                /* using another frame to process different stuff? may be...
                 * // Acquiring a frame
                 * if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                 * {
                 *  break;
                 * }
                 *
                 * // Processing Emotions
                 * ProcessEmotions(emotionModule);
                 *
                 * // Releasing the acquired frame
                 * senseManager.ReleaseFrame();*/
            }


            // Releasing resources
            if (handData != null)
            {
                handData.Dispose();
            }
            if (handConfiguration != null)
            {
                handConfiguration.Dispose();
            }
            rotationHelper.Dispose();

            senseManager.Close();
            senseManager.Dispose();
            session.Dispose();
            client.Disconnect();
        }
Beispiel #27
0
    private Hashtable handList;                            //keep track of bodyside and hands for GUItext

    // Use this for initialization
    void Start()
    {
        handList = new Hashtable();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
        {
            Debug.LogError("SenseManager Initialization Failed");
        }

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts          = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);
        }

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("PXCSenseManager.Init: " + sts);
        }

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl <PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands, MaxJoints];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();

        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }

        myJoints = new Joint[MaxHands, MaxJoints];

        Joint[] joints;
        if (RightHand != null)
        {
            HandMapping RightMapping = RightHand.GetComponent <HandMapping>();
            joints = RightMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[0, j] = joints[j];
            }
        }

        if (LeftHand != null)
        {
            HandMapping LeftMapping = LeftHand.GetComponent <HandMapping>();
            joints = LeftMapping.GetJoints();
            for (int j = 0; j < MaxJoints; j++)
            {
                myJoints[1, j] = joints[j];
            }
        }

        jointData = new PXCMHandData.JointData[MaxHands, MaxJoints];

        for (int i = 0; i < MaxHands; i++)
        {
            for (int j = 0; j < MaxJoints; j++)
            {
                Joint joint = myJoints[i, j];
                if (joint != null)
                {
                    joint.originalPosition = joint.transform.position;
                    joint.originalRotation = joint.transform.rotation;

                    //Calculate orientation
                    Vector3 v          = Vector3.zero;
                    Vector3 parent     = joint.transform.position;
                    int     childcount = 0;

                    foreach (Joint.Neighbour n in joint.neighbours)
                    {
                        if (n.index < j)
                        {
                            parent = n.joint.transform.position;
                        }
                        else
                        {
                            v += n.joint.transform.position;
                            childcount++;
                        }
                    }
                    Vector3 direction = v - parent * childcount;
                    joint.originalOrientation = direction + parent - joint.transform.position;

                    //Joint extensions
                    foreach (Joint e in joint.extensions)
                    {
                        e.originalPosition    = e.transform.position;
                        e.originalRotation    = e.transform.rotation;
                        e.originalOrientation = joint.transform.position - e.transform.position;
                    }
                }

                smoother3D[i, j] = smoother.Create3DWeighted(smoothing);
                jointData[i, j]  = new PXCMHandData.JointData();

                //Test output to check Hand Mapping
                if (myJoints[i, j] == null)
                {
                    Debug.Log("null");
                }
                else
                {
                    Debug.Log(myJoints[i, j].transform.name);
                }
            }
        }
    }
        /// <summary>
        /// コンストラクタ
        /// 
        /// カメラ画像表示用のWritableBitmapを準備してImageに割り当て
        /// カメラ制御用のオブジェクトを取得して
        /// Colorカメラストリームを有効にしてカメラのフレーム取得を開始する
        /// カメラキャプチャーするためのTaskを準備して開始
        /// </summary>
        public MainWindow()
        {
            // 画面コンポーネントを初期化
            InitializeComponent();

            // ジェスチャー画像表示用Imageを非表示にする
            HiddenGestureImage();

            // カメラ画像書き込み用のWriteableBitmapを準備してImageコントローラーにセット
            m_ColorWBitmap = new WriteableBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Bgr32, null);
            ColorCameraImage.Source = m_ColorWBitmap;
            m_HandSegmentWBitmap = new WriteableBitmap(640, 480, 96.0, 96.0, PixelFormats.Gray8, null);
            HandSegmentImage.Source = m_HandSegmentWBitmap;
            m_HandJointWBitmap = new WriteableBitmap(640, 480, 96.0, 96.0, PixelFormats.Bgra32, null);
            HandJointtImage.Source = m_HandJointWBitmap;

            // カメラ制御のオブジェクトを取得
            m_Session = PXCMSession.CreateInstance();
            m_Cm = m_Session.CreateSenseManager();

            // Color,Depth,Irストリームを有効にする
            m_Cm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 30);
            m_Cm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480, 30);
            m_Cm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480, 30);

            // Hand Trackingを有効化と設定
            m_Cm.EnableHand();
            PXCMHandModule handModule = m_Cm.QueryHand();
            PXCMHandConfiguration handConfig = handModule.CreateActiveConfiguration();
            handConfig.SetTrackingMode(PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND);  // FULL_HANDモード
            handConfig.EnableSegmentationImage(true);   // SegmentationImageの有効化
            handConfig.EnableAllGestures();                 // すべてのジェスチャーを補足
            handConfig.SubscribeGesture(OnFiredGesture);    // ジェスチャー発生時のコールバック関数をセット

            handConfig.ApplyChanges();

            // HandDataのインスタンスを作成
            m_HandData = handModule.CreateOutput();

            // カメラのフレーム取得開始
            pxcmStatus initState = m_Cm.Init();
            if (initState < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                // エラー発生
                MessageBox.Show(initState + "\nカメラ初期化に失敗しました。");
                return;
            }

            // カメラ取得画像をミラーモードにする
            m_Cm.captureManager.device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL);

            // 座標変換のためのProjectionインスタンスを取得
            m_Projection = m_Cm.QueryCaptureManager().QueryDevice().CreateProjection();

            // カメラキャプチャーをするためのタスクを準備して起動
            m_CameraCaptureTask = new Task(() => CaptureCameraProcess());
            m_CameraCaptureTask.Start();
        }
        void OnEnable()
        {
            Initialized = false;

            /* Create a SenseManager instance */
            SenseManager = PXCMSenseManager.CreateInstance();

            if (SenseManager == null)
            {
                print("Unable to create the pipeline instance");
                return;
            }

            if (_speechCommandsRef.Count != 0)
            {
                SetSenseOption(SenseOption.SenseOptionID.Speech);
            }

            int numberOfEnabledModalities = 0;

            //Set mode according to RunMode - play from file / record / live stream
            if (RunMode == MCTTypes.RunModes.PlayFromFile)
            {
                //CHECK IF FILE EXISTS
                if (!System.IO.File.Exists(FilePath))
                {
                    Debug.LogWarning("No Filepath Set Or File Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, false);
                    Debug.Log("SenseToolkitManager: Playing from file: " + FilePath);
                }
            }

            if (RunMode == MCTTypes.RunModes.RecordToFile)
            {
                //CHECK IF PATH
                string PathOnly = FilePath;
                while (!PathOnly[PathOnly.Length - 1].Equals('\\'))
                {
                    PathOnly = PathOnly.Remove(PathOnly.Length - 1, 1);
                }

                if (!System.IO.Directory.Exists(PathOnly))
                {
                    Debug.LogWarning("No Filepath Set Or Path Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, true);
                    Debug.Log("SenseToolkitManager: Recording to file: " + FilePath);
                }
            }

            /* Enable modalities according to the set options*/
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                SenseManager.EnableFace();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Enabled     = true;
                SetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                _sts = SenseManager.EnableHand();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Blob, true))
            {
                _sts = SenseManager.EnableBlob();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Blob).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Blob).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                _sts = SenseManager.EnableTracker();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                if (!SpeechManager.IsInitialized)
                {
                    if (SpeechManager.InitalizeSpeech())
                    {
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                        numberOfEnabledModalities++;
                    }
                    else
                    {
                        UnsetSenseOption(SenseOption.SenseOptionID.Speech);
                    }
                }
                else
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled     = true;
                    numberOfEnabledModalities++;
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoDepthStream, true) ||
                IsSenseOptionSet(SenseOption.SenseOptionID.PointCloud, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoIRStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 0, 0, 0);
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoColorStream, true))
            {
                if (ColorImageQuality == MCTTypes.RGBQuality.FullHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HalfHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                }
                else
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                }
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Enabled     = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoSegmentation, true))
            {
                if (ColorImageQuality == MCTTypes.RGBQuality.FullHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HalfHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                }
                else
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                }
                SenseManager.Enable3DSeg();
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Initialized = true;
                _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Enabled     = true;
                numberOfEnabledModalities++;
            }

            /* Initialize the execution */
            _sts = SenseManager.Init();
            if (_sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                return;
            }

            //Set different configurations:

            // Face
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                var faceModule = SenseManager.QueryFace();
                if (faceModule == null)
                {
                    throw new UnityException("QueryFace returned null");
                }

                var faceConfiguration = faceModule.CreateActiveConfiguration();
                if (faceConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                faceConfiguration.Update();

                faceConfiguration.detection.isEnabled      = true;
                faceConfiguration.detection.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.landmarks.isEnabled      = true;
                faceConfiguration.landmarks.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.pose.isEnabled      = true;
                faceConfiguration.pose.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.DisableAllAlerts();

                faceConfiguration.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_APPEARANCE_TIME;

                if ((NumberOfDetectedFaces < 1) || (NumberOfDetectedFaces > 15))
                {
                    Debug.Log("Ilegal value for Number Of Detected Faces, value is set to 1");
                    NumberOfDetectedFaces = 1;
                }

                faceConfiguration.detection.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.landmarks.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.pose.maxTrackedFaces      = NumberOfDetectedFaces;

                PXCMFaceConfiguration.ExpressionsConfiguration expressionConfig = faceConfiguration.QueryExpressions();
                if (expressionConfig == null)
                {
                    throw new UnityException("QueryExpressions returned null");
                }

                expressionConfig.Enable();
                expressionConfig.EnableAllExpressions();


                faceConfiguration.ApplyChanges();
                faceConfiguration.Dispose();

                FaceModuleOutput = faceModule.CreateOutput();

                UnsetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
            }

            // Hand
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                PXCMHandModule handAnalysis = SenseManager.QueryHand();
                if (handAnalysis == null)
                {
                    throw new UnityException("QueryHand returned null");
                }

                PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
                if (handConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                handConfiguration.Update();
                handConfiguration.EnableAllGestures();
                handConfiguration.EnableStabilizer(true);
                handConfiguration.DisableAllAlerts();
                handConfiguration.EnableSegmentationImage(false);
                handConfiguration.ApplyChanges();
                handConfiguration.Dispose();

                HandDataOutput = handAnalysis.CreateOutput();
            }

            // Blob
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Blob, true))
            {
                PXCMBlobModule blobAnalysis = SenseManager.QueryBlob();
                if (blobAnalysis == null)
                {
                    throw new UnityException("QueryBlob returned null");
                }

                PXCMBlobConfiguration blobConfiguration = blobAnalysis.CreateActiveConfiguration();
                if (blobConfiguration == null)
                {
                    throw new UnityException("CreateActiveConfiguration returned null");
                }

                blobConfiguration.Update();
                blobConfiguration.EnableContourExtraction(true);
                blobConfiguration.EnableSegmentationImage(true);
                blobConfiguration.EnableStabilizer(true);
                blobConfiguration.SetMaxDistance(50 * 10);
                blobConfiguration.ApplyChanges();
                blobConfiguration.Dispose();

                BlobDataOutput = blobAnalysis.CreateOutput();
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled != true)
                {
                    _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Object).Enabled = true;
                    OnDisable();
                    OnEnable();
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                UpdateSpeechCommands();
                SpeechManager.Start();
            }

            // Create an instance for the projection & blob extractor

            if (Projection == null)
            {
                Projection = SenseManager.QueryCaptureManager().QueryDevice().CreateProjection();
            }

            /* GZ
             *          if (BlobExtractor == null)
             *          {
             *                  SenseManager.session.CreateImpl<PXCMBlobExtractor>(out BlobExtractor);
             *          }*/

            // Set initialization flag
            Initialized = true;
        }
Beispiel #30
0
    /* Constructor */
    public HandsData(int MaxHands, int MaxJoints)
    {
        NumOfHands  = MaxHands;
        NumOfJoints = MaxJoints;
        JointData   = new PXCMHandData.JointData[NumOfHands][]; // Joint coordinates
        Coordinates = new Main.HandCoord[NumOfHands];

        /* Declaration of the array for the hand data*/
        for (int i = 0; i < NumOfHands; i++)
        {
            JointData[i]   = new PXCMHandData.JointData[NumOfJoints];
            Coordinates[i] = new Main.HandCoord(6, NumOfJoints);
            for (int j = 0; j < NumOfJoints; j++)
            {
                JointData[i][j] = new PXCMHandData.JointData();
            }
        }

        /* Initialization of SenseManager */
        SenseManager = PXCMSenseManager.CreateInstance();
        if (SenseManager == null)
        {
            Debug.LogError("Initialization of the SenseManager has failed");
        }

        /* Enable hand tracking and get an instance of an hand module */
        Status     = SenseManager.EnableHand();
        HandModule = SenseManager.QueryHand();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("SenseManager --> EnableHand " + Status);
        }

        /* Create the connection to the Intel RealSense camera */
        Status = SenseManager.Init();
        if (Status != pxcmStatus.PXCM_STATUS_NO_ERROR)
        {
            Debug.LogError("Initialization of SenseManager: " + Status);
        }



        /* Settings for the hand module */
        PXCMHandConfiguration HandConfig = HandModule.CreateActiveConfiguration();

        if (HandConfig != null)
        {
            HandConfig.EnableAllGestures();
            HandConfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);

            PXCMHandData.JointType st = PXCMHandData.JointType.JOINT_WRIST;
            for (int i = 0; i < NumOfJoints; i++)
            {
                HandConfig.EnableJointSpeed(st, PXCMHandData.JointSpeedType.JOINT_SPEED_AVERAGE, 1000 / 10);
                st++;
            }

            //HandConfig.EnableJointSpeed(PXCMHandData.JointType.JOINT_WRIST, PXCMHandData.JointSpeedType.JOINT_SPEED_ABSOLUTE,1000/20);
            HandConfig.ApplyChanges();
            HandConfig.Dispose();
        }
    }
        // Use this for initialization
        void Start()
        {
            // Creates an instance of the sense manager to be called later
            session = PXCMSenseManager.CreateInstance();


            //Output an error if there is no instance of the sense manager
            if (session == null)
            {
                Debug.LogError("SenseManager Init Failed!");
            }


            // Enables hand tracking
            sts          = session.EnableHand();
            handAnalyzer = session.QueryHand();

            sts2         = session.EnableFace();
            faceAnalyzer = session.QueryFace();


            if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Debug.LogError("PXCSenseManager.EnableHand: " + sts);
            }


            if (sts2 != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Debug.LogError("PXCSenseManager.EnableFace: " + sts2);
            }



            // Creates the session
            sts = session.Init();

            sts2 = session.Init();


            if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Debug.LogError("PXCSenseManager.Init: " + sts);
            }


            if (sts2 != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Debug.LogError("PXCSenseManager.Init: " + sts2);
            }



            // Creates a hand config for future data
            PXCMHandConfiguration handconfig = handAnalyzer.CreateActiveConfiguration();

            PXCMFaceConfiguration faceconfig = faceAnalyzer.CreateActiveConfiguration();


            //If there is handconfig instance
            if (handconfig != null)
            {
                handconfig.EnableAllAlerts();
                handconfig.ApplyChanges();
                handconfig.Dispose();
            }
            if (faceconfig != null)
            {
                faceconfig.EnableAllAlerts();
                faceconfig.ApplyChanges();
                faceconfig.Dispose();
            }
        }
Beispiel #32
0
        public void HandPipeLine()
        {
            PXCMSenseManager pp = m_form.Session.CreateSenseManager();

            if (pp == null)
            {
                throw new Exception("PXCMSenseManager null");
            }

            pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 360);

            //手 初始化
            PXCMHandModule handAnalysis;

            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler();
            handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame);
            PXCMHandConfiguration handConfiguration = null;
            PXCMHandData          handData          = null;


            pxcmStatus status = pp.EnableHand();

            handAnalysis = pp.QueryHand();

            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null)
            {
                Console.WriteLine("hand module load failed");
                return;
            }
            handConfiguration = handAnalysis.CreateActiveConfiguration();
            if (handConfiguration == null)
            {
                Console.WriteLine("Failed Create Configuration");
                return;
            }
            handData = handAnalysis.CreateOutput();
            if (handData == null)
            {
                Console.WriteLine("Failed Create Output");
                return;
            }

            if (pp.Init(handler) != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                Console.WriteLine("init failed");
                return;
            }

            if (handConfiguration != null)
            {
                PXCMHandData.TrackingModeType trackingMode = PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND;

                // 配置收的Tracking Mode
                trackingMode = PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND;

                handConfiguration.SetTrackingMode(trackingMode);

                handConfiguration.EnableAllAlerts();
                handConfiguration.EnableSegmentationImage(true);
                bool isEnabled = handConfiguration.IsSegmentationImageEnabled();

                handConfiguration.ApplyChanges();

                int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber();

                if (totalNumOfGestures > 0)
                {
                    for (int i = 0; i < totalNumOfGestures; i++)
                    {
                        string gestureName = string.Empty;
                        if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) ==
                            pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            Console.WriteLine(gestureName);
                        }
                    }
                }
            }


            int frameCounter = 0;
            int frameNumber  = 0;

            while (!m_form.Stopped)
            {
                string gestureName = "fist";
                if (handConfiguration != null)
                {
                    if (string.IsNullOrEmpty(gestureName) == false)
                    {
                        if (handConfiguration.IsGestureEnabled(gestureName) == false)
                        {
                            handConfiguration.DisableAllGestures();
                            handConfiguration.EnableGesture(gestureName, true);
                            handConfiguration.ApplyChanges();
                        }
                    }
                    else
                    {
                        handConfiguration.DisableAllGestures();
                        handConfiguration.ApplyChanges();
                    }
                }

                if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    break;
                }

                frameCounter++;

                if (pp.IsConnected())
                {
                    PXCMCapture.Sample sample;
                    sample = pp.QueryHandSample();
                    if (sample != null && sample.depth != null)
                    {
                        // frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex();
                        frameNumber = frameCounter;
                    }
                    //bool b=(sample.ir==null);
                    //b = (sample.color== null);
                    //b = (sample.left == null);
                    //b = (sample.right == null);
                    DisplayPicture(sample.depth);

                    if (handData != null)
                    {
                        handData.Update();

                        SaveHandData(handData);
                    }
                    m_form.UpdatePic();
                }
                pp.ReleaseFrame();
            }

            if (handData != null)
            {
                handData.Dispose();
            }
            if (handConfiguration != null)
            {
                handConfiguration.Dispose();
            }

            pp.Close();
            pp.Dispose();
        }
Beispiel #33
0
        public void StreamColorDepth() /* Stream Color and Depth Synchronously or Asynchronously */
        {
            try
            {
                bool sts = true;

                /* Create an instance of the PXCMSenseManager interface */
                PXCMSenseManager sm = PXCMSenseManager.CreateInstance();

                if (sm == null)
                {
                    MessageBox.Show("当前对象为空!");
                    return;
                }

                /* Optional: if playback or recoridng */
                if (File != null)
                {
                    sm.captureManager.SetFileName(File, this.isRecord);
                }

                sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080);

                sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
                sm.EnableHand();
                sm.EnableFace();


                /* Initialization */

                pxcmStatus status = sm.Init();

                if (status >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    /* Reset all properties */
                    sm.captureManager.device.ResetProperties(PXCMCapture.StreamType.STREAM_TYPE_ANY);

                    while (!Stop)
                    {
                        /* Wait until a frame is ready: Synchronized or Asynchronous */
                        if (sm.AcquireFrame(true).IsError())
                        {
                            break;
                        }

                        /* Display images */
                        //PXCMCapture.Sample sample = sm.QuerySample();

                        /* Render streams */
                        //EventHandler<RenderFrameEventArgs> render = RenderFrame;
                        //PXCMImage image = null;

                        //image = sample[PXCMCapture.StreamType.STREAM_TYPE_DEPTH];
                        //render(this, new RenderFrameEventArgs(0, image));


                        sm.ReleaseFrame();
                    }
                }
                else
                {
                    sts = false;
                }

                sm.Dispose();
                //if (sts) MessageBox.Show("Stopped");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                //MessageBox.Show(e.GetType().ToString());
            }
        }
Beispiel #34
0
        /* Using PXCMSenseManager to handle data */
        public void SimplePipeline()
        {
            form.UpdateInfo(String.Empty, Color.Black);
            bool liveCamera = false;

            bool             flag     = true;
            PXCMSenseManager instance = null;

            _disconnected = false;
            instance      = form.g_session.CreateSenseManager();
            if (instance == null)
            {
                form.UpdateStatus("Failed creating SenseManager");
                return;
            }

            if (form.GetRecordState())
            {
                instance.captureManager.SetFileName(form.GetFileName(), true);
                PXCMCapture.DeviceInfo info;
                if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info))
                {
                    instance.captureManager.FilterByDeviceInfo(info);
                }
            }
            else if (form.GetPlaybackState())
            {
                instance.captureManager.SetFileName(form.GetFileName(), false);
                instance.captureManager.SetRealtime(false);
            }
            else
            {
                PXCMCapture.DeviceInfo info;
                if (String.IsNullOrEmpty(form.GetCheckedDevice()))
                {
                    form.UpdateStatus("Device Failure");
                    return;
                }

                if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info))
                {
                    instance.captureManager.FilterByDeviceInfo(info);
                }

                liveCamera = true;
            }
            /* Set Module */
            pxcmStatus     status       = instance.EnableHand(form.GetCheckedModule());
            PXCMHandModule handAnalysis = instance.QueryHand();

            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null)
            {
                form.UpdateStatus("Failed Loading Module");
                return;
            }

            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler();
            handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame);


            PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
            PXCMHandData          handData          = handAnalysis.CreateOutput();

            if (handConfiguration == null)
            {
                form.UpdateStatus("Failed Create Configuration");
                return;
            }
            if (handData == null)
            {
                form.UpdateStatus("Failed Create Output");
                return;
            }

            if (form.getInitGesturesFirstTime() == false)
            {
                int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber();
                if (totalNumOfGestures > 0)
                {
                    this.form.UpdateGesturesToList("", 0);
                    for (int i = 0; i < totalNumOfGestures; i++)
                    {
                        string gestureName = string.Empty;
                        if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) ==
                            pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            this.form.UpdateGesturesToList(gestureName, i + 1);
                        }
                    }
                    form.setInitGesturesFirstTime(true);
                    form.UpdateGesturesListSize();
                }
            }


            FPSTimer timer = new FPSTimer(form);

            form.UpdateStatus("Init Started");
            if (handAnalysis != null && instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMCapture.DeviceInfo dinfo;

                PXCMCapture.Device device = instance.captureManager.device;
                if (device != null)
                {
                    pxcmStatus result = device.QueryDeviceInfo(out dinfo);
                    if (result == pxcmStatus.PXCM_STATUS_NO_ERROR && dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
                    {
                        device.SetDepthConfidenceThreshold(1);
                        device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED);
                        device.SetIVCAMFilterOption(6);
                    }

                    _maxRange = device.QueryDepthSensorRange().max;
                }


                if (handConfiguration != null)
                {
                    handConfiguration.EnableAllAlerts();
                    handConfiguration.EnableSegmentationImage(true);

                    handConfiguration.ApplyChanges();
                    handConfiguration.Update();
                }

                form.UpdateStatus("Streaming");
                int    frameCounter = 0;
                int    frameNumber = 0;
                string nextPageGesture, previousPageGesture, firstPageGesture, endPageGesture;
                HandsRecognition.Hand nextHand, previousHand, firstHand, endHand;

                while (!form.stop)
                {
                    form.GetHandType(out nextHand, out previousHand, out firstHand, out endHand);
                    form.GetGestureName(out nextPageGesture, out previousPageGesture, out firstPageGesture, out endPageGesture);
                    handConfiguration.DisableAllGestures();
                    if (string.IsNullOrEmpty(nextPageGesture) == false && handConfiguration.IsGestureEnabled(nextPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(nextPageGesture, true);
                        NextPageGesture.Gesture  = nextPageGesture;
                        NextPageGesture.handler  = form.NextPage;
                        NextPageGesture.HandType = nextHand;
                    }
                    if (string.IsNullOrEmpty(previousPageGesture) == false && handConfiguration.IsGestureEnabled(previousPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(previousPageGesture, true);
                        PreviousPageGesture.Gesture  = previousPageGesture;
                        PreviousPageGesture.handler  = form.PreviousPage;
                        PreviousPageGesture.HandType = previousHand;
                    }
                    if (string.IsNullOrEmpty(firstPageGesture) == false && handConfiguration.IsGestureEnabled(firstPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(firstPageGesture, true);
                        FirstPageGesture.Gesture  = firstPageGesture;
                        FirstPageGesture.handler  = form.FirstPage;
                        FirstPageGesture.HandType = firstHand;
                    }
                    if (string.IsNullOrEmpty(endPageGesture) == false && handConfiguration.IsGestureEnabled(endPageGesture) == false)
                    {
                        handConfiguration.EnableGesture(endPageGesture, true);
                        EndPageGesture.Gesture  = endPageGesture;
                        EndPageGesture.handler  = form.EndPage;
                        EndPageGesture.HandType = endHand;
                    }
                    handConfiguration.ApplyChanges();
                    if (instance.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        break;
                    }

                    frameCounter++;

                    if (!DisplayDeviceConnection(!instance.IsConnected()))
                    {
                        if (handData != null)
                        {
                            handData.Update();
                        }

                        PXCMCapture.Sample sample = instance.QueryHandSample();
                        if (sample != null && sample.depth != null)
                        {
                            DisplayPicture(sample.depth, handData);

                            if (handData != null)
                            {
                                frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex();

                                DisplayJoints(handData);
                                DisplayGesture(handData, frameNumber);
                                DisplayAlerts(handData, frameNumber);
                            }
                            form.UpdatePanel();
                        }
                        timer.Tick();
                    }
                    instance.ReleaseFrame();
                }

                // Clean Up
                if (handData != null)
                {
                    handData.Dispose();
                }
                if (handConfiguration != null)
                {
                    handConfiguration.Dispose();
                }
            }
            else
            {
                form.UpdateStatus("Init Failed");
                flag = false;
            }
            foreach (PXCMImage pxcmImage in m_images)
            {
                pxcmImage.Dispose();
            }



            instance.Close();
            instance.Dispose();
            if (flag)
            {
                form.UpdateStatus("Stopped");
            }
        }
Beispiel #35
0
    void Start()
    {
        if (CursorObject != null)
        {
            mCursor0 = (GameObject)Instantiate(CursorObject, Vector3.zero, Quaternion.identity);
            mCursor0.transform.SetParent(Camera.main.transform);
            mCursor0.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize);
            mCursor0Active = false;
            mCursor1       = (GameObject)Instantiate(CursorObject, Vector3.zero, Quaternion.identity);
            mCursor1.transform.SetParent(Camera.main.transform);
            mCursor1.transform.localScale = new Vector3(CursorSize, CursorSize, CursorSize);
            mCursor1Active = false;
        }

        mRS = PXCMSenseManager.CreateInstance();
        var stat = pxcmStatus.PXCM_STATUS_NO_ERROR;

        if (mRS != null)
        {
            stat = mRS.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
            if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                stat = mRS.EnableHand();
                if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    stat = mRS.Init();
                    Debug.Log("Sense Manager Started");
                }
            }

            else
            {
                Debug.Log("Unable to start Sense Manager");
            }
            if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                PXCMHandConfiguration cfg = mRS.QueryHand().CreateActiveConfiguration();
                if (cfg != null)
                {
                    stat = cfg.SetTrackingMode(PXCMHandData.TrackingModeType.TRACKING_MODE_CURSOR);
                    if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                    {
                        Debug.Log("Set Cursor Mode 1st Pass");
                        if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                        {
                            stat = cfg.EnableAllGestures(false);
                            if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                            {
                                stat = cfg.ApplyChanges();
                                if (stat >= pxcmStatus.PXCM_STATUS_NO_ERROR)
                                {
                                    stat = cfg.Update();
                                }
                            }
                        }
                        else
                        {
                            Debug.Log("Unable to enable gestures");
                        }
                    }
                    else
                    {
                        Debug.Log("Unable to set Cursor Mode");
                    }
                    cfg.Dispose();
                }
            }

            else
            {
                Debug.Log("Unable to create hand config");
            }

            mHand = mRS.QueryHand().CreateOutput();
            if (mHand != null)
            {
                Debug.Log("Created Hand Data");
                var tracking = mRS.QueryHand().CreateActiveConfiguration().QueryTrackingMode();
                if (tracking == PXCMHandData.TrackingModeType.TRACKING_MODE_CURSOR)
                {
                    Debug.Log("Cursor Mode Enabled");
                }
            }
        }
        else
        {
            Debug.Log("Unable to configure hand module");
        }
        Application.targetFrameRate = 60;

        ResetHead.SetRoomRotation();
    }
    // Use this for initialization
    void Start()
    {
        handList = new Hashtable ();

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance ();
        if (sm == null)
            Debug.LogError ("SenseManager Initialization Failed");

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts = sm.EnableHand ();
        handAnalyzer = sm.QueryHand ();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
            Debug.LogError ("PXCSenseManager.EnableHand: " + sts);

        /* Initialize the execution pipeline */
        sts = sm.Init ();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
            Debug.LogError ("PXCSenseManager.Init: " + sts);

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession ().CreateImpl<PXCMDataSmoothing> (out ds);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMDataSmoothing.Smoother3D[MaxHands][];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration ();
        hcfg.EnableAllGestures ();
        hcfg.EnableAlert (PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
        hcfg.ApplyChanges ();
        hcfg.Dispose ();

        InitializeGameobjects ();

        transform.RotateAround (transform.position, Vector3.up, 200 * Time.deltaTime);
        //	Vector3 _RotateAround = new Vector3 (1, 1f, 180f);

        //	transform.RotateAround (_RotateAround, Vector3.up, 20);
    }
Beispiel #37
0
        //*********************************初始化函数(初始化各种杂乱的参数)*******************************************************************

        // Init all crappy parameters RealSense needs
        private void InitStreamState()
        {
            manager = session.CreateSenseManager();

            //算法模块
            switch (m_algoOption)
            {
            case AlgoOption.Face:
                manager.EnableFace();
                break;

            case AlgoOption.Hand:
                manager.EnableHand();
                break;

            case AlgoOption.FaceAndHand:
                manager.EnableFace();
                manager.EnableHand();
                break;

            default:
                break;
            }

            //视频显示流模块
            switch (m_streamOption)
            {
            case StreamOption.Color:
                //manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 360);
                manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080);
                break;

            case StreamOption.Depth:
                manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
                break;

            case StreamOption.IR:
                manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480);
                break;

            case StreamOption.ColorAndDepth:
                manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);
                manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080);
                break;

            default:
                break;
            }

            //控制录像模块
            var recordPath = System.Configuration.ConfigurationManager.AppSettings["RecordPath"];

            switch (m_recordOption)
            {
            case RecordOption.Live:
                break;

            case RecordOption.Record:
                if (recordPath == null)
                {
#if DEBUG
                    System.Windows.Forms.MessageBox.Show("RecordPath Error");
#endif
                }
                manager.captureManager.SetFileName(recordPath, true);
                break;

            case RecordOption.Playback:
                if (this.PlaybackFile != null)
                {
                    manager.captureManager.SetFileName(this.PlaybackFile, false);
                }
                else
                {
                    manager.captureManager.SetFileName(recordPath, false);
                }
                manager.captureManager.SetRealtime(false);

                if (m_playback_byframe)
                {
                    manager.captureManager.SetRealtime(false);
                    manager.captureManager.SetPause(true);
                }
                //manager.captureManager.SetRealtime(true);
                break;
            }
        }
        void OnEnable()
        {
            Initialized = false;

            /* Create a SenseManager instance */
            SenseManager = PXCMSenseManager.CreateInstance();

            if (SenseManager == null)
            {
                print("Unable to create the pipeline instance");
                return;
            }

            if (_speechCommandsRef.Count != 0)
            {
                SetSenseOption(SenseOption.SenseOptionID.Speech);
            }

            int numberOfEnabledModalities = 0;

            //Set mode according to RunMode - play from file / record / live stream
            if (RunMode == MCTTypes.RunModes.PlayFromFile)
            {
                //CHECK IF FILE EXISTS
                if (!System.IO.File.Exists(FilePath))
                {
                    Debug.LogWarning("No Filepath Set Or File Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, false);
                    Debug.Log("SenseToolkitManager: Playing from file: " + FilePath);
                }
            }

            if (RunMode == MCTTypes.RunModes.RecordToFile)
            {
                //CHECK IF PATH
                string PathOnly = FilePath;
                while (!PathOnly[PathOnly.Length - 1].Equals('\\'))
                {
                    PathOnly = PathOnly.Remove(PathOnly.Length - 1, 1);
                }

                if (!System.IO.Directory.Exists(PathOnly))
                {
                    Debug.LogWarning("No Filepath Set Or Path Doesn't Exist, Run Mode Will Be Changed to Live Stream");
                    RunMode = MCTTypes.RunModes.LiveStream;
                }
                else
                {
                    PXCMCaptureManager cManager = SenseManager.QueryCaptureManager();
                    cManager.SetFileName(FilePath, true);
                    Debug.Log("SenseToolkitManager: Recording to file: " + FilePath);
                }
            }

            /* Enable modalities according to the set options*/
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                SenseManager.EnableFace();
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Face).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Face).Enabled = true;
                SetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                _sts = SenseManager.EnableHand();
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Hand).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Hand).Enabled = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                _sts = SenseManager.EnableTracker();
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Object).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Object).Enabled = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                if (!SpeechManager.IsInitialized)
                {
                    if (SpeechManager.InitalizeSpeech())
                    {
                        _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                        _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Speech).Enabled = true;
                        numberOfEnabledModalities++;
                    }
                    else
                    {
                        UnsetSenseOption(SenseOption.SenseOptionID.Speech);
                    }
                }
                else
                {
                    _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Speech).Initialized = true;
                    _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Speech).Enabled = true;
                    numberOfEnabledModalities++;
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoDepthStream, true) ||
                IsSenseOptionSet(SenseOption.SenseOptionID.PointCloud, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 0, 0, 0);
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Enabled = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoIRStream, true))
            {
                SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 0, 0, 0);
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Enabled = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoColorStream, true))
            {
                if (ColorImageQuality == MCTTypes.RGBQuality.FullHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HalfHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                }
                else
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                }
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Enabled = true;
                numberOfEnabledModalities++;
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.VideoSegmentation, true))
            {
                if (ColorImageQuality == MCTTypes.RGBQuality.FullHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1920, 1080, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 1280, 720, 0);
                }
                else if (ColorImageQuality == MCTTypes.RGBQuality.HalfHD)
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 960, 540, 0);
                }
                else
                {
                    SenseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 0);
                }
                SenseManager.Enable3DSeg();
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Initialized = true;
                _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Enabled = true;
                numberOfEnabledModalities++;
            }

            /* Initialize the execution */
            _sts = SenseManager.Init();
            if (_sts < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                if (numberOfEnabledModalities > 0)
                {
                    Debug.LogError("Unable to initialize all modalities");
                }
                return;
            }
            //Set different configurations:

            // Face
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Face, true))
            {
                var faceModule = SenseManager.QueryFace();
                var faceConfiguration = faceModule.CreateActiveConfiguration();
                if (faceConfiguration == null) throw new UnityException("CreateActiveConfiguration returned null");

                faceConfiguration.Update();

                faceConfiguration.detection.isEnabled = true;
                faceConfiguration.detection.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.landmarks.isEnabled = true;
                faceConfiguration.landmarks.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.pose.isEnabled = true;
                faceConfiguration.pose.smoothingLevel = PXCMFaceConfiguration.SmoothingLevelType.SMOOTHING_DISABLED;

                faceConfiguration.DisableAllAlerts();

                faceConfiguration.strategy = PXCMFaceConfiguration.TrackingStrategyType.STRATEGY_APPEARANCE_TIME;

                if ((NumberOfDetectedFaces < 1) || (NumberOfDetectedFaces > 15))
                {
                    Debug.Log("Ilegal value for Number Of Detected Faces, value is set to 1");
                    NumberOfDetectedFaces = 1;
                }

                faceConfiguration.detection.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.landmarks.maxTrackedFaces = NumberOfDetectedFaces;
                faceConfiguration.pose.maxTrackedFaces = NumberOfDetectedFaces;

                PXCMFaceConfiguration.ExpressionsConfiguration expressionConfig = faceConfiguration.QueryExpressions();
                expressionConfig.Enable();
                expressionConfig.EnableAllExpressions();

                faceConfiguration.ApplyChanges();
                faceConfiguration.Dispose();

                FaceModuleOutput = faceModule.CreateOutput();

                UnsetSenseOption(SenseOption.SenseOptionID.VideoColorStream);
            }

            // Hand
            if (IsSenseOptionSet(SenseOption.SenseOptionID.Hand, true))
            {
                PXCMHandModule handAnalysis = SenseManager.QueryHand();

                PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration();
                if (handConfiguration == null) throw new UnityException("CreateActiveConfiguration returned null");

                handConfiguration.Update();
                handConfiguration.EnableAllGestures();
                handConfiguration.EnableStabilizer(true);
                handConfiguration.DisableAllAlerts();
                handConfiguration.EnableSegmentationImage(false);
                handConfiguration.ApplyChanges();
                handConfiguration.Dispose();

                HandDataOutput = handAnalysis.CreateOutput();
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Object, true))
            {
                if (_senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Object).Enabled != true)
                {
                    _senseOptions.Find( i => i.ID == SenseOption.SenseOptionID.Object).Enabled = true;
                    OnDisable();
                    OnEnable();
                }
            }

            if (IsSenseOptionSet(SenseOption.SenseOptionID.Speech, true))
            {
                UpdateSpeechCommands();
                SpeechManager.Start();
            }

            // Create an instance for the projection & blob extractor

            if (Projection == null)
            {
                Projection = SenseManager.QueryCaptureManager().QueryDevice().CreateProjection();
            }

            if (BlobExtractor == null)
            {
                SenseManager.session.CreateImpl<PXCMBlobExtractor>(out BlobExtractor);
            }

            // Set initialization flag
            Initialized = true;
        }
    public void SetManualMode()
    {
        // REALSENSE 

        /* Initialize a PXCMSenseManager instance */
        sm = PXCMSenseManager.CreateInstance();
        if (sm == null)
            Debug.LogError("SenseManager Initialization Failed");

        /* Enable hand tracking and retrieve an hand module instance to configure */
        sts = sm.EnableHand();
        handAnalyzer = sm.QueryHand();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
            Debug.LogError("PXCSenseManager.EnableHand: " + sts);

        /* Initialize the execution pipeline */
        sts = sm.Init();
        if (sts != pxcmStatus.PXCM_STATUS_NO_ERROR)
            Debug.LogError("PXCSenseManager.Init: " + sts);

        /* Retrieve the the DataSmoothing instance */
        sm.QuerySession().CreateImpl<PXCMSmoother>(out smoother);

        /* Create a 3D Weighted algorithm */
        smoother3D = new PXCMSmoother.Smoother3D[MaxHands][];

        /* Configure a hand - Enable Gestures and Alerts */
        PXCMHandConfiguration hcfg = handAnalyzer.CreateActiveConfiguration();
        if (hcfg != null)
        {
            hcfg.EnableAllGestures();
            hcfg.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);
            hcfg.SubscribeGesture(OnFiredGesture);
            hcfg.ApplyChanges();
            hcfg.Dispose();
        }



      //  handAnalyzer = sm.QueryHand();

        //////

        curMode = userMode = DroneMode.Manual;
        targetBehavior = targetDirectBehavior;
        EnterFreeMovementState();
    }
        private void InitRealSense()
        {
            this.releaseInstances();

            errorManager = new ErrorManager();

            this.manager = PXCMSenseManager.CreateInstance();
            if (manager == null)
            {
                errorManager.InitError("PXCMSenseManager::Create");
            }

            // Init hand module
            errorManager.RunWithStatusCheck(() => manager.EnableHand(), "PXCMHandModule");
            this.handModule = this.manager.QueryHand();
            this.handData = this.handModule.CreateOutput();

            // config hand module
            var hconfig = this.handModule.CreateActiveConfiguration();

            hconfig.EnableTrackedJoints(true);

            //Gestures
            hconfig.DisableAllGestures();

            //alerts========================================================
            hconfig.DisableAllAlerts();
            hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_CALIBRATED);

            //hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_DETECTED);
            hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED);

            // For hand tracking
            hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_INSIDE_BORDERS);
            hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_OUT_OF_BORDERS);

            // For user info
            hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_TOO_CLOSE);
            hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_TOO_FAR);

            hconfig.SubscribeAlert(OnAlertFired);
            //alerts=========================================================

            hconfig.ApplyChanges();
            hconfig.Dispose();

            // Init touchless controller:: Move tracking
            errorManager.RunWithStatusCheck(() => manager.EnableTouchlessController(), "TouchlessController");
            this.touchController = this.manager.QueryTouchlessController();

            // On processed frame callback
            PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler {
                onModuleProcessedFrame = OnFrameProcessed
            };
            // UX events callback
            this.touchController.SubscribeEvent(OnTouchlessControllerUxEvent);

            // Init Sense manager
            errorManager.RunWithStatusCheck(() => manager.Init(handler), "PXCMSenseManager::Init");
            errorManager.RunWithStatusCheck(() => manager.StreamFrames(false), "PXCMSenseManager::StreamFrames");

            if (this.manager.captureManager == null || this.manager.captureManager.device == null)
            {
                throw new NoDeviceException();
            }

            // Query scene info
            PXCMCapture.Sample sample = null;
            do {
                sample = manager.QuerySample();
            }
            while (sample == null || sample.depth == null || sample.depth.info == null);
            sceneXCenter = sample.depth.info.width / 2;
            sceneYCenter = sample.depth.info.height / 2;

            //Set delay before close gesture ability
            Task.Factory.StartNew(() =>
            {
                Thread.Sleep(3000);
                delayForCloseAchived = true;
                this.handData.Update();
                handInsideBorders = this.handData.QueryNumberOfHands() > 0;
            });

            // Hand tracking started.
            started = true;
        }