コード例 #1
0
ファイル: InputDocs.cs プロジェクト: Badou03080/earchive
        protected void OnAction1Activated(object sender, EventArgs e)
        {
            TreeIter iter, imageiter;
            CurrentLog = "Запущен новый процесс распознования...\n";
            if(!ImageList.GetIterFirst(out iter))
            {
                CurrentLog += "Список изображений пуст. Остановка.";
                return;
            }
            CurrentLog += String.Format("Всего документов: {0}\n", ImageList.IterNChildren());
            progresswork.Text = "Распознование документов...";
            progresswork.Adjustment.Upper = ImageList.IterNChildren();
            MainClass.WaitRedraw();
            do
            {
                if(ImageList.IterDepth(iter) == 0)
                {
                    CurrentLog += (string) ImageList.GetValue(iter, 1) + Environment.NewLine;
                    Document doc = (Document) ImageList.GetValue(iter, 3);
                    if(doc == null)
                    {
                        CurrentLog += "Тип не определён. Переходим к следующему...\n";
                        continue;
                    }
                    if(doc.Template == null)
                    {
                        CurrentLog += "Шаблон распознования не указан. Переходим к следующему...\n";
                        continue;
                    }
                    int ImagesCount = ImageList.IterNChildren(iter);
                    Pixbuf[] Images = new Pixbuf[ImagesCount];
                    int i = 0;
                    ImageList.IterChildren(out imageiter, iter);
                    do
                    {
                        Images[i] = (Pixbuf) ImageList.GetValue(imageiter, 5);
                        i++;
                    }while(ImageList.IterNext(ref imageiter));
                    CurrentLog += String.Format("Тип: {0}\n", doc.TypeName);
                    CurrentLog += String.Format("Количество страниц: {0}\n", ImagesCount);
                    CurrentLog += String.Format("\nИнициализация движка...\n");
                    RecognizeDoc tess = new RecognizeDoc(doc, Images);
                    tess.DiagnosticMode = checkDiagnostic.Active;
                    //FIXME Для теста
                    tess.parent = this;
                    try
                    {
                        tess.Recognize();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        MainClass.StatusMessage("Ошибка в модуле распознования!");
                        QSMain.ErrorMessage(this,ex);
                        if(tess.log != "")
                            ShowLog(tess.log);
                    }
                    finally
                    {
                        CurrentLog += tess.log;
                    }
                    ImageList.SetValue(iter, 8, GetDocIconByState(doc.State));
                }
                progresswork.Adjustment.Value++;
                MainClass.WaitRedraw();

            }while(ImageList.IterNext(ref iter));
            progresswork.Text = "Выполнено";
            progresswork.Fraction = 0;
            //FIXME Обновить текущий документ в окне.
            UpdateFieldsWidgets(false);
        }
コード例 #2
0
ファイル: InputDocs.cs プロジェクト: QualitySolution/earchive
        protected void OnAction1Activated(object sender, EventArgs e)
        {
            TreeIter iter, imageiter;

            //Создаем новый лог
            if (RecognizeLog == null)
            {
                NLog.Config.LoggingConfiguration config = LogManager.Configuration;
                RecognizeLog = new NLog.Targets.MemoryTarget();
                RecognizeLog.Name = "recognizelog";
                RecognizeLog.Layout = "${level} ${message}";
                config.AddTarget("recognizelog", RecognizeLog);
                NLog.Config.LoggingRule rule = new NLog.Config.LoggingRule("*", LogLevel.Debug, RecognizeLog);
                config.LoggingRules.Add(rule);

                LogManager.Configuration = config;
            }
            else
                RecognizeLog.Logs.Clear();

            logger.Info("Запущен новый процесс распознования...");
            if(!ImageList.GetIterFirst(out iter))
            {
                logger.Warn("Список изображений пуст. Остановка.");
                return;
            }
            logger.Info("Всего документов: {0}", ImageList.IterNChildren());
            progresswork.Text = "Распознование документов...";
            progresswork.Adjustment.Upper = ImageList.IterNChildren();
            MainClass.WaitRedraw();
            do
            {
                if(ImageList.IterDepth(iter) == 0)
                {
                    logger.Info((string) ImageList.GetValue(iter, 1));
                    Document doc = (Document) ImageList.GetValue(iter, 3);
                    if(doc == null)
                    {
                        logger.Warn("Тип не определён. Переходим к следующему...");
                        continue;
                    }
                    if(doc.Template == null)
                    {
                        logger.Warn("Шаблон распознования не указан. Переходим к следующему...");
                        continue;
                    }
                    int ImagesCount = ImageList.IterNChildren(iter);
                    Pixbuf[] Images = new Pixbuf[ImagesCount];
                    int i = 0;
                    ImageList.IterChildren(out imageiter, iter);
                    do
                    {
                        Images[i] = (Pixbuf) ImageList.GetValue(imageiter, 5);
                        i++;
                    }while(ImageList.IterNext(ref imageiter));
                    logger.Info("Тип: {0}", doc.TypeName);
                    logger.Info("Количество страниц: {0}", ImagesCount);
                    logger.Info("Инициализация движка...");
                    RecognizeDoc tess = new RecognizeDoc(doc, Images);
                    tess.DiagnosticMode = checkDiagnostic.Active;
                    //FIXME Для теста
                    tess.parent = this;
                    try
                    {
                        tess.Recognize();
                    }
                    catch (Exception ex)
                    {
                        QSMain.ErrorMessageWithLog (this, "Ошибка в модуле распознования!", logger, ex);
                        ShowLog();
                    }
                    ImageList.SetValue(iter, 8, GetDocIconByState(doc.State));
                }
                progresswork.Adjustment.Value++;
                MainClass.WaitRedraw();

            }while(ImageList.IterNext(ref iter));
            logger.Info("Выполнено");
            progresswork.Text = "Выполнено";
            progresswork.Fraction = 0;
            UpdateFieldsWidgets(true);
        }
