private static void WriteResult(Shape shape, ImageTemplateResult result) { Console.WriteLine("\tShape: \t" + shape.Label); Console.WriteLine("\tTemplate:\t" + result.Name + "\t" + result.Score.ToString() + "\t" + result.Confidence.ToString()); foreach (ImageMatchError error in result.Errors) { Console.WriteLine("\t\tErrors:\t" + error.Type.ToString() + "\t" + error.Detail.ToString() + "\t" + error.Severity.ToString()); } Console.WriteLine("\t\tMap (Unknown part (believed from SSR) --> Template part):"); foreach (KeyValuePair <string, string> pair in result.Map.MapWithPartNames) { Console.WriteLine("\t\t\t" + pair.Key + "\t" + pair.Value); } Console.WriteLine(); }
private void InitializePanel(Panel panel, ImageTemplateResult result) { InkOverlay ink = new InkOverlay(panel); foreach (Sketch.Substroke s in result.SubstrokesUsedInMatch) { ink.Ink.CreateStroke(s.PointsAsSysPoints); ink.Ink.Strokes[ink.Ink.Strokes.Count - 1].DrawingAttributes.Color = Color.Black; } foreach (Sketch.Substroke s in result.SubstrokesNOTUsedInMatch) { ink.Ink.CreateStroke(s.PointsAsSysPoints); ink.Ink.Strokes[ink.Ink.Strokes.Count - 1].DrawingAttributes.Color = Color.Red; } ScaleAndMoveInk(ref ink, panel); }
private void loadTestSymbolsToolStripMenuItem_Click(object sender, EventArgs e) { bool openSuccess; List <string> sketches = General.SelectOpenFiles(out openSuccess, "Sketches containing test shapes", "Labeled XML Sketches (*.labeled.xml)|*.labeled.xml"); if (!openSuccess) { MessageBox.Show("Unable to load sketches"); return; } //m_Recognizer = ImageAlignerRecognizer.Load("C:\\Reco.iar"); //m_Recognizer = ImageAlignerRecognizer.Load("C:\\Documents and Settings\\eric\\My Documents\\Trunk\\Code\\Recognition\\ImageAligner\\TrainedRecognizers\\ImageAlignerRecognizerNBEST.iar"); int numRight = 0; int numWrong = 0; Dictionary <Shape, ImageTemplateResult> results = new Dictionary <Shape, ImageTemplateResult>(); foreach (string sketchFile in sketches) { Sketch.Sketch sketch = new ReadXML(sketchFile).Sketch; sketch = General.ReOrderParentShapes(sketch); foreach (Shape shape in sketch.Shapes) { if (General.IsGate(shape)) { if (shape.Substrokes[0].Labels[0] == shape.Label) { ImageTemplateResult result = m_Recognizer.Recognize(shape); results.Add(shape, result); if (result != null && result.Name == shape.Label) { numRight++; } else { numWrong++; } } } } } }
static void Main(string[] args) { //if (args.Length == 0) //return; if (NUMBEST != 0) { string filePath = Directory.GetCurrentDirectory(); if (filePath.Contains("\\Code\\")) { filePath = filePath.Substring(0, filePath.IndexOf("\\Code\\") + 1); } TrainByNBest(filePath + "Data\\Gate Study Data\\LabeledPartsSketches", "*.xml"); return; } List <KeyValuePair <string, Dictionary <string, object> > > data = new List <KeyValuePair <string, Dictionary <string, object> > >(); Dictionary <string, List <string>[]> user2sketches = GetSketchesPerUser(args[0], args[1]); // Foreach user: train each of the recognizers foreach (KeyValuePair <string, List <string>[]> pair in user2sketches) { string user = pair.Key; int userNum; bool good = int.TryParse(user.Substring(0, 2), out userNum); if (good && userNum <= 0) { continue; } User u = new User(userNum.ToString()); PlatformUsed platform = PlatformUsed.TabletPC; if (user.Contains("P")) { platform = PlatformUsed.Wacom; } //Console.WriteLine("User: "******"NOT") { List <Substroke> strokes = new List <Substroke>(); foreach (Substroke s in shape.Substrokes) { if (s.Labels[s.Labels.Length - 1] == "Bubble") { strokes.Add(s); break; } } XmlStructs.XmlShapeAttrs attr = new XmlStructs.XmlShapeAttrs(); attr.Type = "NOTBUBBLE"; Shape nb = new Shape(strokes, attr); recognizer.Add(nb); } } } } recognizer.Save("ImageAlignerRecognizer" + user + ".iar"); int numRight = 0; int numWrong = 0; Dictionary <Shape, ImageTemplateResult> results = new Dictionary <Shape, ImageTemplateResult>(); foreach (string sketchFile in testFiles) { Sketch.Sketch sketch = new ReadXML(sketchFile).Sketch; sketch = General.ReOrderParentShapes(sketch); foreach (Shape shape in sketch.Shapes) { if (General.IsGate(shape) && shape.Substrokes[0].Labels[0] == shape.Label && shape.Label != "LabelBox") { ImageTemplateResult result = recognizer.Recognize(shape); if (result != null) { results.Add(shape, result); if (result.Name == shape.Label) { numRight++; } else { numWrong++; } } } } } int total = numRight + numWrong; Console.WriteLine("User: "******" Correct: " + numRight.ToString() + "/" + total.ToString()); if (args.Length > 2 && args[2] == "-v") { foreach (KeyValuePair <Shape, ImageTemplateResult> kv in results) { WriteResult(kv.Key, kv.Value); } } } }