private void ProcessingThread() { // Start AcquireFrame/ReleaseFrame loop for (;;) { if (terminate) { System.Diagnostics.Debug.WriteLine("Application window closed, shutting down"); break; } Status status = senseManager.AcquireFrame(true); if (status.IsError()) { System.Diagnostics.Debug.WriteLine("Failed to Acquire Frame: " + status.ToString()); break; } //process face ProcessLandmarks(); CreateLandmarkBoundingBoxes(); //process image streams ProcessImages(); //Release the frame senseManager.ReleaseFrame(); } senseManager.Close(); session.Dispose(); }
/// <summary> /// フレームごとの更新及び個別のデータ更新処理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CompositionTarget_Rendering(object sender, EventArgs e) { //try //{ //フレームを取得する //AcquireFrame()の引数はすべての機能の更新が終るまで待つかどうかを指定 //ColorやDepthによって更新間隔が異なるので設定によって値を変更 var ret = senseManager.AcquireFrame(true); if (ret < Status.STATUS_NO_ERROR) { return; } //フレームデータを取得する Sample sample = senseManager.Sample; if (sample != null) { //カラー画像の表示 UpdateColorImage(sample.Color); } //フレームを解放する senseManager.ReleaseFrame(); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); // Close(); //} }
public void StartStream() { SenseManager.captureManager.FilterByDeviceInfo(DeviceInfo); // Initializing the SenseManager pxcmStatus initSenseManagerStatus = SenseManager.Init(); // Initializing the SenseManager if (initSenseManagerStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new InvalidRealSenseStatusException(initSenseManagerStatus, string.Format("Failed to initialize the SenseManager. Return code: {0}", initSenseManagerStatus)); } if (SenseManager == null) { throw new NullReferenceException("The SenseManager isn't initialized. Please check if you already called the InitializeStream method."); } IsRunning = true; CaptureThread = new Thread(() => { while (IsRunning) { if (SenseManager == null || !SenseManager.IsConnected()) { throw new Exception("The SenseManager is not ready to stream."); } // Acquiring a frame with ifall=true to wait for both samples to be ready (aligned samples) pxcmStatus acquireFrameStatus = SenseManager.AcquireFrame(true); if (acquireFrameStatus != pxcmStatus.PXCM_STATUS_NO_ERROR) { throw new InvalidRealSenseStatusException(acquireFrameStatus, string.Format("Failed to acquire a frame. Return code: {0}", acquireFrameStatus)); } SenseManager.ReleaseFrame(); } }); CaptureThread.Start(); }
/* 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"); } }
private void StartTrackingLoop() { PXCMFaceData FaceData = FaceModule.CreateOutput(); while (!_shouldStop) { pxcmStatus acquireFrameStatus = SenseManager.AcquireFrame(true); if (acquireFrameStatus < pxcmStatus.PXCM_STATUS_NO_ERROR) { ResetTrackData(); Console.WriteLine("SenseManager.AcquireFrame(true) error: " + acquireFrameStatus.ToString()); continue; } PXCMCapture.Sample captureSample = SenseManager.QueryFaceSample(); if (captureSample == null) { ResetTrackData(); SenseManager.ReleaseFrame(); continue; } //TODO: Image Daten holen TrackImageData(captureSample); FaceData.Update(); int numberOfDetectedFaces = FaceData.QueryNumberOfDetectedFaces(); if (numberOfDetectedFaces != 1) { ResetTrackData(); SenseManager.ReleaseFrame(); continue; } PXCMFaceData.Face faceDataFace = FaceData.QueryFaceByIndex(0); TrackPose(faceDataFace); TrackExpressions(faceDataFace); //TrackLandmarks(faceDataFace); //TrackGaze(); //FaceData.QueryRecognitionModule(); //im nächsten object steckt boundingrectangle und avarageDepth drin //PXCMFaceData.DetectionData faceDataDetectionData = faceDataFace.QueryDetection(); //faceDataDetectionData.QueryFaceAverageDepth(); //faceDataDetectionData.QueryBoundingRect(); SenseManager.ReleaseFrame(); Thread.Sleep(250); } if (FaceData != null) { FaceData.Dispose(); } FaceConfiguration.Dispose(); SenseManager.Close(); SenseManager.Dispose(); }