// Use this for initialization
    void Start()
    {
        //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.SetTrackingMode(PXCMHandData.TrackingModeType.TRACKING_MODE_EXTREMITIES);
                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();
                }
            }
        }
    }
Example #2
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();
        }
Example #3
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>();
        }
Example #4
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();
        }
Example #5
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();
    }