public void ZXingFindQRCode(string filePath, string expected) { // http://www.cvsandbox.com/ filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, filePath); using var image = SixLabors.ImageSharp.Image.Load <SixLabors.ImageSharp.PixelFormats.Rgba32>(filePath); // detect code: var code = image.ReadAsSpanBitmap(self => self.ScanAndDecodeQRCode()); if (string.IsNullOrWhiteSpace(expected)) { Assert.Null(code); return; } Assert.AreEqual(expected, code.Text); // report result: TestContext.WriteLine($"Code found: {code?.Text}"); var points = code.ResultPoints.Select(item => (item.X, item.Y)).ToArray(); var font = SixLabors.Fonts.SystemFonts.CreateFont("Arial", 20); image.Mutate(dc => dc.DrawPolygon(SixLabors.ImageSharp.Color.Red, 3, points)); image.Mutate(dc => dc.DrawText(code.Text.Replace("/", ":"), font, SixLabors.ImageSharp.Color.Red, new POINT(5, 5))); AttachmentInfo.From("result.png").WriteImage(image); }
public void LoadImage(string filePath) { TestContext.CurrentContext.AttachFolderBrowserShortcut(); var codecs = new IBitmapDecoder[] { OpenCvCodec.Default, GDICodec.Default, WPFCodec.Default, ImageSharpCodec.Default, STBCodec.Default, SkiaCodec.Default }; foreach (var decoder in codecs.OfType <IBitmapDecoder>()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var bitmap = MemoryBitmap.Load(ResourceInfo.From(filePath), decoder); sw.Stop(); TestContext.WriteLine($"Loading {System.IO.Path.GetFileName(filePath)} with {decoder} tool {sw.ElapsedMilliseconds}"); foreach (var encoder in codecs.OfType <IBitmapEncoder>()) { // System.Diagnostics.Debug.Assert(!(decoder is WPFCodec && encoder is SkiaCodec)); var fname = $"{decoder.GetType().Name}-To-{encoder.GetType().Name}.png"; bitmap.Save(new AttachmentInfo(fname), encoder); fname = $"{decoder.GetType().Name}-To-{encoder.GetType().Name}.jpg"; bitmap.Save(new AttachmentInfo(fname), encoder); fname = $"{decoder.GetType().Name}-To-{encoder.GetType().Name}-Gray.jpg"; bitmap .AsSpanBitmap() .ToMemoryBitmap(Pixel.Luminance8.Format) .Save(AttachmentInfo.From(fname), encoder); } } }
public void SaveMjpeg() { var f1 = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon.jpg"); var f2 = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon-blurred.jpg"); var ff1 = MemoryBitmap.Load(f1, GDICodec.Default); var ff2 = MemoryBitmap.Load(f2, GDICodec.Default); IEnumerable <MemoryBitmap> _getFrames() { for (int i = 0; i < 10; ++i) { yield return(ff1); yield return(ff1); yield return(ff1); yield return(ff1); yield return(ff2); yield return(ff2); yield return(ff2); yield return(ff2); } } AttachmentInfo .From("video.avi") .WriteAVI(_getFrames()); }
public void DetectImageFeatures(string filePath) { filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, filePath); var img = Image.Load <SixLabors.ImageSharp.PixelFormats.Rgb24>(filePath); AttachmentInfo .From("original.png") .WriteObject(f => img.Save(f)); OpenCvSharp.Mat _Process(OpenCvSharp.Mat src) { var sil_mask = OpenCVProcessing.ExtractSubjectSiluette(src); // return sil_mask; var sub_col_siluette = OpenCVProcessing.ExtractBlobTexture(src, sil_mask); var foot_seg_marker = OpenCVProcessing.ExtractSegmentalMarker(sub_col_siluette); return(foot_seg_marker); } img.WriteAsSpanBitmap(self => self.WithOpenCv().Apply(_Process)); AttachmentInfo .From("result.png") .WriteObject(f => img.Save(f)); // var img2 = img.AsSpanBitmap().AsOpenCVSharp().CloneMutated(_Process); // AttachmentInfo.From("result2.png").WriteObject(f => img2.Save(f.FullName)); }
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 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 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 LoadWebpToImageSharp() { // load a bitmap with SkiaSharp, which is known to support WEBP. var mem = MemoryBitmap.Load(ResourceInfo.From("shannon.webp"), Codecs.SkiaCodec.Default); using (var proxy = mem.UsingImageSharp()) { mem.Save(AttachmentInfo.From("ImageSharp.png")); } }
public void TestRenderReferenceOutlinesInWPF() { var renderTarget = new WPFRenderTarget(512, 512); renderTarget.Draw(DrawDirectVsPolygon); AttachmentInfo .From("referenceWPF.png") .WriteObject(f => renderTarget.SaveToPNG(f)); }
public void TestRender3DSceneToBitmap(string sceneName) { var scene = SceneFactory.CreateRecord3D(sceneName); scene.DrawCube(Matrix4x4.Identity, COLOR.Red, COLOR.Green, COLOR.Blue); AttachmentInfo .From($"{sceneName}.png") .WriteObject(f => Canvas2DFactory.SaveToBitmap(f, 1024, 1024, null, scene)); }
public static void AttachToCurrentTest(this ModelRoot model, string fileName, Animation animation, float time) { // wavefront does't like files paths with spaces because // some implementations would not find the material file fileName = fileName.Replace(" ", "_"); AttachmentInfo .From(fileName) .WriteObject(f => model.SaveAsWavefront(f.FullName, animation, time)); }
public void RenderSceneToSVG() { using var svg = SVGSceneDrawing2D.CreateGraphic(); var scene = SceneFactory.CreateRecord3D("Scene1"); scene.DrawTo(svg, 1024, 1024, new Vector3(7, 5, 20)); AttachmentInfo.From("document.svg").WriteAllText(svg.ToSVGContent()); }
public void TestSVG() { using (var svg = SVGSceneDrawing2D.CreateGraphic()) { svg.DrawLine((0, 0), (100, 100), 2, (COLOR.SkyBlue, LineCapStyle.Round, LineCapStyle.Triangle)); svg.DrawRectangle((10, 10), (80, 80), (COLOR.Blue, 4)); svg.DrawEllipse(new Vector2(50, 50), 70, 70, (COLOR.Red, 2)); AttachmentInfo.From("document.svg").WriteAllText(svg.ToSVGContent()); } }
public void DrawShapes() { var doc = new PlotlyDocumentBuilder(); using (var dc = doc.CreateShapes2DContext()) { dc.DrawCircle((2, 2), 7, System.Drawing.Color.Red); } AttachmentInfo.From("Drawing.html").WriteAllText(doc.ToHtml()); }
public void ParsePathAndFill(string path) { using (var svg = SVGSceneDrawing2D.CreateGraphic()) { svg.DrawPath(System.Numerics.Matrix3x2.Identity, path, (System.Drawing.Color.Red, System.Drawing.Color.Blue, 2)); var document = svg.ToSVGContent(); AttachmentInfo.From("document.svg").WriteAllText(document); } }
public void DrawGDIAsImageSharp() { using var gdi = System.Drawing.Image.FromFile(ResourceInfo.From("shannon.jpg")); using var bmp = new System.Drawing.Bitmap(gdi); using var ptr = bmp.UsingPointerBitmap(); ptr.AsPointerBitmap() .AsSpanBitmapOfType <Pixel.BGRA32>() .ReadAsImageSharp(img => AttachmentInfo.From("result.png").WriteImage(img)); }
public void LoadAndSaveInteropFormat() { TestContext.CurrentContext.AttachFolderBrowserShortcut(); var img1 = MemoryBitmap <Pixel.BGR24> .Load(ResourceInfo.From("shannon.jpg")); var tmpPath = AttachmentInfo.From("shannon.interopbmp").WriteObject(f => img1.Save(f)); var img2 = MemoryBitmap <Pixel.BGR24> .Load(tmpPath.FullName); img2.Save(AttachmentInfo.From("shannon.png")); }
public void DrawToPlanesTest() { var src = MemoryBitmap <Pixel.BGR24> .Load(ResourceInfo.From("shannon.jpg")); var dst = new SpanPlanesXYZ <float>(256, 256); var xform = System.Numerics.Matrix3x2.CreateScale(dst.Width / (float)src.Width, dst.Height / (float)src.Height); dst.SetPixels <Pixel.BGR24>(xform, src, true); dst.Save(AttachmentInfo.From("result.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")); }
public void DrawVolumes() { var scene = new Record3D(); scene.DrawPivot(System.Numerics.Matrix4x4.Identity, 2); scene.DrawCube(System.Numerics.Matrix4x4.CreateTranslation(5, 0, 0), Color.Red, Color.Green, Color.Blue); scene.DrawCube(System.Numerics.Matrix4x4.CreateTranslation(7, 0, 0), (Color.Black, 0.1f)); var doc = new PlotlyDocumentBuilder().Draw(scene); AttachmentInfo.From("Drawing.html").WriteAllText(doc.ToHtml()); }
public void TestFlip() { var src = LoadShannonImage(); src.Save(AttachmentInfo.From("input.png")); src.AsSpanBitmap().ApplyEffect(new Processing.BitmapMirror(true, false)); src.Save(AttachmentInfo.From("horizontalFlip.png")); src.AsSpanBitmap().ApplyEffect(new Processing.BitmapMirror(false, true)); src.Save(AttachmentInfo.From("VerticalFlip.png")); }
private static void _DrawTransformedBitmapWithMulAdd <TPixel>(float mul, float add) where TPixel : unmanaged { var src = MemoryBitmap <Pixel.BGR24> .Load(ResourceInfo.From("shannon.jpg")); var dst = new MemoryBitmap <TPixel>(256, 256); var xform = System.Numerics.Matrix3x2.CreateScale(dst.Width / (float)src.Width, dst.Height / (float)src.Height); dst.AsSpanBitmap().SetPixels <Pixel.BGR24>(xform, src, true, (mul, add)); dst.Save(AttachmentInfo.From($"result-{typeof(TPixel).Name}.jpg")); }
public void DumpTestAPI() { var type = typeof(TestClass); var API = DumpAssemblyAPI.GetTypeSignature(type.GetTypeInfo()).OrderBy(item => item).ToArray(); AttachmentInfo.From("TestAPI.txt").WriteTextLines(API); foreach (var l in API) { TestContext.WriteLine(l); } }
public void LoadImageWPF(string filePath) { filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, filePath); var uri = new Uri(filePath, UriKind.Absolute); var image = new System.Windows.Media.Imaging.BitmapImage(uri); var memory = image.ToMemoryBitmap(); memory.Save(AttachmentInfo.From("Result.png")); var writable = new System.Windows.Media.Imaging.WriteableBitmap(image); }
public void EncodeH264Frames() { var inputFrames = FFmpegAutoGen.DecodeFrames(ResourceInfo.From("count-video.mp4")); var finfo = AttachmentInfo .From("output.h264") .WriteVideo(inputFrames.Select(item => item.bitmap)); foreach (var(bitmap, state) in FFmpegAutoGen.DecodeFrames(finfo.FullName)) { var data = string.Join(" ", state.State); TestContext.WriteLine(data); } }
public void DumpToolkitAPI() { var assembly = typeof(Schema2.Toolkit).Assembly; var API = DumpAssemblyAPI .GetAssemblySignature(assembly) .OrderBy(item => item) .ToArray(); AttachmentInfo .From($"API.Toolkit.{Schema2.Asset.AssemblyInformationalVersion}.txt") .WriteTextLines(API); _CheckBackwardsCompatibility("API.Toolkit.1.0.0-alpha0011.txt", API); }
public void DecodeMp4Frames() { foreach (var(bitmap, state) in FFmpegAutoGen.DecodeFrames(ResourceInfo.From("count-video.mp4"))) { var data = string.Join(" ", state.State); TestContext.WriteLine(data); var idx = state.State["index"]; bitmap .AsSpanBitmap() .ToMemoryBitmap() .Save(AttachmentInfo.From($"frame{idx:D3}.jpg")); } }
public static void TestMeshDecoding() { var modelPath = TestFiles.GetSampleModelsPaths() .FirstOrDefault(item => item.Contains("BrainStem.glb")); var model = Schema2.ModelRoot.Load(modelPath); model.AttachToCurrentTest("reference.plotly"); var scene = model.DefaultScene; var decodedMeshes = scene.LogicalParent.LogicalMeshes.Decode(); var sceneTemplate = SceneTemplate.Create(scene); var sceneInstance = sceneTemplate.CreateInstance(); var duration = sceneInstance.Armature.AnimationTracks[0].Duration; sceneInstance.Armature.SetAnimationFrame(0, duration / 2); IEnumerable <(Vector3, Vector3, Vector3, int)> evaluateTriangles(DrawableInstance inst) { var mesh = decodedMeshes[inst.Template.LogicalMeshIndex]; foreach (var prim in mesh.Primitives) { foreach (var(idxA, idxB, idxC) in prim.TriangleIndices) { var posA = prim.GetPosition(idxA, inst.Transform); var posB = prim.GetPosition(idxB, inst.Transform); var posC = prim.GetPosition(idxC, inst.Transform); yield return(posA, posB, posC, 0xb0b0b0); } } } var worldTriangles = sceneInstance.SelectMany(item => evaluateTriangles(item)); var scenePlot = new PlotlyScene(); scenePlot.AppendTriangles(worldTriangles, c => c); AttachmentInfo .From("result.html") .WriteAllText(scenePlot.ToHtml()); }
public void TestCreateEmptyMesh() { // create a scenebuilder with an empty mesh var sb = new SceneBuilder(); sb.AddRigidMesh(VPOSNRM.CreateCompatibleMesh("Empty"), Matrix4x4.Identity); var schema = sb.ToGltf2(); Assert.AreEqual(0, schema.LogicalMeshes.Count, "SceneBuilder should detect empty meshes and remove them."); schema.CreateMesh("Empty2"); var fileName = AttachmentInfo.From("empty.glb").File.FullName; Assert.Throws <SharpGLTF.Validation.SchemaException>(() => schema.SaveGLB(fileName)); }
public void ResizeTest1(int dstSize) { var src = LoadShannonImage(); var dst = new MemoryBitmap(dstSize, dstSize, Pixel.BGR24.Format, dstSize * 3 + 17); BitmapsToolkit.FitPixels(src, dst, (0, 1)); var sw = System.Diagnostics.Stopwatch.StartNew(); BitmapsToolkit.FitPixels(src, dst, (0, 1)); var elapsed = sw.Elapsed; TestContext.WriteLine($"{elapsed.Milliseconds}ms {elapsed.Ticks}ticks"); src.Save(AttachmentInfo.From("input.png")); dst.Save(AttachmentInfo.From($"output_{dstSize}.png")); }