Ejemplo n.º 1
0
        private void _tableResults_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (_tableResults.Rows.Count > 0 && _tableResults.SelectedCells.Count == 1)
                {
                    OcrFormField field = _tableResults.SelectedCells[0].Tag as OcrFormField;

                    if (field is TextFormField || field is OmrFormField)
                    {
                        DetailedCharacterResults detailedResultsdialog = new DetailedCharacterResults(field);
                        detailedResultsdialog.ShowDialog(this);
                    }
                }
            }
            catch (Exception exp)
            {
                Messager.ShowError(this, exp);
            }
        }
Ejemplo n.º 2
0
        public static void PrintToCSV(string resultPath, AutoFormsRecognizeFormResult result, string formName)
        {
            string fieldname       = "field,";
            string fieldvalue      = "value,";
            string pagenumber      = "pagenumber,";
            string confidencevalue = "confidence,";
            string boundx          = "x,";
            string boundy          = "y,";
            string boundwidth      = "width,";
            string boundheight     = "height,";
            string tableinfo       = "";

            using (var outputStream = new FileStream(resultPath, FileMode.Create))
            {
                using (var writer = new StreamWriter(outputStream))
                {
                    foreach (var formPage in result.FormPages)
                    {
                        foreach (var pageResultItem in formPage)
                        {
                            var textField  = pageResultItem as TextFormField;
                            var omrField   = pageResultItem as OmrFormField;
                            var tablefield = pageResultItem as TableFormField;

                            // confidence.Add(((TextFormFieldResult)textField.Result).AverageConfidence);
                            if (textField != null)
                            {
                                //  if (((TextFormFieldResult)textField.Result).AverageConfidence < 60)

                                ((TextFormFieldResult)textField.Result).Text = ((TextFormFieldResult)textField.Result).Text?.Replace(",", " ");
                                ((TextFormFieldResult)textField.Result).Text = ((TextFormFieldResult)textField.Result).Text?.Replace(System.Environment.NewLine, " ");
                                //MM
                                //writer.WriteLine($"{textField.Name}, {((TextFormFieldResult)textField.Result).Text?.Trim()}, {((TextFormFieldResult)textField.Result).AverageConfidence}, {textField.Bounds.X}, {textField.Bounds.Y}, {textField.Bounds.Width}, {textField.Bounds.Height}");
                                fieldname       += textField.Name + ",";
                                fieldvalue      += ((TextFormFieldResult)(textField.Result)).Text?.Trim() + ",";
                                pagenumber      += (formPage.PageNumber) + ",";
                                confidencevalue += ((TextFormFieldResult)textField.Result).AverageConfidence + ",";
                                boundx          += textField.Bounds.X + ",";
                                boundy          += textField.Bounds.Y + ",";
                                boundwidth      += textField.Bounds.Width + ",";
                                boundheight     += textField.Bounds.Height + ",";
                            }
                            else if (omrField != null)
                            {
                                if (((OmrFormFieldResult)(omrField.Result)).Text == "0")
                                {
                                    ((OmrFormFieldResult)(omrField.Result)).Text = ((OmrFormFieldResult)(omrField.Result)).Text?.Replace("0", "False");
                                }
                                else

                                {
                                    ((OmrFormFieldResult)(omrField.Result)).Text = ((OmrFormFieldResult)(omrField.Result)).Text?.Replace("1", "True");
                                }

                                //MM
                                //writer.WriteLine($"{omrField.Name},{((OmrFormFieldResult)omrField.Result).Text}, {((OmrFormFieldResult)omrField.Result).AverageConfidence}, {omrField.Bounds.X}, {omrField.Bounds.Y}, {omrField.Bounds.Width}, {omrField.Bounds.Height}");
                                fieldname       += omrField.Name + ",";
                                fieldvalue      += ((OmrFormFieldResult)(omrField.Result)).Text + ",";
                                pagenumber      += (formPage.PageNumber) + ",";
                                confidencevalue += ((OmrFormFieldResult)(omrField.Result)).AverageConfidence + ",";
                                boundx          += omrField.Bounds.X + ",";
                                boundy          += omrField.Bounds.Y + ",";
                                boundwidth      += omrField.Bounds.Width + ",";
                                boundheight     += omrField.Bounds.Height + ",";
                            }

                            else if (tablefield != null)
                            {
                                TableFormFieldResult results = tablefield.Result as TableFormFieldResult;

                                if (results != null)
                                {
                                    for (int i = 0; i < results.Rows.Count; i++)
                                    {
                                        TableFormRow row = results.Rows[i];
                                        // tableinfo += tableinfo + row;

                                        for (int j = 0; j < row.Fields.Count; j++)
                                        {
                                            OcrFormField ocrField = row.Fields[j];
                                            if (ocrField is TextFormField)
                                            {
                                                TextFormFieldResult txtResults = ocrField.Result as TextFormFieldResult;
                                                tableinfo += txtResults.Text;
                                            }
                                            else if (ocrField is OmrFormField)
                                            {
                                                OmrFormFieldResult omrResults = ocrField.Result as OmrFormFieldResult;
                                                tableinfo += omrResults.Text;
                                                //tableinfo += ocrField;
                                            }
                                        }
                                    }
                                }
                                File.WriteAllText(@"C: \Users\Public\Lateetud\string.txt", tableinfo);
                            }
                        }
                    }

                    writer.WriteLine(fieldname);
                    writer.WriteLine(fieldvalue);
                    writer.WriteLine(pagenumber);
                    writer.WriteLine(confidencevalue);
                    writer.WriteLine(boundx);
                    writer.WriteLine(boundy);
                    writer.WriteLine(boundwidth);
                    writer.WriteLine(boundheight);
                }
            }
        }
