private async void StartScan(object sender, EventArgs e) { var scale = 0.4; var stream = await TakePhoto(); Loader.IsRunning = true; Loader.IsVisible = true; LoaderGrid.IsVisible = true; await Task.Delay(10); var source = GetPixelMap(stream); var imaging = new ImagingManager(source); //source is PixelMap, you can find samples how to convert image to PixelMap imaging.AddFilter(new BicubicFilter(scale)); //Downscaling imaging.AddFilter(new CannyEdgeDetector()); //This filter contains Grayscale and Gaussian filter in it imaging.Render(); //Renders the image to use it further use var blobCounter = new BlobCounter() { ObjectsOrder = ObjectsOrder.Size }; imaging.AddFilter(blobCounter); imaging.Render(); //Following code finds largest quadratical blob List <Imaging.Library.Entities.Point> corners = null; var blobs = blobCounter.GetObjectsInformation(); foreach (var blob in blobs) { var points = blobCounter.GetBlobsEdgePoints(blob); var shapeChecker = new SimpleShapeChecker(); if (shapeChecker.IsQuadrilateral(points, out corners)) { break; } } imaging.UndoAll(); //Undo every filters applied var edgePoints = new EdgePoints(); edgePoints.SetPoints(corners.ToArray()); edgePoints = edgePoints.ZoomIn(scale); //Corrects points that found on downscaled image to original imaging.AddFilter(new QuadrilateralTransformation(edgePoints, true)); imaging.Render(); CovertedImage.Source = LoadImageFromPixelMap(imaging.Output); //imaging.Output gives that extracted rectangle shape from photo. Check out WPF sample how to save it. Loader.IsRunning = false; Loader.IsVisible = false; LoaderGrid.IsVisible = false; await Task.Delay(10); }
public void convert() { var imaging = new ImagingManager(Source); var scale = 0.4; imaging.AddFilter(new Imaging.Library.Filters.BasicFilters.BicubicFilter(scale)); //Downscaling imaging.Render(); imaging.AddFilter(new CannyEdgeDetector()); imaging.Render(); var blobCounter = new BlobCounter { ObjectsOrder = ObjectsOrder.Size }; imaging.AddFilter(blobCounter); imaging.Render(); List <Point> corners = null; var blobs = blobCounter.GetObjectsInformation(); foreach (var blob in blobs) { var points = blobCounter.GetBlobsEdgePoints(blob); var shapeChecker = new SimpleShapeChecker(); if (shapeChecker.IsQuadrilateral(points, out corners)) { break; } } var edgePoints = new EdgePoints(); edgePoints.SetPoints(corners.ToArray()); imaging.Render(); imaging.UndoAll(); edgePoints = edgePoints.ZoomIn(scale); imaging.AddFilter(new QuadrilateralTransformation(edgePoints, true)); imaging.Render(); var strm = StreamLoadFromPixel(imaging.Output); var memoryStream = new MemoryStream(); strm.CopyTo(memoryStream); DependencyService.Get <ISaveViewFile>().SaveAndViewAsync("out.jpg", memoryStream); myimg.Source = LoadFromPixel(imaging.Output); box.IsVisible = false; loading.IsVisible = false; loading.IsRunning = false; stackloading.IsVisible = false; }
private void ScanDocumentBtn_Click(object sender, EventArgs e) { var imaging = new ImagingManager(Source); var scale = 0.4; imaging.AddFilter(new BicubicFilter(scale)); //Downscaling imaging.Render(); imaging.AddFilter(new CannyEdgeDetector()); imaging.Render(); var blobCounter = new BlobCounter { ObjectsOrder = ObjectsOrder.Size }; imaging.AddFilter(blobCounter); imaging.Render(); List <Point> corners = null; var blobs = blobCounter.GetObjectsInformation(); foreach (var blob in blobs) { var points = blobCounter.GetBlobsEdgePoints(blob); var shapeChecker = new SimpleShapeChecker(); if (shapeChecker.IsQuadrilateral(points, out corners)) { break; } } var edgePoints = new EdgePoints(); edgePoints.SetPoints(corners.ToArray()); imaging.Render(); imaging.UndoAll(); edgePoints = edgePoints.ZoomIn(scale); imaging.AddFilter(new QuadrilateralTransformation(edgePoints, true)); imaging.Render(); var image = LoadFromPixelMap(imaging.Output); var imageView = FindViewById <ImageView>(Resource.Id.myImageView); imageView.SetImageBitmap(image); }
private void EdgeDetection() { var dialog = new OpenFileDialog { InitialDirectory = @"D:\OneDrive", Filter = "Bitmap|*.bmp;*.jpg;*.jpeg;*.png;" }; if (dialog.ShowDialog() == true) { var scale = 0.4; var path = dialog.FileName; var sources = new PixelMap[2]; GetPixelMap(path, sources); var source = sources[0]; var imaging = new ImagingManager(source); imaging.AddFilter(new BicubicFilter(scale)); //Downscaling imaging.Render(); imaging.AddFilter(new CannyEdgeDetector()); imaging.Render(); var blobCounter = new BlobCounter { ObjectsOrder = ObjectsOrder.Size }; imaging.AddFilter(blobCounter); imaging.Render(); List <Point> corners = null; var blobs = blobCounter.GetObjectsInformation(); foreach (var blob in blobs) { var points = blobCounter.GetBlobsEdgePoints(blob); var shapeChecker = new SimpleShapeChecker(); if (shapeChecker.IsQuadrilateral(points, out corners)) { break; } } var edgePoints = new EdgePoints(); edgePoints.SetPoints(corners.ToArray()); var line1 = new Line { X1 = edgePoints.TopLeft.X, Y1 = edgePoints.TopLeft.Y, X2 = edgePoints.BottomLeft.X, Y2 = edgePoints.BottomLeft.Y }; var line2 = new Line { X1 = edgePoints.BottomLeft.X, Y1 = edgePoints.BottomLeft.Y, X2 = edgePoints.BottomRight.X, Y2 = edgePoints.BottomRight.Y }; var line3 = new Line { X1 = edgePoints.BottomRight.X, Y1 = edgePoints.BottomRight.Y, X2 = edgePoints.TopRight.X, Y2 = edgePoints.TopRight.Y }; var line4 = new Line { X1 = edgePoints.TopRight.X, Y1 = edgePoints.TopRight.Y, X2 = edgePoints.TopLeft.X, Y2 = edgePoints.TopLeft.Y }; var pixel = new Pixel(255, 255, 0, 0); imaging.AddFilter(new LineDrawFilter(line1, pixel)); imaging.AddFilter(new LineDrawFilter(line2, pixel)); imaging.AddFilter(new LineDrawFilter(line3, pixel)); imaging.AddFilter(new LineDrawFilter(line4, pixel)); imaging.Render(); image.Source = LoadFromPixelMap(imaging.Output); imaging.UndoAll(); edgePoints = edgePoints.ZoomIn(scale); imaging.AddFilter(new QuadrilateralTransformation(edgePoints, true)); imaging.Render(); image2.Source = LoadFromPixelMap(imaging.Output); SaveImageToFile(LoadFromPixelMap(imaging.Output), @"D:\Desktop\2.jpg"); } }