示例#1
0
        public void Prerecognize()
        {
            try
               {
               _canvas = new Canvas((Bitmap)_image.Clone(), 8.0d);
               _canvas.RecognizeImage();

               testsparam t = _ge.testsparams.First(tp => tp.idt == _testid);

               t.answersparams.Load();
               IEnumerable<answersparam> answers = t.answersparams.Where(a => a.idt == t.idt);
               foreach (answersparam a in answers)
               {
                   Distances _distances = new Distances();
                   _distances.Add(_canvas.TopLeftMarker, (double)a.toplx, (double)a.toply);
                   _distances.Add(_canvas.TopRightMarker, (double)a.toprx, (double)a.topry);
                   _distances.Add(_canvas.BottomLeftMarker, (double)a.blx, (double)a.bly);
                   _distances.Add(_canvas.BottomRightMarker, (double)a.brx, (double)a.bry);

                   Answer _answer = new Answer(_canvas.CorrectedImage, (int)a.num, (int)a.cellscount, _distances, (int)a.intercellswidth, (int)a.cellswidth, (int)a.cellshight);

                   IEnumerable<cellsparam> cells = a.cellsparams.Where(c => c.ida == a.ida);
                   a.cellsparams.Load();
                   int i = 0;
                   foreach (cellsparam cp in cells)
                   {
                       _answer.Cells[i].ContentDescription = cp.description.Trim();
                       i++;
                   }

                   _canvas.Answers.Add(_answer);
               }
               OnRecItem();
               }
               catch (Exception ex) { throw ex; }
        }
示例#2
0
文件: RForm.cs 项目: ondister/Recog
        void btn_recog_Click(object sender, EventArgs e)
        {
            if (this.pb_formimage.Image != null)
            {

                try
                {

                    this.ag_answers.pb_progress.Value = 0;
                    this.ag_answers.pb_progress.Minimum = 0;
                    this.ag_answers.pb_progress.Step = 1;
                    this.ag_answers.pb_progress.Maximum = this.ag_answers.AnswersCount;
                    this.ag_answers.btn_recog.Text = "Идет распознавание...";
                    Recognizer r = new Recognizer(_ge, (Bitmap)this.pb_formimage.Image, _testid);
                    r.RecItem += new EventHandler(r_RecItem);
                    r.Prerecognize();

                    RecogResult rr = r.FindBestRecognize();

                    r.Recognize(rr.RangeWidth, rr.MinDisp);
                    _canvas = r.Canvas;
                    this.ag_answers.Answers = r.Canvas.Answers;
                    answs = r.Canvas.Answers;
                    r.Canvas.Answers.SelectTrueCell();
                    this.pb_formimage.Image = r.Canvas.CorrectedImage;

                    this.ag_answers.btn_recog.Text = "Распознавание завершено";
                    this.ag_answers.pb_progress.Value = this.ag_answers.pb_progress.Maximum;
                    this.ag_answers.btn_recog.Enabled = false;
                    this.btn_scan.Enabled = false;
                    if (r.Canvas.Answers.CountWithEmpty + r.Canvas.Answers.CountWithMiss > 15)
                    {
                        DialogResult dr = MessageBox.Show("Слишком много ошибок при распознавании.\nПричинами может являтся несоответствие бланка и выбранного теста или некорректные настройки яркости-контрастности сканера.\nБолее подробно читайте в справочной информации к программе.\nЖелаете пересканировать этот бланк?", "Проблемы распознавания", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            RForm rf = new RForm(this._testid, this._humanid, _ge,_fe);
                            rf.WindowState = FormWindowState.Maximized;
                            this.Close();
                            rf.ShowDialog();

                        }

                    }

                    this.lb_status.Text = "Итоги распознавания: вопросов без ответа: " + r.Canvas.Answers.CountWithEmpty.ToString() + ", ошибочных ответов: " + r.Canvas.Answers.CountWithMiss.ToString() + ", несколько ответов в вопросе: " + r.Canvas.Answers.CountWithDoubleCross.ToString();
                    this.lb_status.Visible = true;
                    this.chb_onofdesc.Visible = true;
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); }
            }
            else { MessageBox.Show("Нет изображения"); }
        }
