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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        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);
            }
        }
    // 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();
                }
            }
        }
    }
 void SetHandConfig()
 {
     config = handAnalyzer.CreateActiveConfiguration();
     config.EnableAllGestures();
     config.EnableAllAlerts();
     config.ApplyChanges();
     config.Dispose();
 }
Esempio n. 6
0
        public Camera()
        {
            this.action = new Action();

            this.rockCounter = 0;

            directionTimer          = new System.Timers.Timer(1000);
            directionTimer.Elapsed += directionTimer_Elapsed;

            pinchTimer          = new System.Timers.Timer(500);
            pinchTimer.Elapsed += pinchTimer_Elapsed;

            rockTimer          = new System.Timers.Timer(300);
            rockTimer.Elapsed += rockTimer_Elapsed;

            // Create the manager
            this._session = PXCMSession.CreateInstance();
            this._mngr    = this._session.CreateSenseManager();

            // streammmm
            PXCMVideoModule.DataDesc desc = new PXCMVideoModule.DataDesc();
            desc.deviceInfo.streams = PXCMCapture.StreamType.STREAM_TYPE_COLOR | PXCMCapture.StreamType.STREAM_TYPE_DEPTH;
            this._mngr.EnableStreams(desc);
            //this._mngr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, Camera.WIDTH, Camera.HEIGHT, 30);
            //this._mngr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, Camera.WIDTH, Camera.HEIGHT, 30);


            // Hands
            this._mngr.EnableHand();
            this._hand     = this._mngr.QueryHand();
            this._handData = this._hand.CreateOutput();

            // Hands config
            PXCMHandConfiguration conf = this._hand.CreateActiveConfiguration();

            conf.EnableGesture("two_fingers_pinch_open", true);

            // Subscribe hands alerts
            conf.EnableAllAlerts();
            //conf.SubscribeAlert(this.onFiredAlert);

            conf.EnableTrackedJoints(true);

            // and the private one for debug
            //conf.SubscribeGesture(this.onFiredGesture);

            // Apply it all
            conf.ApplyChanges();

            // Set events
            this._handler = new PXCMSenseManager.Handler();
            this._handler.onModuleProcessedFrame = this.onModuleProcessedFrame;

            this._mngr.Init(this._handler);
        }
Esempio n. 7
0
        public Camera(params PXCMHandConfiguration.OnFiredGestureDelegate[] dlgts)
        {
            // Create the manager
            this._session = PXCMSession.CreateInstance();
            this._mngr    = this._session.CreateSenseManager();

            // streammmm
            PXCMVideoModule.DataDesc desc = new PXCMVideoModule.DataDesc();
            desc.deviceInfo.streams = PXCMCapture.StreamType.STREAM_TYPE_COLOR | PXCMCapture.StreamType.STREAM_TYPE_DEPTH;
            this._mngr.EnableStreams(desc);
            //this._mngr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, Camera.WIDTH, Camera.HEIGHT, 30);
            //this._mngr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, Camera.WIDTH, Camera.HEIGHT, 30);


            // Hands
            this._mngr.EnableHand();
            this._hand     = this._mngr.QueryHand();
            this._handData = this._hand.CreateOutput();

            // Hands config
            PXCMHandConfiguration conf = this._hand.CreateActiveConfiguration();

            conf.EnableGesture("spreadfingers", false);
            conf.EnableGesture("thumb_up", false);

            // Subscribe hands alerts
            conf.EnableAllAlerts();
            conf.SubscribeAlert(this.onFiredAlert);

            // Subscribe all gestures
            foreach (PXCMHandConfiguration.OnFiredGestureDelegate subscriber in dlgts)
            {
                conf.SubscribeGesture(subscriber);
            }

            // and the private one for debug
            conf.SubscribeGesture(this.onFiredGesture);

            // Apply it all
            conf.ApplyChanges();

            // Set events
            this._handler = new PXCMSenseManager.Handler();
            this._handler.onModuleProcessedFrame = this.onModuleProcessedFrame;

            this._mngr.Init(this._handler);
        }
        private void ConfigureHandModule()
        {
            timerCount = Stopwatch.StartNew();
            hand       = senseManager.QueryHand();
            handConfig = hand.CreateActiveConfiguration();
            handConfig.EnableGesture("spreadfingers");
            handConfig.EnableGesture("two_fingers_pinch_open");
            handConfig.EnableGesture("wave");
            handConfig.EnableGesture("swipe");
            handConfig.EnableGesture("swipe_left");
            handConfig.EnableGesture("swipe_right");
            handConfig.EnableGesture("fist");
            handConfig.EnableGesture("thumb_up");

            handConfig.EnableAllAlerts();
            handConfig.ApplyChanges();
        }
Esempio n. 9
0
 public override void Init(PXCMSenseManager sManager)
 {
     this.senseManager = sManager;
     hand       = senseManager.QueryHand();
     face       = senseManager.QueryFace();
     handConfig = hand.CreateActiveConfiguration();
     handConfig.EnableGesture("wave");
     handConfig.EnableAllAlerts();
     handConfig.ApplyChanges();
     faceConfic = face.CreateActiveConfiguration();
     faceConfic.QueryExpressions();
     faceConfic.EnableAllAlerts();
     faceConfic.ApplyChanges();
     PXCMFaceConfiguration.ExpressionsConfiguration expc = faceConfic.QueryExpressions();
     expc.Enable();
     expc.EnableAllExpressions();
     faceConfic.ApplyChanges();
     Console.WriteLine("init smile done");
 }
        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();
        }
    // 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();
                }
            }
        }
    }
Esempio n. 12
0
		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);
			}
		}
Esempio n. 13
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");
            }
        }
Esempio n. 14
0
        // 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();
            }
        }
Esempio n. 15
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();
        }
Esempio n. 16
0
 public HandAlertManager(PXCMHandConfiguration handConfig)
 {
     this.statusValues = new Dictionary <int, HandStatus>();
     handConfig.EnableAllAlerts();
     handConfig.SubscribeAlert(this.OnAlert);
 }
Esempio n. 17
0
        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();
        }
Esempio n. 18
0
 private void ConfigureHandModule()
 {
     hand = senseManager.QueryHand();
               handConfig = hand.CreateActiveConfiguration();
     //          handConfig.EnableGesture("spreadfingers");
     //        handConfig.EnableGesture("two_fingers_pinch_open");
     //      handConfig.EnableGesture("wave");
         handConfig.EnableAllAlerts();
         handConfig.ApplyChanges();
 }
Esempio n. 19
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;
        }