private void ConstructPresetDocker() { this.PresetDocker.SecondaryButtonClick += (s, e) => this.PresetDocker.Hide(); this.PresetDocker.PrimaryButtonClick += (s, e) => this.AddPresetDialog.Show(); this.PresetGridView.ItemClick += (s, e) => { if (e.ClickedItem is Project item) { this.PresetDocker.Hide(); this.NewFromProject(item.Clone()); } }; this.AddPresetDialog.SecondaryButtonClick += (s, e) => this.AddPresetDialog.Hide(); this.AddPresetDialog.PrimaryButtonClick += (s, e) => { BitmapSize size = this.PresetSizePicker.Size; // Project Project project = new Project { Width = (int)size.Width, Height = (int)size.Height, }; this.PresetProjects.Add(project); }; }
/// <summary> /// New from size. /// </summary> /// <param name="pixels"> The bitmap size. </param> public void NewFromSize(BitmapSize pixels) { this.LoadingControl.State = LoadingState.Loading; this.LoadingControl.IsActive = true; //Project { string untitled = this.Untitled; string name = this.MainLayout.UntitledRenameByRecursive(untitled); int width = (int)pixels.Width; int height = (int)pixels.Height; Project project = new Project { Name = name, Width = width, Height = height, }; this.ViewModel.LoadFromProject(project); } //Transition TransitionData data = new TransitionData { Type = TransitionType.Size }; this.LoadingControl.IsActive = false; this.LoadingControl.State = LoadingState.None; this.Frame.Navigate(typeof(DrawPage), data);//Navigate }
/// <summary> /// Method to start capturing camera frames at desired resolution. /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public async Task InitializeMediaFrameReaderAsync(uint width = 224, uint height = 224) { // Check state of media capture object if (_mediaCapture == null || _mediaCapture.CameraStreamState == CameraStreamState.Shutdown || _mediaCapture.CameraStreamState == CameraStreamState.NotStreaming) { if (_mediaCapture != null) { _mediaCapture.Dispose(); } // Find right camera settings and prefer back camera MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings(); var allCameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); Debug.Log($"InitializeMediaFrameReaderAsync: allCameras: {allCameras}"); var selectedCamera = allCameras.FirstOrDefault(c => c.EnclosureLocation?.Panel == Panel.Back) ?? allCameras.FirstOrDefault(); Debug.Log($"InitializeMediaFrameReaderAsync: selectedCamera: {selectedCamera}"); if (selectedCamera != null) { settings.VideoDeviceId = selectedCamera.Id; Debug.Log($"InitializeMediaFrameReaderAsync: settings.VideoDeviceId: {settings.VideoDeviceId}"); } // Init capturer and Frame reader _mediaCapture = new MediaCapture(); Debug.Log("InitializeMediaFrameReaderAsync: Successfully created media capture object."); await _mediaCapture.InitializeAsync(settings); Debug.Log("InitializeMediaFrameReaderAsync: Successfully initialized media capture object."); var frameSource = _mediaCapture.FrameSources.Where(source => source.Value.Info.SourceKind == MediaFrameSourceKind.Color).First(); Debug.Log($"InitializeMediaFrameReaderAsync: frameSource: {frameSource}."); // Convert the pixel formats var subtype = MediaEncodingSubtypes.Bgra8; // The overloads of CreateFrameReaderAsync with the format arguments will actually make a copy in FrameArrived BitmapSize outputSize = new BitmapSize { Width = width, Height = height }; _mediaFrameReader = await _mediaCapture.CreateFrameReaderAsync(frameSource.Value, subtype, outputSize); Debug.Log("InitializeMediaFrameReaderAsync: Successfully created media frame reader."); _mediaFrameReader.AcquisitionMode = MediaFrameReaderAcquisitionMode.Realtime; await _mediaFrameReader.StartAsync(); Debug.Log("InitializeMediaFrameReaderAsync: Successfully started media frame reader."); IsCapturing = true; } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { App.dispatcher = this.Dispatcher; Cv2.InitContainer((object)App.container); //_helper.SetContainer(App.container); rootPage = MainPage.Current; // setting up the combobox, and default operation OperationComboBox.ItemsSource = Enum.GetValues(typeof(OperationType)); OperationComboBox.SelectedIndex = 0; currentOperation = OperationType.Blur; // Find the sources var allGroups = await MediaFrameSourceGroup.FindAllAsync(); var sourceGroups = allGroups.Select(g => new { Group = g, SourceInfo = g.SourceInfos.FirstOrDefault(i => i.SourceKind == MediaFrameSourceKind.Color) }).Where(g => g.SourceInfo != null).ToList(); if (sourceGroups.Count == 0) { // No camera sources found return; } var selectedSource = sourceGroups.FirstOrDefault(); // Initialize MediaCapture try { await InitializeMediaCaptureAsync(selectedSource.Group); } catch (Exception exception) { Debug.WriteLine("MediaCapture initialization error: " + exception.Message); await CleanupMediaCaptureAsync(); return; } // Create the frame reader MediaFrameSource frameSource = _mediaCapture.FrameSources[selectedSource.SourceInfo.Id]; BitmapSize size = new BitmapSize() // Choose a lower resolution to make the image processing more performant { Height = IMAGE_ROWS, Width = IMAGE_COLS }; _reader = await _mediaCapture.CreateFrameReaderAsync(frameSource, MediaEncodingSubtypes.Bgra8, size); _reader.FrameArrived += ColorFrameReader_FrameArrivedAsync; await _reader.StartAsync(); _FPSTimer.Start(); }
// AddDialog private void ConstructAddDialog() { this.AddDialog.SecondaryButtonClick += (s, e) => this.HideAddDialog(); this.AddDialog.PrimaryButtonClick += (s, e) => { this.HideAddDialog(); BitmapSize size = this.SizePicker.Size; this.NewFromProject(new Project(size)); }; }
//AddDialog private void ConstructAddDialog() { this.AddDialog.CloseButton.Click += (sender, args) => this.HideAddDialog(); this.AddDialog.PrimaryButton.Click += (sender, args) => { this.HideAddDialog(); BitmapSize size = this.AddSizePicker.Size; this.NewFromSize(size); }; }
public ImageInfo(CanvasRenderTarget image) { _crt = image; BitmapSize bsize = image.SizeInPixels; Size size = image.Size; _offset = new Point(size.Width / 2.0f, size.Height / 2.0f); using (CanvasDrawingSession ds = image.CreateDrawingSession()) { _symbolBounds = image.GetBounds(ds); _imageBounds = ShapeUtilities.clone(_symbolBounds); } }
public async void InitializeManager() { _helper = new OpenCVHelper(); // Find the sources var allGroups = await MediaFrameSourceGroup.FindAllAsync(); var sourceGroups = allGroups.Select(g => new { Group = g, SourceInfo = g.SourceInfos.FirstOrDefault(i => i.SourceKind == MediaFrameSourceKind.Color) }).Where(g => g.SourceInfo != null).ToList(); if (sourceGroups.Count == 0) { // No camera sources found return; } var selectedSource = sourceGroups.FirstOrDefault(); // Initialize MediaCapture try { await InitializeMediaCaptureAsync(selectedSource.Group); } catch (Exception exception) { Debug.WriteLine("MediaCapture initialization error: " + exception.Message); await CleanupMediaCaptureAsync(); return; } // Create the frame reader MediaFrameSource frameSource = _mediaCapture.FrameSources[selectedSource.SourceInfo.Id]; var format = frameSource.SupportedFormats.OrderByDescending(x => x.VideoFormat.Width * x.VideoFormat.Height).FirstOrDefault(); await frameSource.SetFormatAsync(format); BitmapSize size = new BitmapSize() // Choose a lower resolution to make the image processing more performant { Height = format.VideoFormat.Height, Width = format.VideoFormat.Width }; _reader = await _mediaCapture.CreateFrameReaderAsync(frameSource, MediaEncodingSubtypes.Bgra8, size); _reader.FrameArrived += HandleFrameArrive; await _reader.StartAsync(); }
/// <summary> /// Returns a boolean indicating whether the given BitmapSize is equal to this CanvasTransformer instance. /// </summary> /// <param name="other"> The BitmapSize to compare this instance to. </param> /// <returns> Return **true** if the other BitmapSize is equal to this instance, otherwise **false**. </returns> public bool Equals(BitmapSize other) { int width = (int)other.Width; int height = (int)other.Height; if (this.Width != width) { return(false); } if (this.Height != height) { return(false); } return(true); }
public void MethodSetup(BitmapSize bitmapSize, IndicatorMode indicatorMode) { if (this.CanvasTransformer == bitmapSize) { return; } Vector2 previousVector = this.CanvasTransformer.GetIndicatorVector(indicatorMode); //History LayersSetupTransformAddHistory history = new LayersSetupTransformAddHistory("Set canvas size", this.CanvasTransformer); //CanvasTransformer this.CanvasTransformer.BitmapSize = bitmapSize; this.CanvasTransformer.ReloadMatrix(); Vector2 vector = this.CanvasTransformer.GetIndicatorVector(indicatorMode); Vector2 distance = vector - previousVector; //LayerageCollection foreach (Layerage layerage in this.LayerageCollection.RootLayerages) { //Selection this.SetLayerageValueWithChildren(layerage, (layerage2) => { ILayer layer = layerage2.Self; //History history.PushTransform(layer, distance); //Refactoring layer.IsRefactoringTransformer = true; layer.IsRefactoringRender = true; layer.IsRefactoringIconRender = true; //layerage.RefactoringParentsTransformer(); //layerage.RefactoringParentsRender(); //layerage.RefactoringParentsIconRender(); layer.CacheTransform(); layer.TransformAdd(distance); }); } //History this.HistoryPush(history); //Selection this.SetMode(this.LayerageCollection); this.Invalidate();//Invalidate }
public static Rect GetBounds(Color[] co, BitmapSize size) { int W = (int)size.Width; int H = (int)size.Height; //左上右下 int left = W; int top = H; int right = 0; int bottom = 0; for (int y = 0; y < H; y++) { for (int x = 0; x < W; x++) { if (co[y * W + x].A != 0) { if (left > x) { left = x; } if (top > y) { top = y; } if (right < x) { right = x; } if (bottom < y) { bottom = y; } } } } if (right > left && bottom > top) { return(new Rect(left, top, right - left, bottom - top)); } else { return(new Rect(0, 0, W, H)); } }
public void MethodSetup(BitmapSize bitmapSize) { if (this.CanvasTransformer == bitmapSize) { return; } Vector2 scale = this.CanvasTransformer.GetScale(bitmapSize); Matrix3x2 matrix = Matrix3x2.CreateScale(scale); //History LayersSetupTransformMultipliesHistory history = new LayersSetupTransformMultipliesHistory("Set canvas size", this.CanvasTransformer); //CanvasTransformer this.CanvasTransformer.BitmapSize = bitmapSize; this.CanvasTransformer.ReloadMatrix(); //LayerageCollection foreach (Layerage layerage in this.LayerageCollection.RootLayerages) { //Selection this.SetLayerageValueWithChildren(layerage, (layerage2) => { ILayer layer = layerage2.Self; //History history.PushTransform(layer); //Refactoring layer.IsRefactoringTransformer = true; layer.IsRefactoringRender = true; layer.IsRefactoringIconRender = true; //layerage.RefactoringParentsTransformer(); //layerage.RefactoringParentsRender(); //layerage.RefactoringParentsIconRender(); layer.CacheTransform(); layer.TransformMultiplies(matrix); }); } //History this.HistoryPush(history); //Selection this.SetMode(this.LayerageCollection); this.Invalidate();//Invalidate }
public static int GetInt(this BitmapSize b) { switch (b) { case BitmapSize.VERY_LARGE: return(550); case BitmapSize.LARGE: return(430); case BitmapSize.MEDIUM: return(310); default: return(190); } }
public async Task StartCapturing(uint width = 320, uint height = 240) { if (_captureManager == null || _captureManager.CameraStreamState == CameraStreamState.Shutdown || _captureManager.CameraStreamState == CameraStreamState.NotStreaming) { if (_captureManager != null) { _captureManager.Dispose(); } // Find right camera settings and prefer back camera MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings(); var allCameras = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); var selectedCamera = allCameras.FirstOrDefault(c => c.EnclosureLocation?.Panel == Panel.Back) ?? allCameras.FirstOrDefault(); if (selectedCamera != null) { settings.VideoDeviceId = selectedCamera.Id; } // Init capturer and Frame reader _captureManager = new MediaCapture(); await _captureManager.InitializeAsync(settings); var frameSource = _captureManager.FrameSources.Where(source => source.Value.Info.SourceKind == MediaFrameSourceKind.Color).First(); // Convert the pixel formats var subtype = MediaEncodingSubtypes.Bgra8; //if (pixelFormat != BitmapPixelFormat.Bgra8) //{ // throw new Exception($"Pixelformat {pixelFormat} not supported yet. Add conversion here"); //} // The overloads of CreateFrameReaderAsync with the format arguments will actually make a copy in FrameArrived BitmapSize outputSize = new BitmapSize { Width = width, Height = height }; _frameReader = await _captureManager.CreateFrameReaderAsync(frameSource.Value, subtype, outputSize); _frameReader.AcquisitionMode = MediaFrameReaderAcquisitionMode.Realtime; await _frameReader.StartAsync(); IsCapturing = true; } }
public async Task Initialize() { // Find the sources var allGroups = await MediaFrameSourceGroup.FindAllAsync(); var sourceGroups = allGroups.Select(g => new { Group = g, SourceInfo = g.SourceInfos.FirstOrDefault(i => i.SourceKind == MediaFrameSourceKind.Color) }).Where(g => g.SourceInfo != null).ToList(); if (sourceGroups.Count == 0) { // No camera sources found return; } var selectedSource = sourceGroups.FirstOrDefault(); // Initialize MediaCapture try { await InitializeMediaCaptureAsync(selectedSource.Group); } catch (Exception exception) { Debug.WriteLine("MediaCapture initialization error: " + exception.Message); await Cleanup(); return; } // Create the frame reader MediaFrameSource frameSource = _mediaCapture.FrameSources[selectedSource.SourceInfo.Id]; BitmapSize size = new BitmapSize() // Choose a lower resolution to make the image processing more performant { Height = IMAGE_ROWS, Width = IMAGE_COLS }; _reader = await _mediaCapture.CreateFrameReaderAsync(frameSource, MediaEncodingSubtypes.Bgra8, size); _reader.FrameArrived += ColorFrameReader_FrameArrivedAsync; await _reader.StartAsync(); }
/// <summary> /// Export to ... /// </summary> private async Task <bool> Export() { //Render BitmapSize size = this.ExportSizePicker.Size; int dpi = (int)this.DPIComboBox.DPI; bool isClearWhite = this.FileFormatComboBox.IsClearWhite; CanvasRenderTarget renderTarget = this.MainCanvasControl.Render(size, dpi, isClearWhite); //Export return(await FileUtil.SaveCanvasBitmapFile ( renderTarget : renderTarget, fileChoices : this.FileFormatComboBox.FileChoices, suggestedFileName : this.ViewModel.Name, fileFormat : this.FileFormatComboBox.FileFormat, quality : this.ExportQuality )); }
private async Task DecodeLiveviewFrame(JpegPacket packet, bool retry = false) { Action trailingTask = null; if (LiveviewImageBitmap == null || sizeChanged) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { var writeable = await LiveviewUtil.AsWriteableBitmap(packet.ImageData, Dispatcher); OriginalLvSize = new BitmapSize { Width = (uint)writeable.PixelWidth, Height = (uint)writeable.PixelHeight }; var magnification = CalcLiveviewMagnification(); DebugUtil.Log(() => { return("Decode: mag: " + magnification + " offsetV: " + LvOffsetV); }); dpi = DEFAULT_DPI / magnification; RefreshOverlayControlParams(magnification); trailingTask = () => { if (Context?.Target?.Status != null) { RotateLiveviewImage(Context.Target.Status.LiveviewOrientationAsDouble, (sender, arg) => { RefreshOverlayControlParams(magnification); }); } sizeChanged = false; }; }); } else { rwLock.EnterWriteLock(); try { var toDelete = LiveviewImageBitmap; trailingTask = () => { // Dispose after it is drawn toDelete?.Dispose(); }; } finally { rwLock.ExitWriteLock(); } } using (var stream = new InMemoryRandomAccessStream()) { await stream.WriteAsync(packet.ImageData.AsBuffer()); stream.Seek(0); var bmp = await CanvasBitmap.LoadAsync(LiveviewImageCanvas, stream, (float)dpi); var size = bmp.SizeInPixels; rwLock.EnterWriteLock(); try { LiveviewImageBitmap = bmp; } finally { rwLock.ExitWriteLock(); } if (!OriginalLvSize.Equals(size)) { DisposeLiveviewImageBitmap(); if (!retry) { await DecodeLiveviewFrame(packet, true); } return; } } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { LiveviewImageCanvas.Invalidate(); trailingTask?.Invoke(); }); if (PendingPakcet != null) { var task = DecodeLiveviewFrame(PendingPakcet); PendingPakcet = null; } }
/// <summary> /// Get the scale. /// </summary> /// <param name="bitmapSize"> The bitmap size.</param> /// <returns> The produced vector. </returns> public Vector2 GetScale(BitmapSize bitmapSize) => new Vector2((float)bitmapSize.Width / (float)this.Width, (float)bitmapSize.Height / (float)this.Height);
private async void InitOpenCVFrameReader() { //<SnippetOpenCVFrameSourceGroups> var frameSourceGroups = await MediaFrameSourceGroup.FindAllAsync(); var selectedGroupObjects = frameSourceGroups.Select(group => new { sourceGroup = group, colorSourceInfo = group.SourceInfos.FirstOrDefault((sourceInfo) => { // On XBox/Kinect, omit the MediaStreamType and EnclosureLocation tests return(sourceInfo.SourceKind == MediaFrameSourceKind.Color); }) }).Where(t => t.colorSourceInfo != null) .FirstOrDefault(); MediaFrameSourceGroup selectedGroup = selectedGroupObjects?.sourceGroup; MediaFrameSourceInfo colorSourceInfo = selectedGroupObjects?.colorSourceInfo; if (selectedGroup == null) { return; } //</SnippetOpenCVFrameSourceGroups> //<SnippetOpenCVInitMediaCapture> _mediaCapture = new MediaCapture(); var settings = new MediaCaptureInitializationSettings() { SourceGroup = selectedGroup, SharingMode = MediaCaptureSharingMode.ExclusiveControl, MemoryPreference = MediaCaptureMemoryPreference.Cpu, StreamingCaptureMode = StreamingCaptureMode.Video }; try { await _mediaCapture.InitializeAsync(settings); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed: " + ex.Message); return; } var colorFrameSource = _mediaCapture.FrameSources[colorSourceInfo.Id]; //</SnippetOpenCVInitMediaCapture> //<SnippetOpenCVFrameReader> BitmapSize size = new BitmapSize() // Choose a lower resolution to make the image processing more performant { Height = 480, Width = 640 }; _mediaFrameReader = await _mediaCapture.CreateFrameReaderAsync(colorFrameSource, MediaEncodingSubtypes.Argb32, size); _mediaFrameReader.FrameArrived += ColorFrameReader_FrameArrived_OpenCV; _imageElement.Source = new SoftwareBitmapSource(); _frameRenderer = new FrameRenderer(_imageElement); await _mediaFrameReader.StartAsync(); //</SnippetOpenCVFrameReader> }
/// <summary> /// Initializes a Project. /// </summary> /// <param name="size"> The size. </param> public Project(BitmapSize size) { this.Width = (int)size.Width; this.Height = (int)size.Height; }
public static Vector2 ToVector2(this BitmapSize size) { return(new Vector2(size.Width, size.Height)); }