示例#3
0
文件: TestAdd.cs 项目: ondister/Recog
        private void cmd_addtest_Click(object sender, EventArgs e)
        {
            this.lst_answ.Items.Clear();
            _canvas = new Canvas((Bitmap)this.pb_img.Image,8d);
            _canvas.RecognizeImage();
            this.pb_img.Image = _canvas.CorrectedImage;

               //KetelData td = new KetelData();
            pBaseEntities pb = new pBaseEntities();

               // modulData md = new modulData();
               // testsparam tst =  testsparam.Createtestsparam(0, "ОПРОСНИК МОДУЛЬ", 200, true);
               // for (int a = 0; a < tst.answerscount; a++)
               // {
               //     answersparam ap = answersparam.Createanswersparam(0, tst.idt, "Вопрос № " + (a + 1), 2);
               //     ap.num = a + 1;
               //     ap.buttondescription = md.answers[a].text;
               //     ap.intercellswidth = 27;
               //     ap.cellshight = 25;
               //     ap.cellswidth = 25;
               //     ap.toplx = 0;
               //     ap.toply = 0;
               //     ap.toprx = 0;
               //     ap.topry = 0;
               //     ap.blx = 0;
               //     ap.bly = 0;
               //     ap.brx = 0;
               //     ap.bry = 0;

               //     cellsparam cp = cellsparam.Createcellsparam(0, ap.ida);
               //     cp.description = "Да";
               //     cp.buttonsescription = "Да";
               //     cp.mark = md.answers[a].isYes?md.answers[a].mark:0;
               //     cellsparam cp1 = cellsparam.Createcellsparam(0, ap.ida);
               //     cp1.description = "Нет";
               //     cp1.buttonsescription = "Нет";
               //     cp1.mark = md.answers[a].isYes ? 0 : md.answers[a].mark;

               //     ap.cellsparams.Add(cp);
               //     ap.cellsparams.Add(cp1);

               //     tst.answersparams.Add(ap);

               // }

               //pb.testsparams.AddObject(tst);
               // pb.SaveChanges();

            testsparam t = pb.testsparams.First(tp => tp.idt == (int)EnumPTests.NPNA);
            t.answersparams.Load();
            IEnumerable<answersparam> answers = t.answersparams;

            foreach (answersparam ap in answers)
            {
                ListViewItem it = new ListViewItem(ap.num.ToString());
                it.SubItems.Add(ap.ida.ToString());
                it.SubItems.Add(ap.description.ToString());
                it.SubItems.Add(ap.intercellswidth.ToString());
                it.SubItems.Add(ap.cellswidth.ToString());
                it.SubItems.Add(ap.cellshight.ToString());
                it.SubItems.Add(ap.toplx.ToString());
                it.SubItems.Add(ap.toply.ToString());
                this.lst_answ.Items.Add(it);
                //добавляем вопросы на грид
                //создаем коллекцию дистанций для каждого ответа

                Distances _distances = new Distances();
                _distances.Add(_canvas.TopLeftMarker, (double)ap.toplx, (double)ap.toply);
                _distances.Add(_canvas.TopRightMarker, (double)ap.toprx, (double)ap.topry);
                _distances.Add(_canvas.BottomLeftMarker, (double)ap.blx, (double)ap.bly);
                _distances.Add(_canvas.BottomRightMarker, (double)ap.brx, (double)ap.bry);

                //_distances.Add(_canvas.TopLeftMarker, 100, 100);
                //_distances.Add(_canvas.TopRightMarker, 100, 100);
                //_distances.Add(_canvas.BottomLeftMarker, 100, 100);
                //_distances.Add(_canvas.BottomRightMarker, 100, 100);

                //создаем ответы
                Answer _answer = new Answer(_canvas.CorrectedImage, (int)ap.ida, (int)ap.cellscount, _distances, (int)ap.intercellswidth, (int)ap.cellswidth, (int)ap.cellshight);
                _answer.Select();
                _canvas.Answers.Add(_answer);

            }
        }