Esempio n. 1
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();
        }