Пример #1
0
        void Update()
        {
            //Dynamically Pause/Enable Modules
            int numberOfEnabledModules = 0;

            foreach (var option in _senseOptions)
            {
                if (option.RefCounter == 0 && option.Enabled)
                {
                    if (option.ModuleCUID > 0)
                    {
                        SenseManager.PauseModule(option.ModuleCUID, true);
                    }
                    option.Enabled = false;
                }
                else if (option.RefCounter > 0 && !option.Enabled)
                {
                    if (!option.Initialized)
                    {
                        OnDisable();
                        OnEnable();
                        Start();
                    }
                    if (option.ModuleCUID > 0)
                    {
                        SenseManager.PauseModule(option.ModuleCUID, false);
                    }
                    option.Enabled = true;
                }

                if (option.Enabled)
                {
                    numberOfEnabledModules++;
                }
            }

            //Update Speech commands if changed
            if (_speechCommandsChanged)
            {
                UpdateSpeechCommands();
                SpeechManager.Reset();
            }

            // Every frame update all the data
            if (Initialized && numberOfEnabledModules > 0)
            {
                _sts = SenseManager.AcquireFrame(true, 100);
                if (_sts == pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoColorStream).Enabled)
                    {
                        if (ImageRgbOutput != null)
                        {
                            ImageRgbOutput.Dispose();
                        }

                        if (_captureSample == null)
                        {
                            _captureSample = SenseManager.QuerySample();
                        }

                        if (_captureSample.color != null)
                        {
                            ImageRgbOutput = _captureSample.color;
                            ImageRgbOutput.QueryInstance <PXCMAddRef>().AddRef();
                        }
                    }
                    if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoDepthStream).Enabled ||
                        _senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.PointCloud).Enabled)
                    {
                        if (ImageDepthOutput != null)
                        {
                            ImageDepthOutput.Dispose();
                        }

                        if (_captureSample == null)
                        {
                            _captureSample = SenseManager.QuerySample();
                        }

                        if (_captureSample.depth != null)
                        {
                            ImageDepthOutput = _captureSample.depth;
                            ImageDepthOutput.QueryInstance <PXCMAddRef>().AddRef();

                            if (!_isInitBlob)
                            {
                                PXCMImage.ImageInfo info = ImageDepthOutput.QueryInfo();
                                BlobExtractor.Init(info);
                                BlobExtractor.SetMaxBlobs(MaxBlobsToDetect);
                                _isInitBlob = true;
                            }


                            if (PointCloud == null)
                            {
                                PointCloud = new PXCMPoint3DF32[ImageDepthOutput.info.width * ImageDepthOutput.info.height];
                            }

                            if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.PointCloud).Enabled)
                            {
                                if (PointCloud == null)
                                {
                                    PointCloud = new PXCMPoint3DF32[ImageDepthOutput.info.width * ImageDepthOutput.info.height];
                                }

                                _sts = Projection.QueryVertices(ImageDepthOutput, PointCloud);
                            }

                            if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.UVMap).Enabled)
                            {
                                if (UvMap == null)
                                {
                                    UvMap = new PXCMPointF32[ImageDepthOutput.info.width * ImageDepthOutput.info.height];
                                }

                                Projection.QueryUVMap(ImageDepthOutput, UvMap);
                            }
                        }
                    }
                    if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoIRStream).Enabled)
                    {
                        if (ImageIROutput != null)
                        {
                            ImageIROutput.Dispose();
                        }

                        if (_captureSample == null)
                        {
                            _captureSample = SenseManager.QuerySample();
                        }

                        if (_captureSample.ir != null)
                        {
                            ImageIROutput = _captureSample.ir;
                            ImageIROutput.QueryInstance <PXCMAddRef>().AddRef();
                        }
                    }

                    if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.VideoSegmentation).Enabled)
                    {
                        if (Image3DSegmentationOutput != null)
                        {
                            Image3DSegmentationOutput.Dispose();
                        }

                        PXCM3DSeg seg = SenseManager.Query3DSeg();

                        if (seg != null)
                        {
                            Image3DSegmentationOutput = seg.AcquireSegmentedImage();
                        }
                    }

                    if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Face).Enabled)
                    {
                        FaceModuleOutput.Update();
                    }

                    if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Hand).Enabled)
                    {
                        HandDataOutput.Update();
                    }

                    _captureSample = null;

                    SenseManager.ReleaseFrame();
                }

                //Speech
                if (_senseOptions.Find(i => i.ID == SenseOption.SenseOptionID.Speech).Enabled)
                {
                    SpeechManager.QueryRecognizedCommands(out SpeechOutput);
                }
            }
        }
        void Start()
        {
            sm = mask_utils.PipelineManager.session.CreateSenseManager();
            if (sm == null)
            {
                return;
            }

            mask_utils.PipelineManager.session.CreateImpl <PXCMBlobExtractor>(out m_blob);
            if (m_blob == null)
            {
                return;
            }

            mask_utils.PipelineManager.session.CreateImpl <PXCMContourExtractor>(out m_contour);
            if (m_contour == null)
            {
                return;
            }

            /* request depth stream as part of the pipeline*/
            sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480);

            /* Initialize the pipeline*/
            if (sm.Init() == pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                /* Query available capture devices and make sure we have a valid RS device*/
                PXCMCapture.DeviceInfo dinfo;
                sm.QueryCaptureManager().QueryDevice().QueryDeviceInfo(out dinfo);
                if (dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM)
                {
                    /* Set the depth stream confidence threshold value - Any depth pixels with a confidence score below the threshold will be set to the low confidence pixel value*/
                    sm.QueryCaptureManager().QueryDevice().SetDepthConfidenceThreshold(10);
                    /* Set the smoothing aggressiveness parameter - High smoothing effect for distances between 850mm to 1000mm bringing good accuracy with moderate sharpness level.*/
                    sm.QueryCaptureManager().QueryDevice().SetIVCAMFilterOption(6);
                }

                /* The BlobData structure describes the parameters of the detected blob*/
                blobData   = new PXCMBlobExtractor.BlobData[2];
                pointOuter = new PXCMPointI32[2][];
                pointInner = new PXCMPointI32[2][];

                /* Set Blob tracking parameters */
                float bSmooth = mask_utils.PipelineManager.BlobSmoothing;
                m_blob.SetSmoothing(bSmooth);

                float maxDepth = mask_utils.PipelineManager.MaxBlobDepth;
                m_blob.SetMaxDistance(maxDepth);

                int maxBlobs = mask_utils.PipelineManager.MaxBlobs;
                m_blob.SetMaxBlobs(maxBlobs);

                /* Set Contour smoothing parameters */
                float contourSmooth = mask_utils.PipelineManager.ContourSmoothing;
                m_contour.SetSmoothing(contourSmooth);
            }
            else
            {
                OnDisable();
            }
        }