示例#1
0
 private void dataGridMenuSetPageNumber(object sender, EventArgs e)
 {
     if (dataGrid.SelectedRows.Count > 0)
     {
         using (var dlg = new frmChooseNumber(Program.Test.Pages.Count))
         {
             dlg.ShowDialog();
             if (dlg.DialogResult == DialogResult.OK)
             {
                 for (int i = 0; i < dataGrid.SelectedRows.Count; i++)
                 {
                     CorrectedPage page = IdToPage((int)dataGrid.SelectedRows[i].Cells[0].Value);
                     if (page.Status.Analyzed && !page.Status.CalibrationError) // In case of non calibrated page or calibrationerror
                     {                                                          // it makes no sense of giving a page number!
                         page.PageNumber = dlg.Value;
                         page.CheckImage.CalculateInitialItemAltsCheckedState(page.PageNumber, criteriumSure, criteriumDoubt);
                         page.Status.BarCodeError          = false;
                         page.Status.PageNumberOrHashError = false;
                         page.AnalyzeTooManyAndDoubts();
                     }
                     PutOnGrid(page, dataGrid.SelectedRows[i].Index);
                 }
                 Draw();
             }
         }
     }
 }
示例#2
0
 public void UpdateItemCheckedState(CorrectedPage page)
 {
     for (int i = 0; i < Items.Count; i++)
     {
         Items[i].Checked = GetCheckedStateFromCorrectedPage(page, i);
     }
 }
示例#3
0
 private void Run(CorrectedPage p)
 {
     p.AnalyzeGraphical(criteriumSure, criteriumDoubt);
     if (!p.Status.AnyError() && p.PageNumber > -1) // Passed all error checks
     {
         p.AnalyzeTooManyAndDoubts();
     }
     Application.DoEvents();
 }
示例#4
0
        private ItemCheckedState[] GetCheckedStateFromCorrectedPage(CorrectedPage page, int item)
        {
            var check = new ItemCheckedState[NumberOfAlternatives];

            for (int i = 0; i < NumberOfAlternatives; i++)
            {
                var grid = ItemAltPointGrid(item, i);
                check[i] = page.CheckImage.ItemAltsCheckedState[grid.X, grid.Y];
            }
            return(check);
        }
示例#5
0
        private CorrectedPage IdToPage(int id)
        {
            CorrectedPage page = null;

            for (int i = 0; i < CorrectedPages.Count; i++)
            {
                if (CorrectedPages[i].ID == id)
                {
                    page = CorrectedPages[i];
                    break;
                }
            }
            return(page);
        }
示例#6
0
        private int PageToRow(CorrectedPage page)
        {
            int row = -1;

            for (int i = 0; i < dataGrid.Rows.Count; i++)
            {
                if ((int)dataGrid[0, i].Value == page.ID)
                {
                    row = i;
                    break;
                }
            }
            return(row);
        }
示例#7
0
        private int PageToIndex(CorrectedPage page)
        {
            int index = -1;

            for (int i = 0; i < CorrectedPages.Count; i++)
            {
                if (CorrectedPages[i].ID == page.ID)
                {
                    index = i;
                    break;
                }
            }
            return(index);
        }
示例#8
0
 // Put new correctedPage on the grid, or change one row
 private void PutOnGrid(CorrectedPage correctedPage, int row = -1)
 {
     if (row == -1)
     {
         dataGrid.Rows.Add();
         dataGrid.Rows[dataGrid.RowCount - 1].Height = 32;
         row = dataGrid.RowCount - 1;
     }
     dataGrid[0, row].Value = correctedPage.ID;
     dataGrid[1, row].Value = correctedPage.ShortFileName();
     dataGrid[2, row].Value = correctedPage.PageNumber >= 0 ? Convert.ToString(correctedPage.PageNumber + 1) : "?";
     dataGrid[3, row].Value = correctedPage.Status.Analyzed ? Settings.Empty : Settings.NotAnalyzed;
     dataGrid[4, row].Value = correctedPage.Status.ContainsDoubts ? Settings.ContainsDoubts : Settings.Empty;
     dataGrid[5, row].Value = correctedPage.Status.ContainsTooManyChecked ? Settings.ContainsTooManyChecked : Settings.Empty;
     dataGrid[6, row].Value = correctedPage.Status.BarCodeError ? Settings.BarCodeError : Settings.Empty;
     dataGrid[7, row].Value = correctedPage.Status.PageNumberOrHashError ? Settings.PageNumberOrHashError : Settings.Empty;
     dataGrid[8, row].Value = correctedPage.Status.CalibrationError ? Settings.CalibrationError : Settings.Empty;
 }
