private void Start()
    {
        resolutionText.text = "Resolution: " + m_colorWidth + "x" + m_colorHeight;

        if (m_senseManager == null)
        {
            // Create a SenseManager instance
            m_senseManager = PXCMSenseManager.CreateInstance();
            if (m_senseManager == null)
            {
                Debug.Log("SenseManager Instance Failed");
                return;
            }

            // Enable color stream only
            PXCMVideoModule.DataDesc ddesc = new PXCMVideoModule.DataDesc();
            ddesc.streams.color.sizeMin.width  = ddesc.streams.color.sizeMax.width = m_colorWidth;
            ddesc.streams.color.sizeMin.height = ddesc.streams.color.sizeMax.height = m_colorHeight;
            ddesc.streams.color.frameRate.min  = ddesc.streams.color.frameRate.max = m_fps;
            m_senseManager.EnableStreams(ddesc);
        }
    }
示例#2
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)
                {
                    SetStatus("Failed to create an SDK pipeline object");
                    return;
                }

                /* Optional: if playback or recoridng */
                if ((Playback || Record) && File != null)
                {
                    sm.captureManager.SetFileName(File, Record);
                }

                /* Optional: Set Input Source */
                if (!Playback && DeviceInfo != null)
                {
                    sm.captureManager.FilterByDeviceInfo(DeviceInfo);
                }

                /* Set Color & Depth Resolution and enable streams */
                if (StreamProfileSet != null)
                {
                    /* Optional: Filter the data based on the request */
                    sm.captureManager.FilterByStreamProfiles(StreamProfileSet);

                    /* Enable raw data streaming for specific stream types */
                    for (int s = 0; s < PXCMCapture.STREAM_LIMIT; s++)
                    {
                        PXCMCapture.StreamType           st   = PXCMCapture.StreamTypeFromIndex(s);
                        PXCMCapture.Device.StreamProfile info = StreamProfileSet[st];
                        if (info.imageInfo.format != 0)
                        {
                            /* For simple request, you can also use sm.EnableStream(...) */
                            PXCMVideoModule.DataDesc desc = new PXCMVideoModule.DataDesc();
                            desc.streams[st].frameRate.min  = desc.streams[st].frameRate.max = info.frameRate.max;
                            desc.streams[st].sizeMin.height = desc.streams[st].sizeMax.height = info.imageInfo.height;
                            desc.streams[st].sizeMin.width  = desc.streams[st].sizeMax.width = info.imageInfo.width;
                            desc.streams[st].options        = info.options;
                            sm.EnableStreams(desc);
                        }
                    }
                }

                /* Initialization */
                Timer timer = new Timer();
                timer.UpdateStatus += UpdateStatus;

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

                    /* Set mirror mode */
                    PXCMCapture.Device.MirrorMode mirror = Mirror ? PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL : PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED;
                    sm.captureManager.device.SetMirrorMode(mirror);

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

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

                        /* Render streams */
                        EventHandler <RenderFrameEventArgs> render = RenderFrame;
                        PXCMImage image = null;
                        if (ColorPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            image = sample[ColorPanel];
                            render(this, new RenderFrameEventArgs(0, image));
                        }

                        if (DepthPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(1, sample[DepthPanel]));
                        }

                        if (IRPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(2, sample[IRPanel]));
                        }

                        if (IRLeftPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(3, sample[IRLeftPanel]));
                        }

                        if (IRRightPanel != PXCMCapture.StreamType.STREAM_TYPE_ANY && render != null)
                        {
                            render(this, new RenderFrameEventArgs(4, sample[IRRightPanel]));
                        }

                        /* Optional: Set Mirror State */
                        mirror = Mirror ? PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL : PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED;
                        if (mirror != sm.captureManager.device.QueryMirrorMode())
                        {
                            sm.captureManager.device.SetMirrorMode(mirror);
                        }

                        /* Optional: Show performance tick */
                        if (image != null)
                        {
                            timer.Tick(PXCMImage.PixelFormatToString(image.info.format) + " " + image.info.width + "x" + image.info.height);
                        }

                        sm.ReleaseFrame();
                    }
                }
                else
                {
                    SetStatus("Init Failed");
                    sts = false;
                }

                sm.Dispose();
                if (sts)
                {
                    SetStatus("Stopped");
                }
            }
            catch (Exception e) {
                SetStatus(e.GetType().ToString());
            }
        }
        public pxcmStatus InitRecordPlay()
        {
            pxcmStatus status;

            _senseManager.Close();
            PXCMCaptureManager cm = _senseManager.QueryCaptureManager();

            if (Playback || Record)
            {
                status = cm.SetFileName(this.RecordedFile, this.Record);
                if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    _logger.info("Unable to set file name:" + status.ToString());
                    // return status;
                    throw new Smithers.Reading.FrameData.ScannerNotFoundException("Unable to set file record name");
                }
            }
            PXCMVideoModule.DataDesc desc = new PXCMVideoModule.DataDesc();
            if (cm.QueryCapture() != null && Playback)
            {
                //recordedFile = null;
                cm.SetRealtime(RealTime);
                cm.QueryCapture().QueryDeviceInfo(0, out desc.deviceInfo);
                status = _senseManager.EnableStreams(desc);
                if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    _logger.info("Unable to enable capture stream:" + status.ToString());
                    throw new Smithers.Reading.FrameData.ScannerNotFoundException("Unable to enable capture stream");
                }
            }
            else
            {
                status = _senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, Frame.COLOR_WIDTH, Frame.COLOR_HEIGHT, Frame.COLOR_RATE);
                if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    _logger.info("Unable to enable color stream:" + status.ToString());
                    throw new Smithers.Reading.FrameData.ScannerNotFoundException("Unable to enable color stream");
                }
                status = _senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, Frame.DEPTH_WIDTH, Frame.DEPTH_HEIGHT, Frame.DEPTH_RATE);
                if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    _logger.info("Unable to enable depth stream:" + status.ToString());
                    throw new Smithers.Reading.FrameData.ScannerNotFoundException("Unable to enable depth stream");
                }

                _logger.info("Depth Stream Enabled:" + status.ToString());
            }

            status = _senseManager.EnableScenePerception();
            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                _logger.info("Unable to enable scene perception:" + status.ToString());
                throw new Smithers.Reading.FrameData.ScannerNotFoundException("Scene Perception failed");
            }
            _logger.info("Scene Perception Enabled:" + status.ToString());

            _perceptionHandle = _senseManager.QueryScenePerception();

            status = _senseManager.Init();
            if (status != pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                _logger.info("Unable to open sensor in the above mode:" + status.ToString());
                throw new Smithers.Reading.FrameData.ScannerNotFoundException("Init failed");
            }

            _logger.info("Sensor Initialized Successfully:" + status.ToString());
            return(status);
        }