public void Example2() { var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon.webp"); // Use SkiaSharp to load a WEBP image: var bmp = MemoryBitmap.Load(filePath, Codecs.SkiaCodec.Default); // Use OpenCV to resize the image: var span = bmp .WithOpenCv() .ToResizedMemoryBitmap(50, 50, OpenCvSharp.InterpolationFlags.Lanczos4) .AsSpanBitmap(); // Use GDI to draw a triangle: var a = new System.Drawing.Point(5, 5); var b = new System.Drawing.Point(45, 45); var c = new System.Drawing.Point(5, 45); span .WithGDI() .Draw(dc => dc.DrawPolygon(System.Drawing.Pens.Red, new[] { a, b, c })); // Use Imagesharp to save to PNG span.AttachToCurrentTestAll("shannon.png"); }
public void CalculateImageBlurFactor(string filePath) { filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, filePath); // load image using GDI var bitmap = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .AsSpanBitmap(); var blurfactor1 = Processing.SharpnessEvaluator.Evaluate(bitmap, 0.25); // blur with openCV bitmap.WithOpenCv().ApplyBlur((5, 5)); var blurfactor2 = Processing.SharpnessEvaluator.Evaluate(bitmap, 0.25); // blur with openCV bitmap.WithOpenCv().ApplyBlur((32, 32)); var blurfactor3 = Processing.SharpnessEvaluator.Evaluate(bitmap, 0.25); TestContext.WriteLine($"{filePath} => {blurfactor1}, {blurfactor2}, {blurfactor3}"); bitmap.AttachToCurrentTestAll("final.png"); }
public void Example1() { var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon.webp"); // Use SkiaSharp to load a WEBP image: var bmp = MemoryBitmap.Load(filePath, Codecs.SkiaCodec.Default); // Use OpenCV to resize the image: /* * bmp = bmp * .WithOpenCv() * .ToResizedMemoryBitmap(50, 50, OpenCvSharp.InterpolationFlags.Lanczos4); */ using (var proxy = bmp.UsingOpenCv()) { proxy.Mat.Circle(new OpenCvSharp.Point(150, 150), 35, OpenCvSharp.Scalar.Red, 10); // proxy.Mat.Blur(new OpenCvSharp.Size(4, 4)); // OpenCvSharp.Cv2.Blur(proxy.Mat, proxy.Mat, new OpenCvSharp.Size(4, 4)); } using (var proxy = bmp.UsingGDI()) { // Use GDI to draw a triangle: var a = new System.Drawing.Point(5, 5); var b = new System.Drawing.Point(50, 50); var c = new System.Drawing.Point(5, 50); proxy.Canvas.DrawPolygon(System.Drawing.Pens.Red, new[] { a, b, c }); } using (var proxy = bmp.UsingImageSharp()) { proxy.Image.Mutate(ipc => ipc.DrawPolygon(SixLabors.ImageSharp.Color.Blue, 2, (50, 5), (50, 50), (5, 5))); } using (var proxy = bmp.UsingSkiaSharp()) { var p0 = new SkiaSharp.SKPoint(5, 25); var p1 = new SkiaSharp.SKPoint(45, 25); using var skiaPaint = new SkiaSharp.SKPaint { TextSize = 64.0f, IsAntialias = true, StrokeWidth = 20, Color = new SkiaSharp.SKColor(0, 255, 0), Style = SkiaSharp.SKPaintStyle.Fill }; proxy.Canvas.DrawLine(p0, p1, skiaPaint); proxy.Canvas.DrawText("SkiaSharp", new SkiaSharp.SKPoint(5, 200), skiaPaint); } // Use Imagesharp to save to PNG bmp.Save(AttachmentInfo.From("shannon.png")); }
public void DrawMemoryAsImageSharp() { var mem = MemoryBitmap.Load(ResourceInfo.From("shannon.jpg"), Codecs.GDICodec.Default); mem.OfType <Pixel.BGRA32>() .AsSpanBitmap() .ReadAsImageSharp(img => { AttachmentInfo.From("result.png").WriteImage(img); return(0); }); }
public void LoadImage(string filePath) { filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, filePath); var membmp = MemoryBitmap.Load(filePath, Codecs.OpenCvCodec.Default); membmp.Save(AttachmentInfo.From("Result.png")); }
public void TestTransform(bool useBilinear) { var src = LoadShannonImage().OfType <Pixel.BGR24>(); src.Save(new AttachmentInfo("input.png")); var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\cat.png"); var cat00 = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .OfType <Pixel.BGRA32>(); filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\QRCode.png"); var qrcode = MemoryBitmap .Load(filePath, Codecs.GDICodec.Default) .OfType <Pixel.BGRA32>(); var x = Matrix3x2.CreateScale(0.75f, 0.75f) * Matrix3x2.CreateRotation(0.25f); x.Translation = new Vector2(20, 20); Matrix3x2.Invert(x, out var xx); var dst = new MemoryBitmap <Pixel.BGR24>(512, 512); using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"Transform {(int)t.TotalMilliseconds}ms"))) { dst.AsSpanBitmap().SetPixels(xx, src.AsSpanBitmap(), useBilinear); } for (float r = 0.1f; r < 1; r += 0.2f) { // 1st API var xform = Matrix3x2.CreateRotation(r) * Matrix3x2.CreateTranslation(50, 15); xform = Matrix3x2.CreateTranslation(-50, -50) * xform * Matrix3x2.CreateTranslation(50, 50); xform = xform * Matrix3x2.CreateScale(3, 3); dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r); DrawBounds(dst, cat00.Bounds, xform, Colors.Red); // 2nd API xform *= Matrix3x2.CreateTranslation(0, 150); dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r); DrawBounds(dst, cat00.Bounds, xform, Colors.Red); } dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(3), cat00.AsSpanBitmap(), useBilinear); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(-.6f) * Matrix3x2.CreateTranslation(40, 200), cat00.AsSpanBitmap(), useBilinear); dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(.3f) * Matrix3x2.CreateRotation(1) * Matrix3x2.CreateTranslation(150, 300), qrcode.AsSpanBitmap(), useBilinear); dst.Save(new AttachmentInfo("transformed.png")); }
public void LoadKinect2ColorFrame() { TestContext.CurrentContext.AttachFolderBrowserShortcut(); var src = MemoryBitmap <ushort> .Load(ResourceInfo.From("Kinect2Color.InteropBmp")); var dst = new MemoryBitmap <Pixel.BGR24>(src.Width, src.Height); dst.AsSpanBitmap().SetPixelsFromYUY2(src); dst.Save(AttachmentInfo.From("kinect2color.jpg")); }
private static MemoryBitmap LoadShannonImage() { var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon.jpg"); // load a bitmap with SkiaSharp, which is known to support WEBP. var mem = MemoryBitmap.Load(filePath, Codecs.GDICodec.Default); var mem2 = new MemoryBitmap(mem.Width, mem.Height, Pixel.BGR24.Format); mem2.SetPixels(0, 0, mem); return(mem2); }