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"); } }
/// <summary> /// Starts this instance. /// </summary> public void Start() { if (_sm != null) { throw new ResearchException("Camera is already started."); } _sm = PXCMSenseManager.CreateInstance(); // Configure face detection. if (EnableFace) { _sm.EnableFace(); var faceModule = _sm.QueryFace(); using (PXCMFaceConfiguration faceConfig = faceModule.CreateActiveConfiguration()) { faceConfig.EnableAllAlerts(); faceConfig.pose.isEnabled = true; faceConfig.pose.maxTrackedFaces = 4; if (EnableExpression) { PXCMFaceConfiguration.ExpressionsConfiguration expression = faceConfig.QueryExpressions(); expression.Enable(); expression.EnableAllExpressions(); faceConfig.ApplyChanges(); } } } if (EnableEmotion) { // Configure emotion detection. _sm.EnableEmotion(); } if (EnableStreaming) { // Configure streaming. _sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480); // _sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480); // _sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480); } // Event handler for data callbacks. var handler = new PXCMSenseManager.Handler { onModuleProcessedFrame = OnModuleProcessedFrame }; _sm.Init(handler); // GO. Debug.WriteLine("{0} Starting streaming.", Time()); _sm.StreamFrames(false); //Debug.WriteLine("{0} End streaming.", Time()); }
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); }
public MovementController(PXCMSenseManager.Handler handler, PXCMHandConfiguration.OnFiredGestureDelegate handGestureHandler, PXCMHandConfiguration.OnFiredAlertDelegate handAlertHandler) { // register event handlers this._handler = handler; _handGestureHandler = handGestureHandler; _handAlertHandler = handAlertHandler; Session = PXCMSession.CreateInstance(); }
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)); }
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); }
public HandsRecognition(int mod) { try { session = PXCMSession.CreateInstance(); mode = mod; if (mod == 0) { rightcp = new checkPiano(); leftcp = new checkPiano(); } else if (mod == 1) { rightcp = new checkDrum(); leftcp = new checkDrum(); } _disconnected = false; instance = session.CreateSenseManager(); if (instance == null) { MessageBox.Show("Failed creating SenseManager", "OnAlert"); return; } /* Set Module */ pxcmStatus status = instance.EnableHand();//form.GetCheckedModule()); handAnalysis = instance.QueryHand(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null) { MessageBox.Show("Failed Loading Module", "OnAlert"); return; } handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); handData = handAnalysis.CreateOutput(); } catch { MessageBox.Show("Init Failed."); Environment.Exit(0); } }
private static void Fetcher() { // It is yet unclear why we need the handler here // But without it, we get no data PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); senseManager.Init(handler); // Register the handler object while (fetching && senseManager.IsConnected()) { // This is a blocking operation // We need to do this is a separate thread if (senseManager.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } if (!senseManager.IsConnected()) { continue; } senseManager.ReleaseFrame(); //if (bodyTrackingEnabled) // UpdateBodyTracking(); //if (handTrackingEnabled) // UpdateHandTracking(); if (faceTrackingEnabled) { UpdateFace(); } } if (senseManager != null) { //if (handTrackingEnabled) // StopHandTracking(); if (faceTrackingEnabled) { StopFaceTracking(); } senseManager.Close(); senseManager = null; } }
public Form1() { InitializeComponent(); vol = new float[6] { 1F, 1F, 0F, 1F, 0.5F, 0F }; textVolume.Text = vol[3].ToString(); textSpeed.Text = vol[0].ToString(); textPanorama.Text = vol[4].ToString(); thread = new System.Threading.Thread(DoRecognition); flag = 0; oscManager1 = new OscManager(); oscManager1.DestIP = "127.0.0.1"; // Create the SenseManager instance sm = PXCMSenseManager.CreateInstance(); // Enable hand tracking sm.EnableHand(); // Get a hand instance here for configuration PXCMHandModule hand = sm.QueryHand(); // Initialize and stream data. PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler { onModuleProcessedFrame = OnModuleProcessedFrame }; sm.Init(handler); PXCMHandConfiguration handConfiguration = sm.QueryHand().CreateActiveConfiguration(); handConfiguration.EnableGesture("thumb_down"); handConfiguration.EnableGesture("thumb_up"); handConfiguration.EnableGesture("v_sign"); handConfiguration.EnableGesture("spreadfingers"); handConfiguration.EnableGesture("fist"); handConfiguration.EnableGesture("full_pinch"); handConfiguration.ApplyChanges(); if (handConfiguration == null) { Console.WriteLine("Failed Create Configuration"); Console.WriteLine("That`s all..."); Console.ReadKey(); } logTextBox.Text = DateTime.Now.ToString("hh:mm:ss") + " Started" + "\n" + logTextBox.Text; }
public Form1(PXCMSession session) { InitializeComponent(); //_timer = null; thread = new MyBeautifulThread(DoRecognition); flagThread = 0; LightState = 0; flagLight = 0; WindState = 0; flagWind = 0; SendState = 0; sm = PXCMSenseManager.CreateInstance(); sm.EnableHand(); PXCMHandModule hand = sm.QueryHand(); sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 320, 240, 60); PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler { onModuleProcessedFrame = OnModuleProcessedFrame }; sm.Init(handler); PXCMHandConfiguration handConfiguration = sm.QueryHand().CreateActiveConfiguration(); handConfiguration.EnableGesture("wave"); handConfiguration.EnableGesture("swipe_up"); handConfiguration.EnableGesture("thumb_up"); handConfiguration.EnableGesture("tap"); handConfiguration.ApplyChanges(); if (handConfiguration == null) { Console.WriteLine("Failed Create Configuration"); Console.WriteLine("That`s all..."); Console.ReadKey(); } logTextBox.Text = DateTime.Now.ToString("hh:mm:ss") + " Started" + "\n" + logTextBox.Text; }
private void InitializeStreaming() { PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onNewSample = OnNewSample; handler.onStatus = OnStatus; m_status = m_senseManager.Init(handler); if (m_status < pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.Log("Init Failed; " + m_status); hasInitFailed = true; return; } // Start streaming m_status = m_senseManager.StreamFrames(false); if (m_status < pxcmStatus.PXCM_STATUS_NO_ERROR) { Debug.Log("StreamFrames Failed; " + m_status); hasInitFailed = true; } }
public void SimplePipeline() { bool sts = true; PXCMSenseManager pp = form.session.CreateSenseManager(); if (pp == null) throw new Exception("Failed to create sense manager"); disconnected = false; /* Set Source & Profile Index */ PXCMCapture.DeviceInfo info = null; if (this.form.GetRecordState()) { pp.captureManager.SetFileName(this.form.GetFileName(), true); form.PopulateDeviceMenu(); if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info)) { pp.captureManager.FilterByDeviceInfo(info); } } else if (this.form.GetPlaybackState()) { pp.captureManager.SetFileName(this.form.GetFileName(), false); } else { if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info)) { pp.captureManager.FilterByDeviceInfo(info); } } /* Set Module */ pp.EnableEmotion(form.GetCheckedModule()); /* Initialization */ form.UpdateStatus("Init Started"); PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler() { //GZ onModuleQueryProfile = OnModuleQueryProfile }; if (pp.Init(handler) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { form.UpdateStatus("Streaming"); this.timer = new FPSTimer(form); PXCMCaptureManager captureManager = pp.QueryCaptureManager(); if (captureManager == null) throw new Exception("Failed to query capture manager"); PXCMCapture.Device device = captureManager.QueryDevice(); if (device != null && !this.form.GetPlaybackState()) device.SetDepthConfidenceThreshold(7); //GZ device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, 7); while (!form.stop) { if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) break; if (!DisplayDeviceConnection(!pp.IsConnected())) { /* Display Results */ PXCMEmotion ft = pp.QueryEmotion(); if (ft == null) { pp.ReleaseFrame(); continue; } //GZ DisplayPicture(pp.QueryImageByType(PXCMImage.ImageType.IMAGE_TYPE_COLOR)); PXCMCapture.Sample sample = pp.QueryEmotionSample(); if (sample == null) { pp.ReleaseFrame(); continue; } DisplayPicture(sample.color); DisplayLocation(ft); form.UpdatePanel(); } pp.ReleaseFrame(); } } else { form.UpdateStatus("Init Failed"); sts = false; } pp.Close(); pp.Dispose(); if (sts) form.UpdateStatus("Stopped"); }
public void SimplePipeline() { bool sts = true; PXCMSenseManager pp = form.session.CreateSenseManager(); if (pp == null) { throw new Exception("Failed to create sense manager"); } disconnected = false; /* Set Source & Profile Index */ PXCMCapture.DeviceInfo info = null; if (this.form.GetRecordState()) { pp.captureManager.SetFileName(this.form.GetFileName(), true); form.PopulateDeviceMenu(); if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info)) { pp.captureManager.FilterByDeviceInfo(info); } } else if (this.form.GetPlaybackState()) { pp.captureManager.SetFileName(this.form.GetFileName(), false); } else { if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info)) { pp.captureManager.FilterByDeviceInfo(info); } } /* Set Module */ pp.EnableEmotion(form.GetCheckedModule()); /* Initialization */ form.UpdateStatus("Init Started"); PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler() { //GZ onModuleQueryProfile = OnModuleQueryProfile }; if (pp.Init(handler) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { form.UpdateStatus("Streaming"); this.timer = new FPSTimer(form); PXCMCaptureManager captureManager = pp.QueryCaptureManager(); if (captureManager == null) { throw new Exception("Failed to query capture manager"); } PXCMCapture.Device device = captureManager.QueryDevice(); if (device != null && !this.form.GetPlaybackState()) { device.SetDepthConfidenceThreshold(7); } //GZ device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, 7); while (!form.stop) { if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } if (!DisplayDeviceConnection(!pp.IsConnected())) { /* Display Results */ PXCMEmotion ft = pp.QueryEmotion(); if (ft == null) { pp.ReleaseFrame(); continue; } //GZ DisplayPicture(pp.QueryImageByType(PXCMImage.ImageType.IMAGE_TYPE_COLOR)); PXCMCapture.Sample sample = pp.QueryEmotionSample(); if (sample == null) { pp.ReleaseFrame(); continue; } DisplayPicture(sample.color); DisplayLocation(ft); form.UpdatePanel(); } pp.ReleaseFrame(); } } else { form.UpdateStatus("Init Failed"); sts = false; } pp.Close(); pp.Dispose(); if (sts) { form.UpdateStatus("Stopped"); } }
private void InitTouchlessController() { this.senseManager = PXCMSenseManager.CreateInstance(); if (this.senseManager == null) { throw new Exception("Could not create Sense Manager."); } this.session = this.senseManager.session; pxcmStatus sts = this.senseManager.EnableTouchlessController(null); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("Can't get Touchless Controller"); } sts = this.senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, this.width, this.height, FPS); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("Could not enable Color Stream."); } sts = this.senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, this.width, this.height, FPS); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("Could not enable Depth Stream."); } if (!this.senseManager.IsConnected()) { return; } var handler = new PXCMSenseManager.Handler(); sts = this.senseManager.Init(handler); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("Initialization failed. " + sts.ToString()); } this.controller = this.senseManager.QueryTouchlessController(); if (this.controller == null) { throw new Exception("Can't get Touchless Controller"); } this.controller.SubscribeEvent(new PXCMTouchlessController.OnFiredUXEventDelegate(OnTouchlessControllerUXEvent)); this.controller.AddGestureActionMapping("swipeLeft", PXCMTouchlessController.Action.Action_LeftKeyPress, OnFiredAction); PXCMTouchlessController.ProfileInfo pinfo; //this.controller.ClearAllGestureActionMappings(); sts = this.controller.QueryProfile(out pinfo); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("Can't get Touchless Controller profile"); } IntPtr pointer = this.controller.QueryNativePointer(); for (int i = 0; i < FInConfiguration.SliceCount; i++) { pinfo.config |= FInConfiguration[i]; } sts = this.controller.SetProfile(pinfo); if (sts < pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new Exception("Can't set Touchless Controller profile"); } this.senseManager.StreamFrames(false); this.initialized = true; }
public void HandPipeLine() { PXCMSenseManager pp = m_form.Session.CreateSenseManager(); if (pp == null) { throw new Exception("PXCMSenseManager null"); } pp.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 360); //手 初始化 PXCMHandModule handAnalysis; PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); PXCMHandConfiguration handConfiguration = null; PXCMHandData handData = null; pxcmStatus status = pp.EnableHand(); handAnalysis = pp.QueryHand(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null) { Console.WriteLine("hand module load failed"); return; } handConfiguration = handAnalysis.CreateActiveConfiguration(); if (handConfiguration == null) { Console.WriteLine("Failed Create Configuration"); return; } handData = handAnalysis.CreateOutput(); if (handData == null) { Console.WriteLine("Failed Create Output"); return; } if (pp.Init(handler) != pxcmStatus.PXCM_STATUS_NO_ERROR) { Console.WriteLine("init failed"); return; } if (handConfiguration != null) { PXCMHandData.TrackingModeType trackingMode = PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND; // 配置收的Tracking Mode trackingMode = PXCMHandData.TrackingModeType.TRACKING_MODE_FULL_HAND; handConfiguration.SetTrackingMode(trackingMode); handConfiguration.EnableAllAlerts(); handConfiguration.EnableSegmentationImage(true); bool isEnabled = handConfiguration.IsSegmentationImageEnabled(); handConfiguration.ApplyChanges(); int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber(); if (totalNumOfGestures > 0) { for (int i = 0; i < totalNumOfGestures; i++) { string gestureName = string.Empty; if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) == pxcmStatus.PXCM_STATUS_NO_ERROR) { Console.WriteLine(gestureName); } } } } int frameCounter = 0; int frameNumber = 0; while (!m_form.Stopped) { string gestureName = "fist"; 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 (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } frameCounter++; if (pp.IsConnected()) { PXCMCapture.Sample sample; sample = pp.QueryHandSample(); if (sample != null && sample.depth != null) { // frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex(); frameNumber = frameCounter; } //bool b=(sample.ir==null); //b = (sample.color== null); //b = (sample.left == null); //b = (sample.right == null); DisplayPicture(sample.depth); if (handData != null) { handData.Update(); SaveHandData(handData); } m_form.UpdatePic(); } pp.ReleaseFrame(); } if (handData != null) { handData.Dispose(); } if (handConfiguration != null) { handConfiguration.Dispose(); } pp.Close(); pp.Dispose(); }
/* Using PXCMSenseManager to handle data */ public void SimplePipeline() { form.UpdateInfo(String.Empty, Color.Black); bool liveCamera = false; bool flag = true; PXCMSenseManager instance = null; _disconnected = false; instance = form.g_session.CreateSenseManager(); if (instance == null) { form.UpdateStatus("Failed creating SenseManager"); return; } if (form.GetRecordState()) { instance.captureManager.SetFileName(form.GetFileName(), true); PXCMCapture.DeviceInfo info; if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info)) { instance.captureManager.FilterByDeviceInfo(info); } } else if (form.GetPlaybackState()) { instance.captureManager.SetFileName(form.GetFileName(), false); instance.captureManager.SetRealtime(false); } else { PXCMCapture.DeviceInfo info; if (String.IsNullOrEmpty(form.GetCheckedDevice())) { form.UpdateStatus("Device Failure"); return; } if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info)) { instance.captureManager.FilterByDeviceInfo(info); } liveCamera = true; } /* Set Module */ pxcmStatus status = instance.EnableHand(form.GetCheckedModule()); PXCMHandModule handAnalysis = instance.QueryHand(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null) { form.UpdateStatus("Failed Loading Module"); return; } PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration(); PXCMHandData handData = handAnalysis.CreateOutput(); if (handConfiguration == null) { form.UpdateStatus("Failed Create Configuration"); return; } if (handData == null) { form.UpdateStatus("Failed Create Output"); return; } if (form.getInitGesturesFirstTime() == false) { int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber(); if (totalNumOfGestures > 0) { this.form.UpdateGesturesToList("", 0); for (int i = 0; i < totalNumOfGestures; i++) { string gestureName = string.Empty; if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) == pxcmStatus.PXCM_STATUS_NO_ERROR) { this.form.UpdateGesturesToList(gestureName, i + 1); } } form.setInitGesturesFirstTime(true); form.UpdateGesturesListSize(); } } FPSTimer timer = new FPSTimer(form); form.UpdateStatus("Init Started"); if (handAnalysis != null && instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMCapture.DeviceInfo dinfo; PXCMCapture.Device device = instance.captureManager.device; if (device != null) { pxcmStatus result = device.QueryDeviceInfo(out dinfo); if (result == pxcmStatus.PXCM_STATUS_NO_ERROR && dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM) { device.SetDepthConfidenceThreshold(1); device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED); device.SetIVCAMFilterOption(6); } _maxRange = device.QueryDepthSensorRange().max; } if (handConfiguration != null) { handConfiguration.EnableAllAlerts(); handConfiguration.EnableSegmentationImage(true); handConfiguration.ApplyChanges(); handConfiguration.Update(); } form.UpdateStatus("Streaming"); int frameCounter = 0; int frameNumber = 0; string nextPageGesture, previousPageGesture, firstPageGesture, endPageGesture; HandsRecognition.Hand nextHand, previousHand, firstHand, endHand; while (!form.stop) { form.GetHandType(out nextHand, out previousHand, out firstHand, out endHand); form.GetGestureName(out nextPageGesture, out previousPageGesture, out firstPageGesture, out endPageGesture); handConfiguration.DisableAllGestures(); if (string.IsNullOrEmpty(nextPageGesture) == false && handConfiguration.IsGestureEnabled(nextPageGesture) == false) { handConfiguration.EnableGesture(nextPageGesture, true); NextPageGesture.Gesture = nextPageGesture; NextPageGesture.handler = form.NextPage; NextPageGesture.HandType = nextHand; } if (string.IsNullOrEmpty(previousPageGesture) == false && handConfiguration.IsGestureEnabled(previousPageGesture) == false) { handConfiguration.EnableGesture(previousPageGesture, true); PreviousPageGesture.Gesture = previousPageGesture; PreviousPageGesture.handler = form.PreviousPage; PreviousPageGesture.HandType = previousHand; } if (string.IsNullOrEmpty(firstPageGesture) == false && handConfiguration.IsGestureEnabled(firstPageGesture) == false) { handConfiguration.EnableGesture(firstPageGesture, true); FirstPageGesture.Gesture = firstPageGesture; FirstPageGesture.handler = form.FirstPage; FirstPageGesture.HandType = firstHand; } if (string.IsNullOrEmpty(endPageGesture) == false && handConfiguration.IsGestureEnabled(endPageGesture) == false) { handConfiguration.EnableGesture(endPageGesture, true); EndPageGesture.Gesture = endPageGesture; EndPageGesture.handler = form.EndPage; EndPageGesture.HandType = endHand; } handConfiguration.ApplyChanges(); if (instance.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } frameCounter++; if (!DisplayDeviceConnection(!instance.IsConnected())) { if (handData != null) { handData.Update(); } PXCMCapture.Sample sample = instance.QueryHandSample(); if (sample != null && sample.depth != null) { DisplayPicture(sample.depth, handData); if (handData != null) { frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex(); DisplayJoints(handData); DisplayGesture(handData, frameNumber); DisplayAlerts(handData, frameNumber); } form.UpdatePanel(); } timer.Tick(); } instance.ReleaseFrame(); } // Clean Up if (handData != null) { handData.Dispose(); } if (handConfiguration != null) { handConfiguration.Dispose(); } } else { form.UpdateStatus("Init Failed"); flag = false; } foreach (PXCMImage pxcmImage in m_images) { pxcmImage.Dispose(); } instance.Close(); instance.Dispose(); if (flag) { form.UpdateStatus("Stopped"); } }
public void SimplePipeline() { bool sts = true; PXCMSenseManager pp = form.session.CreateSenseManager(); if (pp == null) { throw new Exception("Failed to create sense manager"); } disconnected = false; /* Set Source & Profile Index */ PXCMCapture.DeviceInfo info = null; if (this.form.GetRecordState()) { pp.captureManager.SetFileName(this.form.GetFileName(), true); form.PopulateDeviceMenu(); if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info)) { pp.captureManager.FilterByDeviceInfo(info); } } else if (this.form.GetPlaybackState()) { pp.captureManager.SetFileName(this.form.GetFileName(), false); } else { if (this.form.Devices.TryGetValue(this.form.GetCheckedDevice(), out info)) { pp.captureManager.FilterByDeviceInfo(info); } } /* Set Module */ pp.EnableEmotion(form.GetCheckedModule()); /* Initialization */ form.UpdateStatus("Init Started"); PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler() { //GZ onModuleQueryProfile = OnModuleQueryProfile }; if (pp.Init(handler) >= pxcmStatus.PXCM_STATUS_NO_ERROR) { form.UpdateStatus("Streaming"); this.timer = new FPSTimer(form); PXCMCaptureManager captureManager = pp.QueryCaptureManager(); if (captureManager == null) { throw new Exception("Failed to query capture manager"); } PXCMCapture.Device device = captureManager.QueryDevice(); if (device != null && !this.form.GetPlaybackState()) { device.SetDepthConfidenceThreshold(7); } //GZ device.SetProperty(PXCMCapture.Device.Property.PROPERTY_DEPTH_CONFIDENCE_THRESHOLD, 7); while (!form.stop) { if (pp.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } if (!DisplayDeviceConnection(!pp.IsConnected())) { /* Display Results */ PXCMEmotion ft = pp.QueryEmotion(); //GZ DisplayPicture(pp.QueryImageByType(PXCMImage.ImageType.IMAGE_TYPE_COLOR)); PXCMCapture.Sample sample = pp.QuerySample(); /* Start of modified code */ // Grab the first BMP in the folder, assume there is one for now string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName); string[] files = Directory.GetFiles(folder, "*.bmp"); Bitmap bitmap = new Bitmap(files[0]); // Create a PXCMImage from the BMP PXCMImage.ImageInfo iinfo = new PXCMImage.ImageInfo(); iinfo.width = bitmap.Width; iinfo.height = bitmap.Height; iinfo.format = PXCMImage.PixelFormat.PIXEL_FORMAT_RGB32; PXCMImage imageTEST = form.session.CreateImage(iinfo); PXCMImage.ImageData idata; imageTEST.AcquireAccess(PXCMImage.Access.ACCESS_WRITE, out idata); BitmapData bdata = new BitmapData(); bdata.Scan0 = idata.planes[0]; bdata.Stride = idata.pitches[0]; bdata.PixelFormat = PixelFormat.Format32bppRgb; bdata.Width = bitmap.Width; bdata.Height = bitmap.Height; BitmapData bdata2 = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly | ImageLockMode.UserInputBuffer, PixelFormat.Format32bppRgb, bdata); bitmap.UnlockBits(bdata2); imageTEST.ReleaseAccess(idata); // Save the BMP Bitmap savebmp = idata.ToBitmap(0, bitmap.Width, bitmap.Height); //savebmp.Save(@"O:\unix\projects\instr\production5\research\Francis\result.bmp"); // Put my own PXCMImage into the sample PXCMCapture.Sample smp = new PXCMCapture.Sample(); smp.color = imageTEST; // Get the video module from the emotion instance PXCMVideoModule module = ft.QueryInstance <PXCMVideoModule>(); PXCMSyncPoint sp; // Process the sample module.ProcessImageAsync(smp, out sp); // Synchronize then get emotion data etc. sp.Synchronize(); /* End of modified code */ DisplayPicture(sample.color); DisplayLocation(ft); form.UpdatePanel(); } pp.ReleaseFrame(); } } else { form.UpdateStatus("Init Failed"); sts = false; } pp.Close(); pp.Dispose(); if (sts) { form.UpdateStatus("Stopped"); } }
/* Using PXCMSenseManager to handle data */ public void SimplePipeline() { form.UpdateInfo(String.Empty,Color.Black); bool liveCamera = false; bool flag = true; PXCMSenseManager instance = null; _disconnected = false; instance = form.g_session.CreateSenseManager(); if (instance == null) { form.UpdateStatus("Failed creating SenseManager"); return; } PXCMCaptureManager captureManager = instance.captureManager; if (captureManager != null) { if (form.GetRecordState()) { captureManager.SetFileName(form.GetFileName(), true); PXCMCapture.DeviceInfo info; if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info)) { captureManager.FilterByDeviceInfo(info); } } else if (form.GetPlaybackState()) { captureManager.SetFileName(form.GetFileName(), false); } else { PXCMCapture.DeviceInfo info; if (String.IsNullOrEmpty(form.GetCheckedDevice())) { form.UpdateStatus("Device Failure"); return; } if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info)) { captureManager.FilterByDeviceInfo(info); } liveCamera = true; } } /* Set Module */ pxcmStatus status = instance.EnableHand(form.GetCheckedModule()); PXCMHandModule handAnalysis = instance.QueryHand(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null) { form.UpdateStatus("Failed Loading Module"); return; } PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration(); PXCMHandData handData = handAnalysis.CreateOutput(); if (handConfiguration == null) { form.UpdateStatus("Failed Create Configuration"); return; } if (handData==null) { form.UpdateStatus("Failed Create Output"); return; } if (form.getInitGesturesFirstTime() == false) { int totalNumOfGestures = handConfiguration.QueryGesturesTotalNumber(); if (totalNumOfGestures > 0) { this.form.UpdateGesturesToList("", 0); for (int i = 0; i < totalNumOfGestures; i++) { string gestureName = string.Empty; if (handConfiguration.QueryGestureNameByIndex(i, out gestureName) == pxcmStatus.PXCM_STATUS_NO_ERROR) { this.form.UpdateGesturesToList(gestureName, i + 1); } } form.setInitGesturesFirstTime(true); form.UpdateGesturesListSize(); } } FPSTimer timer = new FPSTimer(form); form.UpdateStatus("Init Started"); if (handAnalysis != null && instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMCapture.DeviceInfo dinfo; PXCMCapture.Device device = instance.captureManager.device; if (device != null) { device.QueryDeviceInfo(out dinfo); _maxRange = device.QueryDepthSensorRange().max; } if (handConfiguration != null) { handConfiguration.EnableAllAlerts(); handConfiguration.EnableSegmentationImage(true); handConfiguration.ApplyChanges(); handConfiguration.Update(); } form.UpdateStatus("Streaming"); int frameCounter = 0; int frameNumber = 0; while (!form.stop) { string gestureName = form.GetGestureName(); 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) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } frameCounter++; if (!DisplayDeviceConnection(!instance.IsConnected())) { if (handData != null) { handData.Update(); } PXCMCapture.Sample sample = instance.QueryHandSample(); if (sample != null && sample.depth != null) { DisplayPicture(sample.depth, handData); if (handData != null) { frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex(); DisplayJoints(handData); DisplayGesture(handData,frameNumber); DisplayAlerts(handData, frameNumber); } form.UpdatePanel(); } timer.Tick(); } instance.ReleaseFrame(); } } else { form.UpdateStatus("Init Failed"); flag = false; } foreach (PXCMImage pxcmImage in m_images) { pxcmImage.Dispose(); } // Clean Up if (handData != null) handData.Dispose(); if (handConfiguration != null) handConfiguration.Dispose(); instance.Close(); instance.Dispose(); if (flag) { form.UpdateStatus("Stopped"); } }
/* Using PXCMSenseManager to handle data */ public void SimplePipeline() { bool flag = true; PXCMSenseManager instance = null; _disconnected = false; instance = form.g_session.CreateSenseManager(); if (instance == null) { form.UpdateStatus("Create SenseManager Failure"); return; } if (form.GetPlaybackState()) { if (instance.captureManager != null) { instance.captureManager.SetFileName(form.GetFileName(), false); instance.captureManager.SetRealtime(false); } } else { PXCMCapture.DeviceInfo info; if (String.IsNullOrEmpty(form.GetCheckedDevice())) { form.UpdateStatus("Device Failure"); return; } if (form.Devices.TryGetValue(form.GetCheckedDevice(), out info)) { instance.captureManager.FilterByDeviceInfo(info); } } /* Set Module */ pxcmStatus status = instance.EnableBlob(); PXCMBlobModule blobModule = instance.QueryBlob(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || blobModule == null) { form.UpdateStatus("Failed Loading Module"); return; } PXCMBlobConfiguration blobConfiguration = blobModule.CreateActiveConfiguration(); PXCMBlobData blobData = blobModule.CreateOutput(); blobConfiguration.SetContourSmoothing(1); if (blobConfiguration == null) { form.UpdateStatus("Failed Create Configuration"); return; } if (blobData == null) { form.UpdateStatus("Failed Create Output"); return; } if (form.worldFacingCamera) { instance.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 320, 240, 0); } PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); form.UpdateStatus("Init Started"); FPSTimer timer = new FPSTimer(form); if (instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR) { blobConfiguration.Update(); PXCMCapture.DeviceInfo dinfo; PXCMCaptureManager captureManager = instance.QueryCaptureManager(); if (captureManager != null) { PXCMCapture.Device device = captureManager.QueryDevice(); if (device != null) { device.QueryDeviceInfo(out dinfo); if (dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM) { device.SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_HORIZONTAL); } if (dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_R200) { device.SetDepthConfidenceThreshold(1); } } } form.UpdateStatus("Streaming"); while (!form.stop) { if (instance.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } if (!DisplayDeviceConnection(!instance.IsConnected())) { PXCMCapture.Sample sample = instance.QuerySample(); if (sample != null && sample.depth != null) { PXCMImage.ImageInfo info = sample.depth.QueryInfo(); float bSmooth = form.GetBlobSmoothing(); blobConfiguration.SetSegmentationSmoothing(bSmooth); float maxDepth = form.GetMaxDepth(); blobConfiguration.SetMaxDistance(maxDepth); int maxBlobs = 2; _maxBlobToShow = maxBlobs; blobConfiguration.SetMaxBlobs(_maxBlobToShow); float contourSmooth = 1; blobConfiguration.SetContourSmoothing(contourSmooth); form.disableTxtForm(false); blobConfiguration.EnableContourExtraction(true); blobConfiguration.EnableSegmentationImage(true); blobConfiguration.ApplyChanges(); if (blobData != null) { blobData.Update(); } if (form.GetContourState() == false && form.GetBlobState() == false) { form.SetBlobState(true); form.SetContourState(true); } DisplayPicture(sample.depth, blobData); form.UpdatePanel(); timer.Tick(); } } instance.ReleaseFrame(); } form.disableTxtForm(true); // Clean Up if (blobData != null) blobData.Dispose(); if (blobConfiguration != null) blobConfiguration.Dispose(); } else { form.UpdateStatus("Init Failed"); flag = false; } instance.Close(); instance.Dispose(); if (flag) { form.UpdateStatus("Stopped"); } }
/* Using PXCMSenseManager to handle data */ public void SimplePipeline(int mod) { mode = mod; if (mod == 0) { rightcp = new checkPiano(); leftcp = new checkPiano(); } else if (mod == 1) { rightcp = new checkDrum(); leftcp = new checkDrum(); } bool liveCamera = false; bool flag = true; PXCMSenseManager instance = null; _disconnected = false; instance = Program.session.CreateSenseManager(); if (instance == null) { Console.WriteLine("Failed creating SenseManager"); return; } /* Set Module */ pxcmStatus status = instance.EnableHand();//form.GetCheckedModule()); PXCMHandModule handAnalysis = instance.QueryHand(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || handAnalysis == null) { Console.WriteLine("Failed Loading Module"); return; } PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); PXCMHandConfiguration handConfiguration = handAnalysis.CreateActiveConfiguration(); PXCMHandData handData = handAnalysis.CreateOutput(); if (handConfiguration == null) { Console.WriteLine("Failed Create Configuration"); return; } if (handData == null) { Console.WriteLine("Failed Create Output"); return; } if (handAnalysis != null && instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMCapture.DeviceInfo dinfo; PXCMCapture.Device device = instance.captureManager.device; if (device != null) { device.QueryDeviceInfo(out dinfo); _maxRange = device.QueryDepthSensorRange().max; } if (handConfiguration != null) { handConfiguration.EnableAllAlerts(); handConfiguration.EnableSegmentationImage(true); handConfiguration.ApplyChanges(); handConfiguration.Update(); } Console.WriteLine("PXCSenseManager Initializing OK\n"); int frameCounter = 0; int frameNumber = 0; //for thread //ThreadPlay tp = new ThreadPlay(); //int t = tp.play("music.txt"); while (!mon.stop) { if (instance.AcquireFrame(true) < pxcmStatus.PXCM_STATUS_NO_ERROR) { break; } frameCounter++; if (!DisplayDeviceConnection(!instance.IsConnected())) { if (handData != null) { handData.Update(); } PXCMCapture.Sample sample = instance.QueryHandSample(); if (sample != null && sample.depth != null) { if (handData != null) { frameNumber = liveCamera ? frameCounter : instance.captureManager.QueryFrameIndex(); DisplayJoints(handData); DisplayGesture(handData, frameNumber); } } } instance.ReleaseFrame(); } } else { Console.WriteLine("Init Failed"); flag = false; } foreach (PXCMImage pxcmImage in m_images) { pxcmImage.Dispose(); } //store as a file sr.Close(); //string filename = System.Guid.NewGuid().ToString() + ".txt"; eventReceiver2.ClickStore("temp.txt"); // Clean Up if (handData != null) handData.Dispose(); if (handConfiguration != null) handConfiguration.Dispose(); instance.Close(); instance.Dispose(); if (flag) { Console.WriteLine("Stopped"); } }
/// <summary> /// Starts this instance. /// </summary> public void Start() { if (_sm != null) throw new ResearchException("Camera is already started."); _sm = PXCMSenseManager.CreateInstance(); // Configure face detection. if (EnableFace) { _sm.EnableFace(); var faceModule = _sm.QueryFace(); using (PXCMFaceConfiguration faceConfig = faceModule.CreateActiveConfiguration()) { faceConfig.EnableAllAlerts(); faceConfig.pose.isEnabled = true; faceConfig.pose.maxTrackedFaces = 4; if (EnableExpression) { PXCMFaceConfiguration.ExpressionsConfiguration expression = faceConfig.QueryExpressions(); expression.Enable(); expression.EnableAllExpressions(); faceConfig.ApplyChanges(); } } } if (EnableEmotion) { // Configure emotion detection. _sm.EnableEmotion(); } if (EnableStreaming) { // Configure streaming. _sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480); // _sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 640, 480); // _sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_IR, 640, 480); } // Event handler for data callbacks. var handler = new PXCMSenseManager.Handler { onModuleProcessedFrame=OnModuleProcessedFrame }; _sm.Init(handler); // GO. Debug.WriteLine("{0} Starting streaming.", Time()); _sm.StreamFrames(false); //Debug.WriteLine("{0} End streaming.", Time()); }
/// <summary> /// Using PXCMSenseManager to handle data /// </summary> public void SimplePipeline() { session = PXCMSession.CreateInstance(); if (session != null) { instance = session.CreateSenseManager(); if (instance == null) { Debug.Log("Create SenseManager Failure"); return; } pxcmStatus status = instance.EnableBlob(); PXCMBlobModule blobModule = instance.QueryBlob(); if (status != pxcmStatus.PXCM_STATUS_NO_ERROR || blobModule == null) { Debug.Log("Failed Loading Module"); return; } blobConfiguration = blobModule.CreateActiveConfiguration(); blobData = blobModule.CreateOutput(); if (blobConfiguration != null) { blobConfiguration.SetSegmentationSmoothing(1.0f); blobConfiguration.SetMaxDistance(550); blobConfiguration.SetMaxObjectDepth(100); blobConfiguration.SetMaxBlobs(_maxBlobToShow); blobConfiguration.SetContourSmoothing(1.0f); blobConfiguration.EnableContourExtraction(true); blobConfiguration.EnableSegmentationImage(true); blobConfiguration.ApplyChanges(); } if (blobData == null) { Debug.Log("Failed Create Output"); return; } PXCMSenseManager.Handler handler = new PXCMSenseManager.Handler(); handler.onModuleProcessedFrame = new PXCMSenseManager.Handler.OnModuleProcessedFrameDelegate(OnNewFrame); if (instance.Init(handler) == pxcmStatus.PXCM_STATUS_NO_ERROR) { PXCMCapture.DeviceInfo dinfo; instance.QueryCaptureManager().QueryDevice().QueryDeviceInfo(out dinfo); if (dinfo != null && dinfo.model == PXCMCapture.DeviceModel.DEVICE_MODEL_IVCAM) { instance.QueryCaptureManager().QueryDevice().SetMirrorMode(PXCMCapture.Device.MirrorMode.MIRROR_MODE_DISABLED); } /* Set the depth stream confidence threshold value - Any depth pixels with a confidence score below the threshold will be set to the low confidence pixel value*/ instance.QueryCaptureManager().QueryDevice().SetDepthConfidenceThreshold(10); /* Set the smoothing aggressiveness parameter - High smoothing effect for distances between 850mm to 1000mm bringing good accuracy with moderate sharpness level.*/ instance.QueryCaptureManager().QueryDevice().SetIVCAMFilterOption(6); } } else { Debug.Log("Init Failed"); } }
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; }