Exemple #1
0
        public RealsenseManager(bool isDataOnly)
        {
            sm = RS.SenseManager.CreateInstance();
            if (!isDataOnly)
            {
                rgbReader   = RS.SampleReader.Activate(sm);
                depthReader = RS.SampleReader.Activate(sm);
                rgbReader.EnableStream(RS.StreamType.STREAM_TYPE_COLOR);
                depthReader.EnableStream(RS.StreamType.STREAM_TYPE_DEPTH);
                rgbReader.SampleArrived   += RgbReader_SampleArrived;
                depthReader.SampleArrived += DepthReader_SampleArrived;
            }
            // config hand


            handModule = HandModule.Activate(sm);
            handConfig = handModule.CreateActiveConfiguration();
            handConfig.TrackedJointsEnabled = true;
            handConfig.StabilizerEnabled    = true;
            handConfig.TrackingMode         = TrackingModeType.TRACKING_MODE_FULL_HAND;
            handConfig.ApplyChanges();
            handData = handModule.CreateOutput();

            handModule.FrameProcessed += HandModule_FrameProcessed;
        }
Exemple #2
0
 // Activate Hand Module
 void SetupHandModule()
 {
     depthCameraManager = GetComponent <DepthCameraManger>();
     handModule         = HandModule.Activate(depthCameraManager.senseManager);
     if (handModule == null)
     {
         throw new System.Exception("Failed Loading Hand Module");
     }
     else
     {
         Debug.Log(TAG + "Hand Module is loaded successful");
         SetupHandConfiguration();
     }
 }
        public void SetUpHandModule()
        {
            /* Set Module */

            handModule = HandModule.Activate(manager.SenseManager);

            if (handModule == null)
            {
                manager.SetStatus("Failed Loading Module");
                manager.Stop = true;
                return;
            }

            HandConfiguration = handModule.CreateActiveConfiguration();
            if (HandConfiguration == null)
            {
                manager.SetStatus("Failed Create Configuration");
                manager.Stop = true;
                return;
            }

            handData = handModule.CreateOutput();
            if (handData == null)
            {
                manager.SetStatus("Failed Create Output");
                HandConfiguration.Dispose();
                manager.Stop = true;
                return;
            }

            HandConfiguration.TrackingMode         = TrackingModeType.TRACKING_MODE_FULL_HAND;
            HandConfiguration.TrackedJointsEnabled = true;
            HandConfiguration.EnableJointSpeed(JointType.JOINT_INDEX_TIP, JointSpeedType.JOINT_SPEED_ABSOLUTE, 20);
            HandConfiguration.StabilizerEnabled = true;
            HandConfiguration.EnableAllAlerts();
            HandConfiguration.SegmentationImageEnabled = false;
            HandConfiguration.SmoothingValue           = 1; // The value is from 0(not smoothed) to 1(smoothed motion).

            HandConfiguration.ApplyChanges();
        }
