private void toolStripButton4_Click_1(object sender, EventArgs e) { SystemParam.Ts = 6.25 / 1000000; double t; for (int i = 0; i < chart2.Series.Count; i++) { chart2.Series[i].Points.Clear(); } for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, i); } chart2.SaveImage(SystemParam.TempPicPath + "1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.ChartAreas[0].AxisY.Title = "平均暗信号"; Calc1.miu_d = new List <double>(); Random r = new Random(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { Calc1.miu_d.Add(r.Next(1000, 1100)); } chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = Calc1.miu_d.Min <double>(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.miu_d[i]); } chart2.SaveImage(SystemParam.TempPicPath + "2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.ChartAreas[0].AxisY.Title = "暗信号均方差"; chart2.ChartAreas[0].AxisY.Minimum = double.NaN; chart2.Series[0].Points.Clear(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, i); } chart2.SaveImage(SystemParam.TempPicPath + "3.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.ChartAreas[0].AxisY.Title = "信噪比"; chart2.Series[0].Points.Clear(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, i); } chart2.SaveImage(SystemParam.TempPicPath + "4.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); saveFileDialog1.ShowDialog(); TestReport.MakeReport(saveFileDialog1.FileName); }
private void 开始测试_Click(object sender, EventArgs e) { //EnvironmentInfo ei = SerialFunc.SerialCommand2(); MessageBox.Show("请转入明场,点击确定继续"); /************************************************************************/ /* 界面初始化 */ /************************************************************************/ textBox1.AppendText("-------------------------------------------------\r\n"); for (int i = 0; i < chart1.Series.Count; i++) { chart1.Series[i].Points.Clear(); } chart1.ChartAreas[0].AxisY.Title = "明场均值"; chart1.ChartAreas[1].AxisY.Title = "明场方差"; toolStrip1.Enabled = false; /************************************************************************/ /* */ /************************************************************************/ SystemParam.DeviceID = InputBox.ShowInputBox("请设定当前测试器件ID", SystemParam.DeviceID); iniFileOP.Write("System Run", "DeviceID", SystemParam.DeviceID); Calc1.p1 = (int)((Calc1.percent_base - Calc1.percent) * SystemParam.ExposureTest_Ns / 100); Calc1.p2 = (int)((Calc1.percent_base + Calc1.percent) * SystemParam.ExposureTest_Ns / 100); InitListView(); if (m_online) { CMOSInfo cmosInfo = SerialFunc.SerialCommand1(); if (cmosInfo == null) { MessageBox.Show("与采集器通信失败"); toolStrip1.Enabled = true; return; } SystemParam.cmosInfo.Ts = cmosInfo.Ts; SystemParam.Ts = (double)SystemParam.cmosInfo.Ts / 100 / 1000 / 1000;//ms //SystemParam.Pixel4Pic = (int)SystemParam.cmosInfo.ColPixels * SystemParam.cmosInfo.RowPixels; } /************************************************************************/ /* */ /************************************************************************/ //第一步、采集图像 testStep = 1; InitCam(2 + CamEx); if (SystemParam.cmosInfo.bRGB != 0) { wfSapGUI.GetRGBPixelInfo(SystemParam.cmosInfo.RowPixels, SystemParam.cmosInfo.ColPixels, SystemParam.cmosInfo.RGB1, SystemParam.cmosInfo.RGB2, SystemParam.cmosInfo.RGB3, SystemParam.cmosInfo.RGB4); } StatusLabelInfoTrash.Text = ""; m_Xfer.Grab(); waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = SystemParam.ExposureTest_Ns; CMOSTestLib.WaitingProcFunc wpf = new CMOSTestLib.WaitingProcFunc(曝光测试); if (!waitProc.Execute(wpf, "曝光时间测试", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } MessageBox.Show("请转入暗场,点击确定继续"); waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = SystemParam.ExposureTest_Ns; wpf = new CMOSTestLib.WaitingProcFunc(暗场采集); if (!waitProc.Execute(wpf, "曝光递进暗场采集", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } waitProc = new CMOSTestLib.WaitingProc(); if (SystemParam.cmosInfo.bRGB == 0) { wpf = new CMOSTestLib.WaitingProcFunc(计算饱和输出电压_动态范围_平均暗信号_暗信号均方差); if (!waitProc.Execute(wpf, "计算饱和输出电压_动态范围_平均暗信号_暗信号均方差", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } } else { wpf = new CMOSTestLib.WaitingProcFunc(计算饱和输出电压_动态范围_平均暗信号_暗信号均方差); if (!waitProc.Execute(wpf, "灰度:计算饱和输出电压_动态范围_平均暗信号_暗信号均方差", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } wpf = new CMOSTestLib.WaitingProcFunc(RGB_计算饱和输出电压_动态范围_平均暗信号_暗信号均方差); if (!waitProc.Execute(wpf, "RGB:计算饱和输出电压_动态范围_平均暗信号_暗信号均方差", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } } m_Xfer.Freeze(); // // 计算饱和输出电压_动态范围_平均暗信号_暗信号均方差(); //Calc1.Saturated50Index = 118 / 2; //Calc1.OverAllGain_K = 0.01; //第二步、在同一曝光时间下,采集某一光照条件下和无光照条件下的L组数据 testStep = 2; InitCam(SystemParam.Step2_len + CamEx); m_Xfer.Grab(); toolStripLabel3.Text = SystemParam.GetTime(Calc1.Saturated50Index).ToString("F2") + " ms"; SystemParam.CreateTempFile(m_Buffers.Height, m_Buffers.Width, m_Buffers.BytesPerPixel, SystemParam.L, Calc2.LightTempFile); SystemParam.CreateTempFile(m_Buffers.Height, m_Buffers.Width, m_Buffers.BytesPerPixel, SystemParam.L, Calc2.DarkTempFile); MessageBox.Show("曝光测试完成,请转入明场,点击确定进行下一步测试"); waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = SystemParam.L; /*CMOSTestLib.WaitingProcFunc*/ wpf = new CMOSTestLib.WaitingProcFunc(第二步明场采集); if (!waitProc.Execute(wpf, "相同曝光条件下,明场采集", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } MessageBox.Show("请转入暗场,点击确定继续"); waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = SystemParam.L; wpf = new CMOSTestLib.WaitingProcFunc(第二步暗场采集); if (!waitProc.Execute(wpf, "相同曝光条件下,暗场采集", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = SystemParam.L; if (SystemParam.cmosInfo.bRGB == 0) { wpf = new CMOSTestLib.WaitingProcFunc(第二步数据处理); if (!waitProc.Execute(wpf, "相同曝光条件下数据处理", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } } else { wpf = new CMOSTestLib.WaitingProcFunc(RGB_第二步数据处理); if (!waitProc.Execute(wpf, "相同曝光条件下数据处理", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } } if (saveFileDialog1.ShowDialog() != DialogResult.OK) { textBox1.AppendText("自动测试结束,用户未保存报告\r\n"); MessageBox.Show("CMOS测试完成"); toolStrip1.Enabled = true; return; } if (SystemParam.cmosInfo.bRGB == 0) { /************************************************************************/ /* 生成报告用图片 */ /************************************************************************/ double t; for (int i = 0; i < chart2.Series.Count; i++) { chart2.Series[i].Points.Clear(); } chart2.ChartAreas[0].AxisY.Title = "明场均值"; chart2.ChartAreas[0].AxisY.Minimum = double.NaN; for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.miu_y[i]); } chart2.SaveImage(SystemParam.TempPicPath + "1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.ChartAreas[0].AxisY.Title = "平均暗信号"; chart2.ChartAreas[0].AxisY.Minimum = Calc1.miu_d.Min <double>(); chart2.Series[0].Points.Clear(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.miu_d[i]); } chart2.SaveImage(SystemParam.TempPicPath + "2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.ChartAreas[0].AxisY.Title = "暗信号均方差"; List <double> axhjfc = new List <double>(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { axhjfc.Add(Math.Sqrt(Calc1.delta_y_dark[i]) / Calc1.OverAllGain_K); } chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = axhjfc.Min <double>(); for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, axhjfc[i]); } chart2.SaveImage(SystemParam.TempPicPath + "3.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.ChartAreas[0].AxisY.Title = "信噪比"; chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = double.NaN; for (int i = 0; i < SystemParam.ExposureTest_Ns; i++) { t = SystemParam.GetTime(i); if (Calc1.SNR[i] == double.MaxValue) { int p = chart2.Series[0].Points.AddXY(t, 0); chart2.Series[0].Points[p].IsEmpty = true; } else { chart2.Series[0].Points.AddXY(t, Calc1.SNR[i]); } } chart2.SaveImage(SystemParam.TempPicPath + "4.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); TestReport.MakeReport(saveFileDialog1.FileName); } else { /************************************************************************/ /* 生成报告用图片 */ /************************************************************************/ double t; for (int i = 0; i < chart2.Series.Count; i++) { chart2.Series[i].Points.Clear(); } chart2.ChartAreas[0].AxisY.Title = "明场均值"; chart2.ChartAreas[0].AxisY.Minimum = double.NaN; chart2.Series[0].Color = System.Drawing.Color.Red; for (int i = 0; i < Calc1.R_miu_y.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.R_miu_y[i]); } chart2.SaveImage(SystemParam.TempPicPath + "1_R.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.Series[0].Points.Clear(); chart2.Series[0].Color = System.Drawing.Color.Lime; for (int i = 0; i < Calc1.G_miu_y.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.G_miu_y[i]); } chart2.SaveImage(SystemParam.TempPicPath + "1_G.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.Series[0].Points.Clear(); chart2.Series[0].Color = System.Drawing.Color.Blue; for (int i = 0; i < Calc1.B_miu_y.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.B_miu_y[i]); } chart2.SaveImage(SystemParam.TempPicPath + "1_B.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); /************************************************************************/ /* */ /************************************************************************/ chart2.ChartAreas[0].AxisY.Title = "平均暗信号"; chart2.Series[0].Points.Clear(); chart2.Series[0].Color = System.Drawing.Color.Red; chart2.ChartAreas[0].AxisY.Minimum = Calc1.R_miu_d.Min <double>(); for (int i = 0; i < Calc1.R_miu_d.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.R_miu_d[i]); } chart2.SaveImage(SystemParam.TempPicPath + "2_R.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.Series[0].Points.Clear(); chart2.Series[0].Color = System.Drawing.Color.Lime; chart2.ChartAreas[0].AxisY.Minimum = Calc1.G_miu_d.Min <double>(); for (int i = 0; i < Calc1.G_miu_d.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.G_miu_d[i]); } chart2.SaveImage(SystemParam.TempPicPath + "2_G.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.Series[0].Points.Clear(); chart2.Series[0].Color = System.Drawing.Color.Blue; chart2.ChartAreas[0].AxisY.Minimum = Calc1.B_miu_d.Min <double>(); for (int i = 0; i < Calc1.B_miu_d.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, Calc1.B_miu_d[i]); } chart2.SaveImage(SystemParam.TempPicPath + "2_B.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); /************************************************************************/ /* */ /************************************************************************/ chart2.ChartAreas[0].AxisY.Title = "暗信号均方差"; chart2.Series[0].Color = System.Drawing.Color.Red; List <double> axhjfc = new List <double>(); for (int i = 0; i < Calc1.R_delta_y_dark.Count; i++) { axhjfc.Add(Math.Sqrt(Calc1.R_delta_y_dark[i]) / Calc1.R_OverAllGain_K); } chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = axhjfc.Min <double>(); for (int i = 0; i < axhjfc.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, axhjfc[i]); } chart2.SaveImage(SystemParam.TempPicPath + "3_R.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); axhjfc = new List <double>(); for (int i = 0; i < Calc1.G_delta_y_dark.Count; i++) { axhjfc.Add(Math.Sqrt(Calc1.G_delta_y_dark[i]) / Calc1.G_OverAllGain_K); } chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = axhjfc.Min <double>(); chart2.Series[0].Color = System.Drawing.Color.Lime; for (int i = 0; i < axhjfc.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, axhjfc[i]); } chart2.SaveImage(SystemParam.TempPicPath + "3_G.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); axhjfc = new List <double>(); for (int i = 0; i < Calc1.B_delta_y_dark.Count; i++) { axhjfc.Add(Math.Sqrt(Calc1.B_delta_y_dark[i]) / Calc1.B_OverAllGain_K); } chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = axhjfc.Min <double>(); chart2.Series[0].Color = System.Drawing.Color.Blue; for (int i = 0; i < axhjfc.Count; i++) { t = SystemParam.GetTime(i); chart2.Series[0].Points.AddXY(t, axhjfc[i]); } chart2.SaveImage(SystemParam.TempPicPath + "3_B.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); /************************************************************************/ /* */ /************************************************************************/ chart2.ChartAreas[0].AxisY.Title = "信噪比"; chart2.Series[0].Points.Clear(); chart2.Series[0].Color = System.Drawing.Color.Red; chart2.ChartAreas[0].AxisY.Minimum = double.NaN; for (int i = 0; i < Calc1.R_SNR.Count; i++) { t = SystemParam.GetTime(i); if (Calc1.R_SNR[i] == double.MaxValue) { int p = chart2.Series[0].Points.AddXY(t, 0); chart2.Series[0].Points[p].IsEmpty = true; } else { chart2.Series[0].Points.AddXY(t, Calc1.R_SNR[i]); } } chart2.SaveImage(SystemParam.TempPicPath + "4_R.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = double.NaN; chart2.Series[0].Color = System.Drawing.Color.Lime; for (int i = 0; i < Calc1.G_SNR.Count; i++) { t = SystemParam.GetTime(i); if (Calc1.G_SNR[i] == double.MaxValue) { int p = chart2.Series[0].Points.AddXY(t, 0); chart2.Series[0].Points[p].IsEmpty = true; } else { chart2.Series[0].Points.AddXY(t, Calc1.G_SNR[i]); } } chart2.SaveImage(SystemParam.TempPicPath + "4_G.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); chart2.Series[0].Points.Clear(); chart2.ChartAreas[0].AxisY.Minimum = double.NaN; chart2.Series[0].Color = System.Drawing.Color.Blue; for (int i = 0; i < Calc1.B_SNR.Count; i++) { t = SystemParam.GetTime(i); if (Calc1.B_SNR[i] == double.MaxValue) { int p = chart2.Series[0].Points.AddXY(t, 0); chart2.Series[0].Points[p].IsEmpty = true; } else { chart2.Series[0].Points.AddXY(t, Calc1.B_SNR[i]); } } chart2.SaveImage(SystemParam.TempPicPath + "4_B.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); TestReport.RGBMakeReport(saveFileDialog1.FileName); } textBox1.AppendText("自动测试结束,测试报告保存位置为:\r\n"); textBox1.AppendText(saveFileDialog1.FileName); MessageBox.Show("CMOS测试完成"); toolStrip1.Enabled = true; }
void 暗场采集(object LockWatingThread) { double y, d; double t; Calc1.miu_y_dark = new List <double>(); Calc1.delta_y_dark = new List <double>(); this.Invoke((EventHandler)(delegate { chart1.Series[0].Points.Clear(); chart1.Series[1].Points.Clear(); chart1.ChartAreas[0].AxisY.Title = "暗场均值"; chart1.ChartAreas[1].AxisY.Title = "暗场方差"; })); NopCam((ushort)(PicN + 1), SystemParam.eStart); int saveindex = 0; int step = (int)(MaxTime / SystemParam.Ts / PhotoNs); for (uint i = 0; i < PhotoNs; i++) { uint ls = SystemParam.eStart + (uint)(i * step); this.Invoke((EventHandler)(delegate { toolStripLabel3.Text = SystemParam.GetTime((int)i).ToString("F2") + " ms"; })); if (waitProc.HasBeenCancelled()) { return; } SerialFunc.SerialCommand3((ushort)(PicN + 1), ls); if (!WaitCam((ushort)(PicN + 1))) { i--; continue; } for (int j = 1; j < PicN + 1; j++) { saveindex++; m_Buffers.Save(Calc1.TempPicPath_Dark + saveindex.ToString() + ".bmp", "-format bmp", j, 0); Thread.Sleep(SystemParam.PicDelay); } byte[] yByteArray; t = ls * SystemParam.Ts; for (int j = 1; j < PicN + 1; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j); SystemParam.CreateBINFile(yByteArray, SystemParam.TxtCustomDarkDataPath + dtStart.ToString("yyyyMMdd_HHmmss") + "\\" + t.ToString("F3") + "_" + j.ToString() + ".bin"); } // yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, 1); // SystemParam.CreateBINFile(yByteArray, SystemParam.TxtCustomDarkDataPath + dtStart.ToString("yyyyMMdd_HHmmss") + "\\" + t.ToString("F3") + "_1.bin"); // yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, 2); // SystemParam.CreateBINFile(yByteArray, SystemParam.TxtCustomDarkDataPath + dtStart.ToString("yyyyMMdd_HHmmss") + "\\" + t.ToString("F3") + "_2.bin"); ya = wfSapGUI.ReadPicDatas(m_Buffers, PicN); //yb = wfSapGUI.ReadPicDatas(m_Buffers, 2); Calc1.TestExposureTime1(ya, m_Buffers.Height, m_Buffers.Width, SystemParam.cmosInfo.PixelDepth, out y, out d); this.Invoke((EventHandler)(delegate { chart1.Series[0].Points.AddXY(t, y); chart1.Series[1].Points.AddXY(t, d); waitProc.SetProcessBar((int)(i + 1)); })); TextLog.AddTextLog(String.Format(SystemParam.TxtCustomDarkDataFormat, t.ToString("F3"), y.ToString("F6"), d.ToString("F6")), fileName, false); } }