/// <summary> /// Recognizes a sketch of a circuit using the Flow. /// </summary> /// <param name="args">An unlabeled Sketch and a UserTriggered flag</param> /// <returns>A Labeled Sketch and </returns> public override RecognitionResult Recognize(RecognitionArgs args) { RecognitionResult result = new RecognitionResult(); result.UserTriggered = args.UserTriggered; // Only recognize when necessary if (!args.UserTriggered) { return(result); } // Run recognition and fill result Flow.Flow flow; try { // Try to run the flow flow = new Flow.Flow(args.Sketch); // Grab sketch result.Sketch = flow.SketchHolder; } catch (Exception e) { // Catch all other exceptions System.Windows.MessageBox.Show("General Exception from sketch recognizer component: \n" + e.Message); // Return unrecognized sketch result.Sketch = args.Sketch; } return(result); }
public override RecognitionResult Recognize(RecognitionArgs args) { Console.WriteLine("Sending sample sketch as recognition result"); Sketch.Sketch resultSketch = ((new ReadXML(TestSketchFilePath)).Sketch); RecognitionResult result = new RecognitionResult(); result.UserTriggered = true; result.Sketch = resultSketch; return(result); }
/// <summary> /// Runs CircuitRec on a sketch (optionally a the test sketch located at TestSketchFilePath). /// Retrieves a CircuitRec instance that contains the following data: /// * Map of substroke Ids to circuit elements (e.g. symbols, wires, and labels) /// * Endpoints /// * List of Parse error (if any) /// * Text recognition results of recognizing labels /// /// Precondition: args contains a labeled sketch; exceptions will occur (and be caught) /// in CircuitRec if the labels are illogical or missing. This is never called? /// </summary> public override RecognitionResult Recognize(RecognitionArgs args) { // Get sketch to recognize Sketch.Sketch resultSketch; // DEBUG if (ReadFromFile) { resultSketch = ((new ReadXML(TestSketchFilePath)).Sketch); } else { resultSketch = args.Sketch; } // Init CircuitRec CircuitRecResult result = new CircuitRecResult(); Domain domain = new Domain(FilenameConstants.DefaultCircuitRecDomainFilepath); Microsoft.Ink.WordList wordList = TextRecognition.TextRecognition.createLabelWordList(); CircuitRec.CircuitRec crec = new CircuitRec.CircuitRec(domain, wordList); // Run CircuitRec try { crec.Run(resultSketch); } catch (ParseError e) { // TEMP deprecated? result.ParseError = e; } catch (ApplicationException e) { System.Windows.MessageBox.Show("Error (ApplicationException): CircuitRec could not recognize circuit properties: \n" + e.Message); } catch (Exception e) { System.Windows.MessageBox.Show("Error (General Exception): \n" + e.Message); } // Fill in result result.UserTriggered = args.UserTriggered; result.Sketch = resultSketch; result.CircuitRecInstance = crec; return(result); }
/// <summary> /// Recognizes the strokes of the sketch using the Ink. /// </summary> /// <param name="args">An unlabeled Sketch and a UserTriggered flag</param> /// <returns>A Labeled Sketch and </returns> public override RecognitionResult Recognize(RecognitionArgs args) { RecognitionResult result = new RecognitionResult(); result.UserTriggered = args.UserTriggered; // Only recognize when necessary if (!args.UserTriggered) { return(result); } // Run recognition and fill result Sketcher sketcher = new Sketcher(); iTool = sketcher.InkPanel.InkTool; iTool.Clusterer.ImageRecognizer.RecognitionCompleted += new RecognitionCompletedEventHandler(ImageRecognizer_RecognitionCompleted); settingsFilename = sketcher.SettingsFilename; dir = sketcher.BaseDirectory; try { iTool.Clusterer.ImageRecognizer.m_RecognitionComplete = false; // Try to use InkTool bool success = iTool.ClassifySketch(args.Sketch, settingsFilename, dir); StrokeClassifier.StrokeClassifierResult clResult = iTool.Clusterer.Classifier.Classify(); StrokeGrouper.StrokeGrouperResult grResult = iTool.Clusterer.Grouper.Group(clResult.AllClassifications); List <Cluster> initialClusters = new List <Cluster>();//iTool.Clusterer.CreateClusters(grResult); ImageRecognizerWrapper.ImageRecognizerResults imgResult = iTool.Clusterer.GetImageResults(initialClusters); //while (!iTool.Clusterer.InitialClustersDone); //iTool.Clusterer.ImageRecognizer.RecognizeST(iTool.Clusterer. rSketch = iTool.MakeSketch(imgResult.ScoredClusters); result.Sketch = rSketch; } catch (Exception e) { // Catch all other exceptions System.Windows.MessageBox.Show("General Exception from sketch recognizer component: \n" + e.Message); // Return unrecognized sketch result.Sketch = args.Sketch; } return(result); }
/// <summary> /// When the user manually triggers recognition, label everything /// in the sketch as a wire, and label a fixed percentage of a /// random selection of substrokes as erroneous. /// </summary> public override RecognitionResult Recognize(RecognitionArgs args) { RecognitionResult result = new RecognitionResult(); // Only operate on user triggered recognition events if (!args.UserTriggered) { return(result); } if (args.Sketch == null) { return(result); } Sketch.Sketch sketch = args.Sketch; // Label the substrokes foreach (Substroke sub in sketch.Substrokes) { if (randObj.NextDouble() < ErrorRate) { sketch.AddLabel(sub, ErrorLabel, 1.0); } else { sketch.AddLabel(sub, WireLabel, 1.0); } } // Create result result.UserTriggered = args.UserTriggered; result.Sketch = sketch; return(result); }
public override RecognitionResult Recognize(RecognitionArgs args) { TruthTableRecognitionResult result = new TruthTableRecognitionResult(); // Only recognizer on user triggered event if (!args.UserTriggered) { return(result); } // Extract number of columns, if available // TEMP Removed because TruthTable.assign(int) is no longer available //int numCols = -1; //if (args is TruthTableRecognitionArgs) //{ // numCols = ((TruthTableRecognitionArgs)args).NumCols; //} // Run recognition and create result result.Sketch = args.Sketch; TruthTable ttRecognizer = new TruthTable(result.Sketch); //if (numCols == -1) //{ result.DataMatrix = ttRecognizer.assign(); //} //else //{ // result.DataMatrix = ttRecognizer.assign(numCols); //} result.DataPins = ttRecognizer.createPins(result.DataMatrix); result.LabelPins = ttRecognizer.outputLabels(); result.NumCols = ttRecognizer.NumCols; result.NumRows = ttRecognizer.NumRows; result.DividerIndex = ttRecognizer.DivIndex; result.UserTriggered = args.UserTriggered; //result.Sketch = ttRecognizer.LabeledSketch; #region DEBUG /*Console.WriteLine("printing labels " + args.Sketch.LabelStrings.ToString()); * * foreach (Sketch.Shape sh in result.Sketch.Shapes) * { * Console.WriteLine("sketch shape " + sh.XmlAttrs.Type); * if (sh.XmlAttrs.Type.Equals("Divider")) * { * foreach (Sketch.Substroke sub in sh.Substrokes) * { * sub.XmlAttrs.Color = System.Drawing.Color.Red.ToArgb(); * Console.WriteLine("divider has substroke with props: " + sub.XmlAttrs.Id + "\n" + sub.Points[0]); * } * } * } * * foreach (Sketch.Substroke sub in result.Sketch.Substrokes) * { * if (sub.ParentShapes.Count == 0) * { * Console.WriteLine("no parent shapes: " + sub.XmlAttrs.Id + "\n " + sub.Points[0]); * } * else if (sub.ParentShapes[0].XmlAttrs.Type.Equals("Divider")) * { * Console.WriteLine("has a parent as divider: " + sub.XmlAttrs.Id + "\n " + sub.Points[0]); * } * }*/ // // TEMP START Debug code from TruthTables/Debugging.cs // /*int cols = result.NumCols; * Console.WriteLine("cols: " + cols); * int rows = result.NumRows; * Console.WriteLine("rows: " + rows); * * // print out the labels * ttRecognizer.outputLabels(); * * // put the data values into the matrix, * // including the underscore between inputs and outputs * if (rows == -1) * return result; * string[] list = new string[rows]; * int d = result.DividerIndex; * Console.WriteLine("divider index: " + d); * * for (int j = 0; j < rows; j++) * { * for (int k = 0; k < cols; k++) * { * if (k == d) * { * list[j] += "_"; // separate inputs from outputs * } * if (result.DataMatrix[j, k] == -1) * { * list[j] += "X"; * } * else * { * list[j] += result.DataMatrix[j, k]; * } * } * } * * // print out the matrix * for (int u = 0; u < list.Length; u++) * { * Console.WriteLine(list[u]); * } * * // * // TEMP END Debug code from TruthTables/Debugging.cs * // */ #endregion return(result); }