Exemple #4
0
        /* Using SenseManager to handle data */
        public void SimplePipeline()
        {
            _form.UpdateInfo(String.Empty, System.Drawing.Color.Black);
            bool liveCamera = false;

            bool         flag     = true;
            SenseManager instance = null;

            _disconnected = false;
            instance      = _form.session.CreateSenseManager();
            if (instance == null)
            {
                _form.UpdateStatus("Failed creating SenseManager");
                _form.EnableTrackingMode(true);
                return;
            }
            CaptureManager captureManager = instance.CaptureManager;
            DeviceInfo     info           = null;

            if (captureManager != null)
            {
                if (_form.GetPlaybackState())
                {
                    captureManager.SetFileName(_form.GetFileName(), false);
                    info = _form.GetDeviceFromFileMenu(_form.GetFileName());
                }
                else
                {
                    if (_form.Devices.Count == 0)
                    {
                        _form.UpdateStatus("No device were found");
                        return;
                    }

                    _form.Devices.TryGetValue(_form.GetCheckedDevice(), out info);


                    if (_form.GetRecordState())
                    {
                        captureManager.SetFileName(_form.GetFileName(), true);
                        if (_form.Devices.TryGetValue(_form.GetCheckedDevice(), out info))
                        {
                            captureManager.FilterByDeviceInfo(_form.GetCheckedDeviceInfo());
                        }
                    }
                    else
                    {
                        captureManager.FilterByDeviceInfo(_form.GetCheckedDeviceInfo());
                        liveCamera = true;
                    }
                    if (info == null)
                    {
                        _form.UpdateStatus("Device Failure");
                        return;
                    }
                }
            }
            /* Set Module */

            HandModule handAnalysis;

            // SenseManager.Handler handler = new SenseManager Handler();
            // handler.onModuleProcessedFrame = new SenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame);


            HandConfiguration handConfiguration = null;
            HandData          handData          = null;



            handAnalysis = HandModule.Activate(instance);

            if (handAnalysis == null)
            {
                _form.UpdateStatus("Failed Loading Module");
                _form.EnableTrackingMode(true);

                return;
            }

            handConfiguration = handAnalysis.CreateActiveConfiguration();
            if (handConfiguration == null)
            {
                _form.UpdateStatus("Failed Create Configuration");
                _form.EnableTrackingMode(true);
                instance.Close();
                instance.Dispose();
                return;
            }
            handData = handAnalysis.CreateOutput();
            if (handData == null)
            {
                _form.UpdateStatus("Failed Create Output");
                _form.EnableTrackingMode(true);
                handConfiguration.Dispose();
                instance.Close();
                instance.Dispose();
                return;
            }


            FPSTimer timer = new FPSTimer(_form);

            _form.UpdateStatus("Init Started");

            if (instance.Init() == Status.STATUS_NO_ERROR)
            {
                DeviceInfo  dinfo;
                DeviceModel dModel = DeviceModel.DEVICE_MODEL_F200;
                Device      device = instance.CaptureManager.Device;
                if (device != null)
                {
                    device.QueryDeviceInfo(out dinfo);
                    dModel    = dinfo.model;
                    _maxRange = device.DepthSensorRange.max;
                }


                if (handConfiguration != null)
                {
                    TrackingModeType trackingMode = TrackingModeType.TRACKING_MODE_FULL_HAND;

                    if (_form.GetFullHandModeState())
                    {
                        trackingMode = TrackingModeType.TRACKING_MODE_FULL_HAND;
                    }

                    handConfiguration.TrackingMode = trackingMode;

                    handConfiguration.EnableAllAlerts();
                    handConfiguration.SegmentationImageEnabled = true;
                    bool isEnabled = handConfiguration.SegmentationImageEnabled;

                    handConfiguration.ApplyChanges();


                    _form.resetGesturesList();
                    int totalNumOfGestures = handConfiguration.NumberOfGestures;

                    if (totalNumOfGestures > 0)
                    {
                        this._form.UpdateGesturesToList("", 0);
                        for (int i = 0; i < totalNumOfGestures; i++)
                        {
                            string gestureName = string.Empty;
                            if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) ==
                                Status.STATUS_NO_ERROR)
                            {
                                this._form.UpdateGesturesToList(gestureName, i + 1);
                            }
                        }

                        _form.UpdateGesturesListSize();
                    }
                }



                _form.UpdateStatus("Streaming");
                int frameCounter = 0;
                int frameNumber  = 0;

                while (!_form.stop)
                {
                    string gestureName = _form.GetGestureName();
                    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 (instance.AcquireFrame(true) < Status.STATUS_NO_ERROR)
                    {
                        break;
                    }

                    frameCounter++;

                    if (!DisplayDeviceConnection(!instance.IsConnected()))
                    {
                        Sample sample = instance.Sample;

                        if (sample != null && sample.Depth != null)
                        {
                            frameNumber = liveCamera ? frameCounter : instance.CaptureManager.FrameIndex;

                            if (handData != null)
                            {
                                handData.Update();

                                DisplayPicture(sample.Depth, handData);
                                DisplayGesture(handData, frameNumber);
                                DisplayJoints(handData);
                                DisplayAlerts(handData, frameNumber);
                            }


                            _form.UpdatePanel();
                        }
                        timer.Tick();
                    }
                    instance.ReleaseFrame();
                }
            }
            else
            {
                _form.UpdateStatus("Init Failed");
                flag = false;
            }
            foreach (Image Image in _mImages)
            {
                Image.Dispose();
            }

            // Clean Up
            if (handData != null)
            {
                handData.Dispose();
            }
            if (handConfiguration != null)
            {
                handConfiguration.Dispose();
            }

            instance.Close();
            instance.Dispose();

            if (flag)
            {
                _form.UpdateStatus("Stopped");
            }
        }