private void Playback() { var filePath = app.BrowseFileToOpen("MKV recordings|*.mkv"); if (!string.IsNullOrWhiteSpace(filePath)) { try { using (app.IndicateWaiting()) { var readingLoop = BackgroundReadingLoop.CreateForPlayback(filePath, disableColor: false, disableDepth: false, doNotPlayFasterThanOriginalFps: true); if (readingLoop.ColorResolution == ColorResolution.Off) { throw new ApplicationException("There is no color data in the video"); } if (readingLoop.DepthMode == DepthMode.Off || readingLoop.DepthMode == DepthMode.PassiveIR) { throw new ApplicationException("There is no depth data in the video"); } var viewModel = new ProcessingViewModel(readingLoop, app); app.ShowWindowForModel(viewModel); } } catch (Exception exc) { app.ShowErrorMessage(exc.Message, "Cannot open file for playback"); } } }
public ViewerModel(IApp app, BackgroundReadingLoop readingLoop) : base(app) { this.readingLoop = readingLoop; readingLoop.CaptureReady += ReadingLoop_CaptureReady; readingLoop.Failed += ReadingLoop_Failed; Title = readingLoop.ToString(); var colorRes = readingLoop.ColorResolution; var depthMode = readingLoop.DepthMode; // Image visualizers for color if (colorRes != ColorResolution.Off) { colorImageVisualizer = ImageVisualizer.CreateForColorBgra(dispatcher, colorRes.WidthPixels(), colorRes.HeightPixels()); if (depthMode.HasDepth()) { readingLoop.GetCalibration(out var calibration); transformation = calibration.CreateTransformation(); depthOverColorImage = new Image(ImageFormat.Depth16, colorRes.WidthPixels(), colorRes.HeightPixels()); depthOverColorImageVisualizer = ImageVisualizer.CreateForDepth(dispatcher, colorRes.WidthPixels(), colorRes.HeightPixels()); } } // Image visualizers for depth and IR (if any) if (depthMode.HasDepth()) { depthImageVisualizer = ImageVisualizer.CreateForDepth(dispatcher, depthMode.WidthPixels(), depthMode.HeightPixels()); } if (depthMode.HasPassiveIR()) { irImageVisualizer = ImageVisualizer.CreateForIR(dispatcher, depthMode.WidthPixels(), depthMode.HeightPixels()); } // Proportions between columns if (colorRes != ColorResolution.Off && depthMode.HasPassiveIR()) { IRColumnWidth = new GridLength(irImageVisualizer.WidthPixels, GridUnitType.Star); DepthColumnWidth = depthMode.HasDepth() ? IRColumnWidth : new GridLength(0, GridUnitType.Pixel); ColorColumnWidth = new GridLength( irImageVisualizer.HeightPixels * colorImageVisualizer.WidthPixels / colorImageVisualizer.HeightPixels, GridUnitType.Star); } else if (colorRes != ColorResolution.Off) { DepthColumnWidth = IRColumnWidth = new GridLength(0, GridUnitType.Pixel); ColorColumnWidth = new GridLength(1, GridUnitType.Star); } else { IRColumnWidth = new GridLength(1, GridUnitType.Star); ColorColumnWidth = new GridLength(0, GridUnitType.Pixel); DepthColumnWidth = depthMode.HasDepth() ? IRColumnWidth : ColorColumnWidth; } }
public TrackerModel(IApp app, BackgroundReadingLoop readingLoop, TrackerProcessingMode processingMode, DnnModel dnnModel, SensorOrientation sensorOrientation, float smoothingFactor) : base(app) { // try to create tracking loop first readingLoop.GetCalibration(out calibration); trackingLoop = new BackgroundTrackingLoop(in calibration, processingMode, dnnModel, sensorOrientation, smoothingFactor); trackingLoop.BodyFrameReady += TrackingLoop_BodyFrameReady; trackingLoop.Failed += BackgroundLoop_Failed; this.readingLoop = readingLoop; readingLoop.CaptureReady += ReadingLoop_CaptureReady; readingLoop.Failed += BackgroundLoop_Failed; Title = readingLoop.ToString(); // Image and skeleton visualizers for depth var depthMode = readingLoop.DepthMode; depthImageVisualizer = ImageVisualizer.CreateForDepth(dispatcher, depthMode.WidthPixels(), depthMode.HeightPixels()); depthSkeletonVisualizer = new SkeletonVisualizer(dispatcher, depthMode.WidthPixels(), depthMode.HeightPixels(), ProjectJointToDepthMap); // Image and skeleton visualizers for color var colorRes = readingLoop.ColorResolution; if (colorRes != ColorResolution.Off) { colorImageVisualizer = ImageVisualizer.CreateForColorBgra(dispatcher, colorRes.WidthPixels(), colorRes.HeightPixels()); colorSkeletonVisualizer = new SkeletonVisualizer(dispatcher, colorRes.WidthPixels(), colorRes.HeightPixels(), ProjectJointToColorImage); bodyIndexMapTransformation = new BodyIndexMapTransformation(in calibration); } // Proportions between columns if (colorRes != ColorResolution.Off) { DepthColumnWidth = new GridLength(depthImageVisualizer.WidthPixels, GridUnitType.Star); ColorColumnWidth = new GridLength( depthImageVisualizer.HeightPixels * colorImageVisualizer.WidthPixels / colorImageVisualizer.HeightPixels, GridUnitType.Star); } else { DepthColumnWidth = new GridLength(1, GridUnitType.Star); ColorColumnWidth = new GridLength(0, GridUnitType.Pixel); } }
public ProcessingViewModel(BackgroundReadingLoop readingLoop, IApp app) : base(app) { this.readingLoop = readingLoop ?? throw new ArgumentNullException(nameof(readingLoop)); readingLoop.GetCalibration(out var calibration); transformation = calibration.CreateTransformation(); var frameWidth = readingLoop.ColorResolution.WidthPixels(); var frameHeight = readingLoop.ColorResolution.HeightPixels(); depthImage = new Image(ImageFormat.Depth16, frameWidth, frameHeight); bitmap = dispatcher.Invoke(new Func <WriteableBitmap>( () => new WriteableBitmap(frameWidth, frameHeight, 96, 96, PixelFormats.Bgra32, null))); processor = new Processor(frameWidth, frameHeight); readingLoop.CaptureReady += ReadingLoop_CaptureReady; readingLoop.Failed += ReadingLoop_Failed; processor.ImageUpdated += Processor_ImageUpdated; }