/// <summary> /// Iterate through each row of the form data and /// display the recognition results /// </summary> private void Recognize() { // Check to ensure that the user has at least one recognizer installed Recognizers inkRecognizers = new Recognizers(); if (0 == inkRecognizers.Count) { MessageBox.Show(this, "There are no handwriting recognizers installed. You need to have at least one in order to perform the recognition."); } else { StringBuilder buffer = new StringBuilder(); // Iterate through the rows in the "FieldInfo" table foreach (DataRow row in formData.Tables["FieldInfo"].Rows) { // get the metadata for the field // Note that the DataSet contains a row for each field // in the form. It is assumed that the rows are in the // same order as the fields in the form. The DataSet // has the following columns: // Name: the field's name // Left, Top, Right, Bottom: the coordinates of the field (in pixels) string fieldname = (string)row["Name"]; Point pt1 = new Point((int)row["Left"], (int)row["Top"]); Point pt2 = new Point((int)row["Right"], (int)row["Bottom"]); using (Graphics g = CreateGraphics()) { // Convert to ink space units inkPicture1.Renderer.PixelToInkSpace(g, ref pt1); inkPicture1.Renderer.PixelToInkSpace(g, ref pt2); } // the rectangle for the region Rectangle rc = new Rectangle(pt1.X, pt1.Y, pt2.X - pt1.X, pt2.Y - pt1.Y); // find the strokes that intersect and lie inside of the rectangle Strokes strokes = inkPicture1.Ink.HitTest(rc, 70); // recognize the handwriting if (strokes.Count > 0) { buffer.Append(fieldname + " = " + strokes.ToString() + Environment.NewLine); } } // Display the results if (buffer.Length > 0) { MessageBox.Show(this, buffer.ToString()); } else { MessageBox.Show(this, "There aren't any recognition results."); } } }
// Busca el texto de las clases. Si la opcion es: // - 0=>Nombre de la clase // - 1=>Atributos // - 2=>Metodos public static String FindTextClass(Class c, Strokes strokes_text, int option) { Strokes reco_name = FormManager.ink_overlay.Ink.CreateStrokes(); String name = null; // Se obtienen los puntos necesarios de la clase int s1_X = c.GetS1().GetPoint(0).X; int s2_X = c.GetS2().GetPoint(0).X; int s3_Y = 0; int s4_Y = 0; switch (option) { case 0: s3_Y = c.GetS3().GetPoint(0).Y; s4_Y = c.GetS4().GetPoint(0).Y; break; case 1: s3_Y = c.GetS4().GetPoint(0).Y; s4_Y = c.GetS5().GetPoint(0).Y; break; case 2: s3_Y = c.GetS5().GetPoint(0).Y; s4_Y = c.GetS6().GetPoint(0).Y; break; default: break; } // Se recorren los strokes reconocidos como texto, y los que esten entre s3 y s4 de // la clase, forman el nombre, y es lo que se reconoce for (int i = 0; i < strokes_text.Count; i++) { Stroke s = strokes_text[i]; // Se obtienen los puntos de la esquina superior izquierda del stroke int s_X = s.GetBoundingBox().X; int s_Y = s.GetBoundingBox().Y; // Si el stroke esta entre los lados 1,2,3 y 4 de la clase, pertenece al // nombre de la clase if ((s1_X < s_X) && (s2_X > s_X) && (s3_Y < s_Y) && (s4_Y > s_Y)) { reco_name.Add(s); Facade.strokes_recognized.Add(s); } } name = reco_name.ToString(); return(name); }