public static AssemblyNode CreateProject() { string rootpath = Path.GetFullPath("tests/"); DominoAssembly main = new DominoAssembly(); main.Save(Path.Combine(rootpath, "main.DProject")); main.colorPath = "colors.DColor"; var mainnode = new AssemblyNode(Path.Combine(rootpath, "main.DProject")); FieldParameters field1 = new FieldParameters(Path.GetFullPath("tests/field1.DObject"), "mountain.jpg", main.colorPath, 8, 8, 24, 8, 10000, Emgu.CV.CvEnum.Inter.Lanczos4, new CieDe2000Comparison(), new Dithering(), new NoColorRestriction()); field1.Save(); new FieldNode("field1.DObject", main); StreamReader sr = new StreamReader(new FileStream("Structures.xml", FileMode.Open)); XElement xml = XElement.Parse(sr.ReadToEnd()); StructureParameters structure = new StructureParameters(Path.GetFullPath("tests/structure.DObject"), "transparent.png", xml.Elements().ElementAt(1), 30000, main.colorPath, ColorDetectionMode.Cie1976Comparison, new Dithering(), AverageMode.Corner, new NoColorRestriction(), true); structure.Save(); new StructureNode("structure.DObject", main); DominoAssembly sub = new DominoAssembly(); string subpath = "sub.DProject"; sub.Save(Workspace.AbsolutePathFromReference(ref subpath, main)); sub.colorPath = "colors.DColor"; new AssemblyNode("sub.DProject", main); FieldParameters sub1 = new FieldParameters(Path.GetFullPath("tests/field2.DObject"), "transparent.png", main.colorPath, 8, 8, 24, 8, 10000, Emgu.CV.CvEnum.Inter.Lanczos4, new CieDe2000Comparison(), new Dithering(), new NoColorRestriction()); field1.Save(); new FieldNode("field2.DObject", sub); new FieldNode("field1.DObject", sub); sub.Save(); foreach (AssemblyNode node in main.children.Where(child => child is AssemblyNode)) { node.obj.Save(); } if (field1 == ((FieldNode)sub.children[1]).obj) { Console.WriteLine("references to field1 identical"); } main.Save(mainnode.Path); PrintProjectStructure(mainnode, ""); return(mainnode); }
static void FieldTest(String path) { Console.WriteLine("======= FIELD TEST ======="); //Progress<String> progress = new Progress<string>(pr => Console.WriteLine(pr)); //Mat mat = CvInvoke.Imread(path, ImreadModes.Unchanged); FieldParameters p = new FieldParameters(Path.GetFullPath("tests/FieldTest.DObject"), path, "colors.DColor", 8, 8, 24, 8, 20000, Inter.Lanczos4, ColorDetectionMode.Cie1976Comparison, new Dithering(), new NoColorRestriction()); ((FieldCalculation)p.PrimaryCalculation).TransparencySetting = 128; var watch = System.Diagnostics.Stopwatch.StartNew(); p.Generate().GenerateImage().Save("tests/fieldtests_before_filters.png"); watch.Stop(); Console.WriteLine("elapsed: " + watch.ElapsedMilliseconds); /*watch.Restart(); * p.ditherMode = new FloydSteinbergDithering(); * watch.Stop(); * Console.WriteLine("elapsed: " + watch.ElapsedMilliseconds); * watch.Restart(); * p.Generate().GenerateImage().Save("tests/fieldtest_floyd_steinberg.png"); * p.ditherMode = new Dithering(); * watch.Stop(); * Console.WriteLine("elapsed: " + watch.ElapsedMilliseconds); * watch.Restart(); * p.Generate().GenerateImage().Save("tests/fieldtest_after_dithering.png"); * p.ditherMode = new StuckiDithering(); * watch.Stop(); * Console.WriteLine("elapsed: " + watch.ElapsedMilliseconds); * watch.Restart(); * p.Generate().GenerateImage().Save("tests/fieldtest_stucki.png"); * p.ditherMode = new JarvisJudiceNinkeDithering(); * watch.Stop(); * Console.WriteLine("elapsed: " + watch.ElapsedMilliseconds); * watch.Restart(); * p.Generate().GenerateImage().Save("tests/fieldtest_jjn.png"); * watch.Stop(); * Console.WriteLine("elapsed: " + watch.ElapsedMilliseconds);*/ //DominoTransfer t = await Dispatcher.CurrentDispatcher.Invoke(async () => await Task.Run(() => p.Generate())); // Filtertests für ein Logo oder ähnliches /*var erster = ((BlendFileFilter)p.ImageFilters[0]); * erster.RotateAngle = 30; * erster.ScaleX = 0.5; * erster.ScaleY = 0.3; * erster.CenterX = erster.GetSizeOfMat().Width * 0.6; * erster.CenterY = erster.GetSizeOfMat().Height * 0.6; * var zweiter = new BlendTextFilter(); * zweiter.FontSize = 40; * zweiter.FontFamily = "Calibri"; * zweiter.Text = "Hallo Welt"; * zweiter.Color = System.Drawing.Color.Green; * p.ImageFilters.Add(zweiter); * zweiter.CenterX = 500; * zweiter.CenterY = 500;*/ // Filtertests für Bilder // Helligkeit / Kontrast /*var hell = new ContrastLightFilter(); * hell.Alpha = 1.5; * hell.Beta = -150; * p.ImageFilters.Add(hell);*/ //var gamma = new GammaCorrectFilter(); //gamma.Gamma = 1.1; //p.ImageFilters.Add(gamma); /*var blur = new GaussianSharpenFilter(); * blur.KernelSize = 21; * blur.StandardDeviation = 5; * blur.SharpenWeight = 0.5; * p.ImageFilters.Add(blur);*/ /*var replace = new ReplaceColorFilter(); * replace.BeforeColor = System.Drawing.Color.LightBlue; * replace.AfterColor = System.Drawing.Color.Red; * replace.Tolerance = 50; * p.ImageFilters.Add(replace);*/ //p.ColorFilters.Add(new ChangeCountColorFilter() { Index = 14, NewCount = 0 }); //p.ColorFilters.Add(new ChangeRGBColorFilter() { Index = 30, Color = Colors.Green }); //p.Generate(); /*Console.WriteLine(String.Join("\n", p.counts)); * Console.WriteLine("Size: " + p.Generate().shapes.Count()); * watch.Stop(); * Console.WriteLine(watch.ElapsedMilliseconds); * watch = System.Diagnostics.Stopwatch.StartNew(); * Mat b2 = p.Generate().GenerateImage(Colors.Transparent, 2000); * watch.Stop(); * Console.WriteLine(watch.ElapsedMilliseconds); * b2.Save("tests/FieldTest.png"); * FileStream fs = new FileStream(@"tests/FieldPlanTest.html", FileMode.Create); * StreamWriter sw = new StreamWriter(fs);*/ /*sw.Write(p.GetHTMLProcotol(new ObjectProtocolParameters() * { * backColorMode = ColorMode.Normal, * foreColorMode = ColorMode.Intelligent, * orientation = Core.Orientation.Horizontal, * reverse = false, * summaryMode = SummaryMode.Large, * textFormat = "<font face=\"Verdana\">", * templateLength = 20, * textRegex = "%count% %color%", * title = "Field" * }));*/ /*p.SaveXLSFieldPlan("tests/ExcelFieldPlanTest.xlsx", new ObjectProtocolParameters() * { * backColorMode = ColorMode.Normal, * foreColorMode = ColorMode.Intelligent, * orientation = Core.Orientation.Horizontal, * reverse = false, * summaryMode = SummaryMode.Large, * textFormat = "<font face=\"Verdana\">", * templateLength = 20, * textRegex = "%count%", * title = "Field", * path = Directory.GetCurrentDirectory() * * });*/ //sw.Close(); p.Save(); watch = Stopwatch.StartNew(); int[] counts = Workspace.LoadColorList <FieldParameters>(Path.GetFullPath("tests/FieldTest.DObject")).Item2; watch.Stop(); Console.WriteLine("Preview Load Time: " + watch.ElapsedMilliseconds); Console.WriteLine(String.Join(", ", counts)); Workspace.Clear(); watch = Stopwatch.StartNew(); FieldParameters loaded = Workspace.Load <FieldParameters>(Path.GetFullPath("tests/FieldTest.DObject")); loaded.Generate(); watch.Stop(); Console.WriteLine("Load Time: " + watch.ElapsedMilliseconds); //loaded.last.GenerateImage(Colors.Transparent).Save("tests/afterLoad.png"); Console.WriteLine(p.colors == loaded.colors); watch = Stopwatch.StartNew(); int[] counts2 = Workspace.LoadColorList <FieldParameters>(Path.GetFullPath("tests/FieldTest.DObject")).Item2; watch.Stop(); Console.WriteLine("Preview Load Time: " + watch.ElapsedMilliseconds); Console.WriteLine(String.Join(", ", counts2)); Console.WriteLine("Number of image filters: " + ((FieldReadout)loaded.PrimaryImageTreatment).ImageFilters.Count); //loaded.ImageHeight = 1500; //loaded.ColorFilters.Add(new ChangeCountColorFilter() { Index = 14, NewCount = 0 }); //loaded.ColorFilters.Add(new ChangeRGBColorFilter() { Index = 30, Color = Colors.Green }); //t = loaded.Generate(); p.Generate().GenerateImage().Save("tests/fieldtest_after_load.png"); Console.WriteLine(String.Join(", ", loaded.Counts)); }