Ejemplo n.º 3
0
        public DetailedTableResults(TableFormField table)
        {
            _table = table;
            InitializeComponent();
            _tableResults.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
            _tableResults.AutoSizeRowsMode          = DataGridViewAutoSizeRowsMode.AllCells;
            foreach (TableColumn column in _table.Columns)
            {
                int index = _tableResults.Columns.Add(column.OcrField.Name, column.OcrField.Name);
                if (column.Alignment == FieldAlignment.Left)
                {
                    _tableResults.Columns[index].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft;
                }
                else if (column.Alignment == FieldAlignment.Right)
                {
                    _tableResults.Columns[index].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                }
                else if (column.Alignment == FieldAlignment.Center)
                {
                    _tableResults.Columns[index].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                }
            }

            TableFormFieldResult results = table.Result as TableFormFieldResult;

            if (results != null)
            {
                for (int i = 0; i < results.Rows.Count; i++)
                {
                    TableFormRow row = results.Rows[i];
                    _tableResults.Rows.Add();

                    int lineCounter = 1;
                    for (int j = 0; j < row.Fields.Count; j++)
                    {
                        OcrFormField ocrField = row.Fields[j];
                        if (ocrField is TextFormField)
                        {
                            TextFormFieldResult txtResults = ocrField.Result as TextFormFieldResult;
                            _tableResults.Rows[i].Cells[j].Value = txtResults.Text;
                            int counter = 1;

                            if (txtResults.Text != null)
                            {
                                counter += CountCharacterInString(txtResults.Text, '\n');
                            }

                            if (counter > lineCounter)
                            {
                                lineCounter = counter;
                            }

                            _tableResults.Rows[i].Cells[j].Tag = ocrField;
                        }
                        else if (ocrField is OmrFormField)
                        {
                            OmrFormFieldResult omrResults = ocrField.Result as OmrFormFieldResult;
                            _tableResults.Rows[i].Cells[j].Value = omrResults.Text;
                            _tableResults.Rows[i].Cells[j].Tag   = ocrField;
                        }
                    }

                    _tableResults.Rows[i].Height *= lineCounter;
                }
            }
        }