示例#9
0
        /// <summary>
        /// Get the score for identification
        /// </summary>
        public string ScoreString(CorrectedPage page, int item = -1)
        {
            var str = new StringBuilder();

            if (page.Status.Analyzed && page.PageNumber >= 0)
            {
                if (item >= 0 && item < Items.Count) // specific item
                {
                    str.Append(Items[item].ScoreString(Alternatives));
                }
                else // all items
                {
                    for (int i = 0; i < Items.Count; i++)
                    {
                        str.Append(Items[i].ScoreString(Alternatives));
                    }
                }
            }
            return(str.ToString());
        }
示例#10
0
        /// <summary>
        /// Get the score of a total itemset or single item
        /// </summary>
        public Fraction Score(CorrectedPage page, int item = -1)
        {
            Fraction sum = new Fraction();

            if (page.Status.Analyzed && !page.Status.AnyError())
            {
                if (item >= 0 && item < Items.Count) // specific item
                {
                    sum += Items[item].Score(this);
                }
                else // all items
                {
                    for (int i = 0; i < Items.Count; i++)
                    {
                        sum += Items[i].Score(this);
                    }
                }
            }
            return(sum);
        }
示例#11
0
 private int PageToId(CorrectedPage page)
 {
     return(page.ID);
 }
示例#12
0
        private void Calibrate(List <string> fileNames)
        {
            try // Number of files == pages in test (already checked)
            {
                var frmProc = new frmProcessing(this);
                frmProc.Show();

                var correctPageNumbers = new List <int>();
                var colDist            = new ColorDistribution();

                // Better not do this in parallel (colDist is shared); most of the time this is one page only anyway
                for (int i = 0; i < fileNames.Count; i++)
                {
                    using (var cPage = new CorrectedPage(fileNames[i]))
                    {
                        cPage.AnalyzeGraphical(criteriumSure, criteriumDoubt);
                        if (cPage.PageNumber > -1) // Passed all error checks
                        {
                            correctPageNumbers.Add(cPage.PageNumber);
                            colDist.Add(cPage.CheckImage.ColorDistribution.Values);
                        }
                    }
                }

                frmProc.Dispose();

                bool pagesOk = true;
                if (correctPageNumbers.Count == Program.Test.Pages.Count)
                {
                    for (int i = 0; i < correctPageNumbers.Count; i++)
                    {
                        if (!correctPageNumbers.Contains(i))
                        {
                            pagesOk = false;
                            break;
                        }
                    }
                }
                else
                {
                    pagesOk = false;
                }

                if (pagesOk)
                {
                    using (var frm = new frmCalibrationResults(colDist))
                    {
                        frm.ShowDialog();
                    }
                }
                else
                {
                #if DEBUG
                    if (MessageBox.Show("The barcode of the file you selected could not be read correctly or doesn't match the open test.\r\nDo you want to continue the calibration? "
                                        + "Try again with barcode check turned off?",
                                        "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                    {
                        Settings.IgnoreBarCodeErrors = true;
                        Calibrate(fileNames);
                        Settings.IgnoreBarCodeErrors = false;
                    }
                #else
                    MessageBox.Show(Convert.ToString(Program.Test.Pages.Count - CorrectedPages.Count) + " of the selected images could not be used for calibration. " +
                                    "Make sure the images you're trying to use correspond to the current test. Consider scanning images again using higher quality settings.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                #endif
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Calibration failed: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }