Esempio n. 1
0
        private void DoWork()
        {
            try
            {
                while (!manager.Stop)
                {
                    RS.Sample sample = manager.GetSample();

                    streams.RenderStreams(sample);
                    //manager.ShowPerformanceTick();
                    handsRecognition.RecogniseHands(sample); //Todo
                    manager.SenseManager.ReleaseFrame();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(null, e.ToString(), "Error while Recognition", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            Invoke(new DoWorkEnd(
                       delegate
            {
                buttonStart.Enabled = true;
                buttonStop.Enabled  = false;
                menuStrip.Enabled   = true;
                ActivateGestureCheckboxes(true);
                manager.SenseManager.Close();
                if (closing)
                {
                    Close();
                }
            }
                       ));
        }
Esempio n. 2
0
        public void RenderStreams(RS.Sample sample)
        {
            /* Render streams */
            EventHandler <RenderFrameEventArgs> render = RenderFrame;

            RS.Image image = null;
            if (StreamType != RS.StreamType.STREAM_TYPE_ANY && render != null)
            {
                // ???????????????????????
                image = sample[StreamType];
                render(this, new RenderFrameEventArgs(0, image));
                //render(this, new RenderFrameEventArgs(1, image));
            }
        }
 public RS.Sample GetSample()
 {
     RS.Sample sample = null;
     /* Wait until a frame is ready: Synchronized or Asynchronous */
     if (SenseManager.AcquireFrame(false) == RS.Status.STATUS_NO_ERROR)
     {
         /* Aquire Frame from Camera */
         sample = SenseManager.Sample;
         return(sample);
     }
     else
     {
         return(sample = null);
     }
 }
Esempio n. 4
0
        public void RenderStreams(RS.Sample sample)
        {
            /* Render streams */
            EventHandler <RenderFrameEventArgs> render = RenderFrame;

            RS.Image image = null;
            if (render != null)
            {
                image = sample[RS.StreamType.STREAM_TYPE_COLOR];
                render(this, new RenderFrameEventArgs(0, image));

                if (StreamType == RS.StreamType.STREAM_TYPE_ANY)
                {
                    return;
                }
                else
                {
                    image = sample[StreamType];
                    render(this, new RenderFrameEventArgs(1, image));
                }
            }
        }
Esempio n. 5
0
        public void StreamColorDepth() /* Stream Color and Depth Synchronously or Asynchronously */
        {
            try
            {
                bool sts = true;

                /* Create an instance of the RS.SenseManager interface */
                RS.SenseManager sm = RS.SenseManager.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 < RS.Capture.STREAM_LIMIT; s++)
                    {
                        RS.StreamType    st   = RS.Capture.StreamTypeFromIndex(s);
                        RS.StreamProfile info = StreamProfileSet[st];
                        if (info.imageInfo.format != 0)
                        {
                            /* For simple request, you can also use sm.EnableStream(...) */
                            RS.DataDesc desc = new RS.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;
                            desc.receivePartialSample       = true;
                            RS.SampleReader sampleReader = RS.SampleReader.Activate(sm);
                            sampleReader.EnableStreams(desc);
                        }
                    }
                }

                /* Initialization */


                SetStatus("Init Started");
                if (sm.Init() >= RS.Status.STATUS_NO_ERROR)
                {
                    /* Reset all properties */
                    sm.CaptureManager.Device.ResetProperties(RS.StreamType.STREAM_TYPE_ANY);

                    /* Set mirror mode */
                    RS.MirrorMode mirror = Mirror ? RS.MirrorMode.MIRROR_MODE_HORIZONTAL : RS.MirrorMode.MIRROR_MODE_DISABLED;
                    sm.CaptureManager.Device.MirrorMode = mirror;

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

                        /* Display images */
                        RS.Sample sample = sm.Sample;

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

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

                        /* Optional: Set Mirror State */
                        mirror = Mirror ? RS.MirrorMode.MIRROR_MODE_HORIZONTAL : RS.MirrorMode.MIRROR_MODE_DISABLED;
                        if (mirror != sm.CaptureManager.Device.MirrorMode)
                        {
                            sm.CaptureManager.Device.MirrorMode = mirror;
                        }

                        /* Optional: Show performance tick */



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

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