public frmCalibrationResults(ColorDistribution distribution) { InitializeComponent(); Mean = Math.Round(distribution.Mean(), 4); SD = Math.Round(distribution.StandardDeviation(), 4); pictureBox.Image = Processing.Histogram(distribution.Values, true, 0, 100, pictureBox.Width, pictureBox.Height); textBox.Text = "The current settings are:" + "\r\n\tMean: " + Program.UserSettings.calibrationMean + "\r\n\tStandard deviation: " + Program.UserSettings.calibrationSD + "\r\n\r\nThe results from the calibration are:" + "\r\n\tMean:" + "\r\n\tStandard deviation:"; textBox1.Text = "Do you want to use the results from this calibration from now on?" + "\r\nYou can also manually change the newly obtained values if necessary." + "\r\n" + "\r\n(This values will only be changed in the test if you also save it.)"; txtMean.Text = Convert.ToString(Mean); txtSD.Text = Convert.ToString(SD); btnOnlyTest.Top = this.ClientSize.Height - btnOnlyTest.Height - 5; btnAlways.Top = this.ClientSize.Height - btnAlways.Height - 5; btnCancel.Top = this.ClientSize.Height - btnCancel.Height - 5; btnCancel.Left = this.ClientSize.Width - btnCancel.Width - 5; btnAlways.Left = btnCancel.Left - btnAlways.Width - 3; btnOnlyTest.Left = btnAlways.Left - btnOnlyTest.Width - 3; }
partial void Callback_OnMaxClicked() { ColorDistribution distribution = Value; if (DistributionType == PropertyDistributionType.RandomRange) { ColorPicker.Show(distribution.GetMaxConstant(), (success, value) => { if (!success) { return; } Value = new ColorDistribution(distribution.GetMinConstant(), value); OnChanged?.Invoke(); }); } else if (DistributionType == PropertyDistributionType.RandomCurveRange) { GradientPicker.Show(distribution.GetMaxGradient(), (success, colorGradient) => { if (!success) { return; } Value = new ColorDistribution(distribution.GetMinGradient(), colorGradient); OnChanged?.Invoke(); }); } }
partial void OnMinClicked() { ColorDistribution distribution = Value; if (DistributionType == PropertyDistributionType.Constant || DistributionType == PropertyDistributionType.RandomRange) { ColorPicker.Show(distribution.GetMinConstant(), (success, value) => { if (!success) { return; } if (DistributionType == PropertyDistributionType.Constant) { Value = new ColorDistribution(value); } else { Value = new ColorDistribution(value, distribution.GetMaxConstant()); } OnChanged?.Invoke(); }); } else if (DistributionType == PropertyDistributionType.Curve || DistributionType == PropertyDistributionType.RandomCurveRange) { GradientPicker.Show(distribution.GetMinGradient(), (success, colorGradient) => { if (!success) { return; } if (DistributionType == PropertyDistributionType.Curve) { Value = new ColorDistribution(colorGradient); } else { Value = new ColorDistribution(colorGradient, distribution.GetMaxGradient()); } OnChanged?.Invoke(); }); } }
private static extern void Internal_setValue(IntPtr thisPtr, ColorDistribution value);
private static extern void Internal_setcolorOverLifetime(IntPtr thisPtr, ColorDistribution value);
private static extern void Internal_ColorDistribution3(ColorDistribution managedInstance, ColorGradient minGradient, ColorGradient maxGradient);
private static extern void Internal_ColorDistribution2(ColorDistribution managedInstance, ColorGradient gradient);
private static extern void Internal_ColorDistribution1(ColorDistribution managedInstance, ref Color minColor, ref Color maxColor);
private static extern void Internal_ColorDistribution0(ColorDistribution managedInstance, ref Color color);
private static extern void Internal_ColorDistribution(ColorDistribution managedInstance);
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); } }