Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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 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);
        }
    }
Exemple #5
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;
        }
        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);
        }
Exemple #8
0
        internal string SetupStreams()
        {
            PXCMCapture.Device.StreamProfileSet profiles = new PXCMCapture.Device.StreamProfileSet();
            string Status = ""; //"Setup streams...\n\r";

            //COLOR
            if( (FStreamColorMode != null) && (FStreamColorMode[0].Index > 0)&& (FStreamColorMode[0].Name != "Disabled"))
            {
                var profileInfo = getProfile(PXCMCapture.StreamType.STREAM_TYPE_COLOR, FStreamColorMode[0].Name);
                if(EnableCaptureStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, profileInfo))
                {
                    profiles[PXCMCapture.StreamType.STREAM_TYPE_COLOR] = profileInfo;
                    Status += "RSSDK: Enabled stream " + FStreamColorMode[0].Name + "\n\r";
                }
            }

            //DEPTH
            if( (FStreamDepthMode != null) && (FStreamDepthMode[0].Index > 0) && (FStreamDepthMode[0].Name != "Disabled"))
            {
                var profileInfo = getProfile(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, FStreamDepthMode[0].Name);
                if(EnableCaptureStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, profileInfo))
                {
                    profiles[PXCMCapture.StreamType.STREAM_TYPE_DEPTH] = profileInfo;
                    Status += "RSSDK: Enabled stream " + FStreamDepthMode[0].Name + "\n\r";
                }
            }

            //IR
            if( (FStreamIRMode != null) && (FStreamIRMode[0].Index > 0) && (FStreamIRMode[0].Name != "Disabled") )
            {
                var profileInfo = getProfile(PXCMCapture.StreamType.STREAM_TYPE_IR, FStreamIRMode[0].Name);
                if(EnableCaptureStream(PXCMCapture.StreamType.STREAM_TYPE_IR, profileInfo))
                {
                    profiles[PXCMCapture.StreamType.STREAM_TYPE_IR] = profileInfo;
                    Status += "RSSDK: Enabled stream " + FStreamIRMode[0].Name + "\n\r";
                }
            }

            SenseSession.cm.FilterByStreamProfiles(profiles);

            //validate profileSet
            if(SenseSession.device.IsStreamProfileSetValid(profiles))
            {
                if(SenseSession.device.SetStreamProfileSet(profiles) ==  pxcmStatus.PXCM_STATUS_NO_ERROR)
                {
                    Status += "RSSDK: Profileset is valid\n\r";
                    SenseSession.Status = pxcmStatus.PXCM_STATUS_NO_ERROR;
                    FLogger.Log(LogType.Debug, "RSSDK: Profileset is valid");
                } //SenseSession.Configured
                else
                {
                    Status += "RSSDK: Profileset can not be set\n\r";
                    FLogger.Log(LogType.Debug, "RSSDK: Profileset can not be set");
                }
            }
            else
            {
                Status += "RSSDK: Profileset is not valid\n\r";
                FLogger.Log(LogType.Debug, "RSSDK: Profileset is not valid");
            }

            //setup sync streams
            if (FSync[0])
            {
                SenseSession.IsSynchronized = true;

                PXCMVideoModule.DataDesc ddesc=new PXCMVideoModule.DataDesc();
                if(FStreamColorMode[0].Name != "Disabled") ddesc.deviceInfo.streams|= PXCMCapture.StreamType.STREAM_TYPE_COLOR;
                if(FStreamDepthMode[0].Name != "Disabled") ddesc.deviceInfo.streams|= PXCMCapture.StreamType.STREAM_TYPE_DEPTH;
                if(FStreamIRMode[0].Name != "Disabled") ddesc.deviceInfo.streams|= PXCMCapture.StreamType.STREAM_TYPE_IR;
                SenseSession.Status = SenseSession.sm.EnableStreams(ddesc);
            }

            return Status;
        }