public RealSenseEngine() { m_session = PXCMSession.CreateInstance(); if (m_session == null) { throw new RealSenseEngineException("Failed to create a Session"); } m_senseManager = m_session.CreateSenseManager(); if (m_senseManager == null) { throw new RealSenseEngineException("Failed to create a SenseManager"); } pxcmStatus res = m_senseManager.EnableTouchlessController(); if (res != pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new RealSenseEngineException("Failed to Enable Touchless Controller"); } var handler = new PXCMSenseManager.Handler(); res = m_senseManager.Init(handler); if (res != pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new RealSenseEngineException("Failed to Init Handler"); } // getting touchless controller m_touchlessController = m_senseManager.QueryTouchlessController(); if (m_touchlessController == null) { throw new RealSenseEngineException("Failed to Query Touchless Controller"); } }
private void StartRealSense() { Console.WriteLine("Starting Touchless Controller"); pxcmStatus rc; // creating Sense Manager psm = PXCMSenseManager.CreateInstance(); Console.WriteLine("Creating SenseManager: " + psm == null ? "failed" : "success"); if (psm == null) { MessageBox.Show("Failed to create SenseManager!", "Failed", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(-1); } // work from file if a filename is given as command line argument string[] args = Environment.GetCommandLineArgs(); if (args.Length > 1) { psm.captureManager.SetFileName(args[1], false); } // Enable touchless controller in the multimodal pipeline rc = psm.EnableTouchlessController(null); Console.WriteLine("Enabling Touchless Controller: " + rc.ToString()); if (rc != pxcmStatus.PXCM_STATUS_NO_ERROR) { MessageBox.Show("Failed to enable touchless controller!", "Failed", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(-1); } // initialize the pipeline PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); rc = psm.Init(handler); Console.WriteLine("Initializing the pipeline: " + rc.ToString()); if (rc != pxcmStatus.PXCM_STATUS_NO_ERROR) { MessageBox.Show("Failed to initialize the pipeline!", "Failed", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(-1); } // getting touchless controller ptc = psm.QueryTouchlessController(); if (ptc == null) { MessageBox.Show("Failed to get touchless controller!", "Failed", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(-1); } ptc.SubscribeEvent(new PXCMTouchlessController.OnFiredUXEventDelegate(OnTouchlessControllerUXEvent)); }
// RS private void STButton_Click(object sender, RoutedEventArgs e) { EXButton.IsEnabled = true; STButton.IsEnabled = false; // init the sense manager _senseManager = PXCMSenseManager.CreateInstance(); // enable hand analysis in the multimodal pipeline _senseManager.EnableTouchlessController(); // init the pipeline if (_senseManager.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR) { MessageBox.Show("RealSense Camera init failed"); } // get an instance of the touchless control _touchlessController = _senseManager.QueryTouchlessController(); // register fo ux event _touchlessController.SubscribeEvent(OnTouchlessControllerUXEventHandler); //event _touchlessController.SubscribeAlert(OnFiredAlertEventHandler); //alert // configuration pxcmStatus rc; PXCMTouchlessController.ProfileInfo pInfo; rc = _touchlessController.QueryProfile(out pInfo); pInfo.config = PXCMTouchlessController.ProfileInfo.Configuration.Configuration_Allow_Zoom | PXCMTouchlessController.ProfileInfo.Configuration.Configuration_Allow_Selection | PXCMTouchlessController.ProfileInfo.Configuration.Configuration_Allow_Back; rc = _touchlessController.SetProfile(pInfo); // configure hand module _hand = _senseManager.QueryHand(); _handConfig = _hand.CreateActiveConfiguration(); _handConfig.EnableGesture("thumb_up", true); // true is importment _handConfig.EnableGesture("v_sign", true); _handConfig.SubscribeGesture(OnFiredGestureEventHandler); _handConfig.ApplyChanges(); // processing loop _processingThread = new Thread(new ThreadStart(ProcessingThread)); _processingThread.Start(); }
// system check private void JSButton_Click(object sender, RoutedEventArgs e) { bool passSysCheck = false; //check internet connection if (IsConnectedToInternet()) { passSysCheck = true; } else { Popwind_ShowInfo("Check Internet Connection"); return; } if (passSysCheck) { // init the sense manager _senseManager = PXCMSenseManager.CreateInstance(); _senseManager.EnableTouchlessController(); // init the pipeline if (_senseManager.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR) { passSysCheck = false; } if (_senseManager != null) { _senseManager.Dispose(); } } if (passSysCheck) { STButton.IsEnabled = true; Popwind_ShowInfo("Everything is good"); } else { Popwind_ShowInfo("Check the RealSense Camera"); } }
private void InitRealSense() { this.releaseInstances(); errorManager = new ErrorManager(); this.manager = PXCMSenseManager.CreateInstance(); if (manager == null) { errorManager.InitError("PXCMSenseManager::Create"); } // Init hand module errorManager.RunWithStatusCheck(() => manager.EnableHand(), "PXCMHandModule"); this.handModule = this.manager.QueryHand(); this.handData = this.handModule.CreateOutput(); // config hand module var hconfig = this.handModule.CreateActiveConfiguration(); hconfig.EnableTrackedJoints(true); //Gestures hconfig.DisableAllGestures(); //alerts======================================================== hconfig.DisableAllAlerts(); hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_CALIBRATED); //hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_DETECTED); hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_NOT_DETECTED); // For hand tracking hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_INSIDE_BORDERS); hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_OUT_OF_BORDERS); // For user info hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_TOO_CLOSE); hconfig.EnableAlert(PXCMHandData.AlertType.ALERT_HAND_TOO_FAR); hconfig.SubscribeAlert(OnAlertFired); //alerts========================================================= hconfig.ApplyChanges(); hconfig.Dispose(); // Init touchless controller:: Move tracking errorManager.RunWithStatusCheck(() => manager.EnableTouchlessController(), "TouchlessController"); this.touchController = this.manager.QueryTouchlessController(); // On processed frame callback PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler { onModuleProcessedFrame = OnFrameProcessed }; // UX events callback this.touchController.SubscribeEvent(OnTouchlessControllerUxEvent); // Init Sense manager errorManager.RunWithStatusCheck(() => manager.Init(handler), "PXCMSenseManager::Init"); errorManager.RunWithStatusCheck(() => manager.StreamFrames(false), "PXCMSenseManager::StreamFrames"); if (this.manager.captureManager == null || this.manager.captureManager.device == null) { throw new NoDeviceException(); } // Query scene info PXCMCapture.Sample sample = null; do { sample = manager.QuerySample(); } while (sample == null || sample.depth == null || sample.depth.info == null); sceneXCenter = sample.depth.info.width / 2; sceneYCenter = sample.depth.info.height / 2; //Set delay before close gesture ability Task.Factory.StartNew(() => { Thread.Sleep(3000); delayForCloseAchived = true; this.handData.Update(); handInsideBorders = this.handData.QueryNumberOfHands() > 0; }); // Hand tracking started. started = true; }