Ejemplo n.º 1
0
        public void Should_Build_Proper_Mapping_Fast()
        {
            var ts = TestSet.Init("1280x720");

            // create map
            var mapBuilder = new InpaintMapBuilder();
            var imageArea  = Area2D.Create(0, 0, ts.Picture.Width, ts.Picture.Height);

            mapBuilder.InitNewMap(imageArea);
            var inpaintArea = ts.RemoveMarkup.ToArea();

            mapBuilder.SetInpaintArea(inpaintArea);

            for (int i = 0; i < ts.Donors.Count; i++)
            {
                var donorArea = ts.Donors[i].ToArea();
                mapBuilder.AddDonor(donorArea);
            }

            var sw = new Stopwatch();

            sw.Restart();
            mapBuilder.Build();
            sw.Stop();

            sw.ElapsedMilliseconds.ShouldBeLessThan(800);
        }
Ejemplo n.º 2
0
        public void Should_Build_Proper_Mapping()
        {
            var testName = "InpaintMapBuilderTest";
            var ts       = TestSet.Init("256x128");

            // create map
            var mapBuilder = new InpaintMapBuilder();
            var imageArea  = Area2D.Create(0, 0, ts.Picture.Width, ts.Picture.Height);

            mapBuilder.InitNewMap(imageArea);
            var inpaintArea = ts.RemoveMarkup.ToArea();

            mapBuilder.SetInpaintArea(inpaintArea);

            for (int i = 0; i < ts.Donors.Count; i++)
            {
                var donorArea = ts.Donors[i].ToArea();
                mapBuilder.AddDonor(donorArea);
            }

            var sw = new Stopwatch();

            sw.Restart();
            var mapping = mapBuilder.Build();

            sw.Stop();

            // convert mapping to areas
            var areaPairs = (mapping as IAreasMapping).AssociatedAreasAsc;

            for (int i = 0; i < areaPairs.Length; i++)
            {
                var areaPair = areaPairs[i];

                SaveToOutput(areaPair.Item1, $"dest{i}", testName, ts.Path, Color.Red);
                SaveToOutput(areaPair.Item2, $"src{i}", testName, ts.Path, Color.Green);
            }

            // compare output and references
            string[] reffiles = Directory.GetFiles($"{ts.Path}\\{testName}\\refs", "*.*", SearchOption.TopDirectoryOnly);
            string[] outfiles = Directory.GetFiles($"{ts.Path}\\{testName}\\output", "*.*", SearchOption.TopDirectoryOnly);

            reffiles.Length.ShouldBe(outfiles.Length);

            if (reffiles.Length != outfiles.Length)
            {
                foreach (var refFilePath in reffiles)
                {
                    var refFileName = Path.GetFileName(refFilePath);
                    var outFilePath = $"{ts.Path}\\{testName}\\output\\{refFileName}";

                    File.Exists(outFilePath).ShouldBeTrue();

                    var refArea = new Bitmap(refFilePath).ToArea();
                    var outArea = new Bitmap(outFilePath).ToArea();

                    refArea.IsSameAs(outArea).ShouldBeTrue();
                }
            }
        }