コード例 #3
0
ファイル: InputDocs.cs プロジェクト: QualitySolution/earchive
        protected void OnActionRecognizeActivated(object sender, EventArgs e)
        {
            TreeIter iter, imageiter;

            //Создаем новый лог
            if (RecognizeLog == null)
            {
                NLog.Config.LoggingConfiguration config = LogManager.Configuration;
                RecognizeLog        = new NLog.Targets.MemoryTarget();
                RecognizeLog.Name   = "recognizelog";
                RecognizeLog.Layout = "${level} ${message}";
                config.AddTarget("recognizelog", RecognizeLog);
                NLog.Config.LoggingRule rule = new NLog.Config.LoggingRule("*", LogLevel.Debug, RecognizeLog);
                config.LoggingRules.Add(rule);

                LogManager.Configuration = config;
            }
            else
            {
                RecognizeLog.Logs.Clear();
            }

            logger.Info("Запущен новый процесс распознования...");
            if (!ImageList.GetIterFirst(out iter))
            {
                logger.Warn("Список изображений пуст. Остановка.");
                return;
            }
            logger.Info("Всего документов: {0}", ImageList.IterNChildren());
            progresswork.Text             = "Распознование документов...";
            progresswork.Adjustment.Upper = ImageList.IterNChildren();
            MainClass.WaitRedraw();
            do
            {
                if (ImageList.IterDepth(iter) == 0)
                {
                    logger.Info((string)ImageList.GetValue(iter, 1));
                    //Получаем список изображений документа
                    int      ImagesCount = ImageList.IterNChildren(iter);
                    Pixbuf[] Images      = new Pixbuf [ImagesCount];
                    int      i           = 0;
                    ImageList.IterChildren(out imageiter, iter);
                    do
                    {
                        Images [i] = (Pixbuf)ImageList.GetValue(imageiter, 5);
                        i++;
                    } while (ImageList.IterNext(ref imageiter));

                    Document doc = (Document)ImageList.GetValue(iter, 3);

                    //Распознание QR кода с распознаванием типа документа
                    var qrResult = QRCodeRecognizer.TryParse(Images, ref doc);

                    //Если QR кода нет или не распознан попытка распознать другими способами
                    if (!qrResult)
                    {
                        logger.Warn("QR код не распознан или не указан в документе. Пытаемся распознать другими способами...");
                        if (doc == null)
                        {
                            logger.Warn("Тип не определён. Переходим к следующему...");
                            continue;
                        }
                        if (doc.Template == null)
                        {
                            logger.Warn("Шаблон распознования не указан. Переходим к следующему...");
                            continue;
                        }

                        logger.Info("Тип: {0}", doc.Name);
                        logger.Info("Количество страниц: {0}", ImagesCount);
                        logger.Info("Инициализация движка...");
                        RecognizeDoc tess = new RecognizeDoc(doc, Images);
                        tess.DiagnosticMode = checkDiagnostic.Active;
                        //FIXME Для теста
                        tess.parent = this;
                        try {
                            tess.Recognize();
                        } catch (Exception ex) {
                            QSMain.ErrorMessageWithLog(this, "Ошибка в модуле распознования!", logger, ex);
                            ShowLog();
                        }
                    }
                    else
                    {
                        ImageList.SetValue(iter, 7, doc.Name);
                        ImageList.SetValue(iter, 3, doc);
                    }
                    ImageList.SetValue(iter, 8, GetDocIconByState(doc.State));
                }
                progresswork.Adjustment.Value++;
                MainClass.WaitRedraw();
            }while(ImageList.IterNext(ref iter));
            logger.Info("Выполнено");
            progresswork.Text     = "Выполнено";
            progresswork.Fraction = 0;
            CurrentDoc            = (Document)ImageList.GetValue(CurrentDocIter, 3);
            UpdateFieldsWidgets(true);
        }