private void Analyze(List <int> IdList) { if (IdList.Count > 0) { // These values can be obtained by scanning an EMPTY test (see calibration) criteriumSure = (float)(Program.Test.CalibrationMean - (Program.UserSettings.SDsure * Program.Test.CalibrationSD)); criteriumDoubt = (float)(Program.Test.CalibrationMean - (Program.UserSettings.SDdoubt * Program.Test.CalibrationSD)); var frmProc = new frmProcessing(this); frmProc.Show(); if (IdList.Count == 1) { // Easier for debugging not to run in parallel if not needed Run(IdToPage(IdList[0])); } else { Parallel.For(0, IdList.Count, new ParallelOptions { MaxDegreeOfParallelism = Program.UserSettings.numberOfParallelThreads }, i => { Run(IdToPage(IdList[i])); }); } frmProc.Dispose(); FillGrid(); Draw(); } }
private void btnImport_Click(object sender, EventArgs e) { var dlg = new OpenFileDialog(); dlg.Filter = Settings.readableFilter; dlg.InitialDirectory = Program.UserSettings.currentDirectory; dlg.Multiselect = true; if (dlg.ShowDialog() == DialogResult.OK) { var frmProc = new frmProcessing(this); frmProc.Show(); foreach (var file in dlg.FileNames) { Application.DoEvents(); if (!ContainsFile(file)) { ImportImageFile(file); } else { var answ = MessageBox.Show("The file " + file + " is already imported. Do you want to replace it? Press cancel to interrupt all imports.", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (answ == DialogResult.OK) { ImportImageFile(file); } else if (answ == DialogResult.Cancel) { break; } } Program.UserSettings.currentDirectory = Path.GetDirectoryName(file); } frmProc.Dispose(); } FillGrid(); Draw(); }
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); } }