void 手动拍照(object LockWatingThread) { SerialFunc.SerialCommand3(rxNeed, ls); while (true) { WFNetLib.WFGlobal.WaitMS(1); if (waitProc.HasBeenCancelled()) { break; } else { waitProc.SetProcessBar(rxFrame); } if (rxFrame == rxNeed) { break; } } for (int i = 0; i < rxNeed; i++) { byte[] yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, i); SystemParam.CreateBINFile(yByteArray, saveFileFolder + "//" + toolStripTextBox2.Text + "(" + (i + 1).ToString() + ")" + ".bin"); // SystemParam.WriteTempFile(yByteArray, i * FPN_Len + j - 1, FPNFile_Path + "TempData\\Light\\" + (k + 1).ToString() + "bin"); } }
private void Form4_FormClosing(object sender, FormClosingEventArgs e) { m_Xfer.Freeze(); DestroyObjects(); DisposeObjects(); SerialFunc.CloseSerialPort(); }
private void Form5_Load(object sender, EventArgs e) { toolStripTextBox1.Text = iniFileOP.Read("System Run", "MaxTime"); toolStripTextBox2.Text = iniFileOP.Read("System Run", "PhotoNs"); toolStripTextBox3.Text = iniFileOP.Read("System Run", "PicN"); if (!SerialFunc.OpenSerialPort()) { this.Close(); } if (SystemParam.cmosInfo == null) { SystemParam.cmosInfo = SerialFunc.SerialCommand1(); if (SystemParam.cmosInfo == null) { MessageBox.Show("与采集器通信失败"); this.Close(); } SystemParam.Ts = (double)SystemParam.cmosInfo.Ts / 100 / 1000 / 1000;//ms SystemParam.Pixel4Pic = (int)SystemParam.cmosInfo.ColPixels * SystemParam.cmosInfo.RowPixels; } if (!CreateObjects()) { DisposeObjects(); return; } }
private void Form1_Load(object sender, EventArgs e) { return; InitSystemParam(); // TestReport.MakeReport(); //this.Controls.Add(this.m_ImageBox); AcqConfigDlg acConfigDlg = new AcqConfigDlg(null, "", AcqConfigDlg.ServerCategory.ServerAcq); if (acConfigDlg.InitServerCombo()) { m_online = true; } else { m_online = false; } if (m_online) { //SerialFunc.SerialPortName = "COM2"; if (!SerialFunc.OpenSerialPort()) { this.Close(); } } else { toolStripButton3.Enabled = false; toolStripButton6.Enabled = false; toolStripButton8.Enabled = false; toolStripButton7.Enabled = false; m_Buffers = new SapBuffer(1, 600, 480, SapFormat.Mono16, SapBuffer.MemoryType.ScatterGather); //m_View = new SapView(m_Buffers); StatusLabelInfo.Text = "offline... Load images"; float WidthScalor = (float)(splitContainer1.Panel2.Size.Width) / m_Buffers.Width; float HeightScalor = (float)(splitContainer1.Panel2.Size.Height) / m_Buffers.Height; //m_View.SetScalingMode(WidthScalor, HeightScalor); } //m_ImageBox.View = m_View; if (!CreateObjects()) { DisposeObjects(); return; } //m_ImageBox.OnSize(); for (int i = 0; i < listView1.Items.Count; i++) { listView1.Items[i].SubItems.Add(""); listView1.Items[i].SubItems.Add(""); } //EnableSignalStatus(); }
void NopCam(ushort count, uint ls) { while (true) { SerialFunc.SerialCommand3(count, ls); if (WaitCam(count)) { break; } } WFGlobal.WaitMS(200); }
private void 自定义暗场测试_Click(object sender, EventArgs e) { SerialFunc.CloseSerialPort(); DestroyObjects(); DisposeObjects(); Form5 f = new Form5(); f.ShowDialog(); if (!SerialFunc.OpenSerialPort()) { this.Close(); } }
void 手动拍照(object LockWatingThread) { SerialFunc.SerialCommand3(rxNeed, ls); while (true) { WFNetLib.WFGlobal.WaitMS(1); if (waitProc.HasBeenCancelled()) { break; } else { waitProc.SetProcessBar(rxFrame); } if (rxFrame == rxNeed) { break; } } }
private void Form4_Load(object sender, EventArgs e) { StatusLabelInfo.Text = "offline... Load images"; if (!SerialFunc.OpenSerialPort()) { this.Close(); } if (SystemParam.cmosInfo == null) { SystemParam.cmosInfo = SerialFunc.SerialCommand1(); if (SystemParam.cmosInfo == null) { MessageBox.Show("与采集器通信失败"); this.Close(); } SystemParam.Ts = (double)SystemParam.cmosInfo.Ts / 100 / 1000 / 1000;//ms SystemParam.Pixel4Pic = (int)SystemParam.cmosInfo.ColPixels * SystemParam.cmosInfo.RowPixels; } InitCam(1); toolStripTextBox2.Text = (trackBar1.Value * SystemParam.Ts).ToString("F3"); }
void 第二步明场采集(object LockWatingThread) { byte[] yByteArray; rxFrame = 0; uint ls = SystemParam.eStart + (uint)Calc1.Saturated50Index * SystemParam.eStep; Calc2.y50 = new double[m_Buffers.Height, m_Buffers.Width]; int nCount = SystemParam.L / SystemParam.Step2_len; this.Invoke((EventHandler)(delegate { textBox1.AppendText("开始50%曝光明场采集\r\n"); })); //NopCam((ushort)(SystemParam.Step2_len + 1), ls); // waitProc.SetProcessBar(SystemParam.Step2_len); int saveindex = 0; for (int i = 0; i < nCount; i++) { if (waitProc.HasBeenCancelled()) { return; } SerialFunc.SerialCommand3((ushort)(SystemParam.Step2_len + CamEx), ls); if (!WaitCam(SystemParam.Step2_len + CamEx)) { i--; continue; } for (int j = 0; j < SystemParam.Step2_len; j++) { saveindex++; m_Buffers.Save(Calc2.TempPicPath_Light + saveindex.ToString() + ".bmp", "-format bmp", j + CamEx, 0); Thread.Sleep(SystemParam.PicDelay); } for (int j = 0; j < SystemParam.Step2_len; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j + CamEx); SystemParam.WriteTempFile(yByteArray, i * SystemParam.Step2_len + j, Calc2.LightTempFile); } this.Invoke((EventHandler)(delegate { listView1.Items[12].SubItems[1].Text = (((double)(i + 1) * SystemParam.Step2_len) * 100 / SystemParam.L).ToString("F1") + "%"; })); waitProc.SetProcessBar((int)((i + 1) * SystemParam.Step2_len)); } if (nCount * SystemParam.Step2_len < SystemParam.L)//还有一个 { while (true) { int left = SystemParam.L - nCount * SystemParam.Step2_len; rxFrame = 0; SerialFunc.SerialCommand3((ushort)(SystemParam.Step2_len + CamEx), ls); if (!WaitCam(SystemParam.Step2_len + CamEx)) { continue; } for (int j = 0; j < SystemParam.Step2_len; j++) { saveindex++; m_Buffers.Save(Calc2.TempPicPath_Light + saveindex.ToString() + ".bmp", "-format bmp", j + CamEx, 0); Thread.Sleep(SystemParam.PicDelay); } for (int j = 0; j < left; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j + CamEx); SystemParam.WriteTempFile(yByteArray, nCount * SystemParam.Step2_len + j, Calc2.LightTempFile); } break; } } waitProc.SetProcessBar(100); this.Invoke((EventHandler)(delegate { listView1.Items[12].SubItems[1].Text = "完成"; textBox1.AppendText("50%曝光明场采集完成\r\n"); })); }
private void FPN测试_Click(object sender, EventArgs e) { int saveindex = 0; string fileName = FPNFile_Path + "TempPic\\Light\\" + saveindex.ToString() + ".bmp"; FileInfo f = new FileInfo(fileName); if (!Directory.Exists(f.DirectoryName)) { Directory.CreateDirectory(f.DirectoryName); } fileName = FPNFile_Path + "TempData\\Light\\" + "1.tif"; f = new FileInfo(fileName); if (!Directory.Exists(f.DirectoryName)) { Directory.CreateDirectory(f.DirectoryName); } fileName = FPNFile_Path + "TempPic\\Dark\\" + "1.tif"; f = new FileInfo(fileName); if (!Directory.Exists(f.DirectoryName)) { Directory.CreateDirectory(f.DirectoryName); } fileName = FPNFile_Path + "TempData\\Dark\\" + "1.tif"; f = new FileInfo(fileName); if (!Directory.Exists(f.DirectoryName)) { Directory.CreateDirectory(f.DirectoryName); } iniFileOP.iniFilePath = System.Windows.Forms.Application.StartupPath + "\\Config.ini"; FPN_Per = int.Parse(iniFileOP.Read("System Setting", "FPN_Per")); FPN_Ns = int.Parse(iniFileOP.Read("System Setting", "FPN_Ns")); FPN_L = int.Parse(iniFileOP.Read("System Setting", "FPN_L")); FPN_Len = int.Parse(iniFileOP.Read("System Setting", "FPN_Len")); MessageBox.Show("请转入明场,点击确定继续"); textBox1.AppendText("-------------------------------------------------\r\n"); chart1.Series[0].Points.Clear(); chart1.Series[1].Points.Clear(); chart1.Series[2].Points.Clear(); toolStrip1.Enabled = false; Calc1.p1 = (int)((Calc1.percent_base - Calc1.percent) * SystemParam.ExposureTest_Ns / 100); Calc1.p2 = (int)((Calc1.percent_base + Calc1.percent) * SystemParam.ExposureTest_Ns / 100); SystemParam.cmosInfo = SerialFunc.SerialCommand1(); if (SystemParam.cmosInfo == null) { MessageBox.Show("与采集器通信失败"); this.Close(); } //第一步、采集图像 testStep = 1; InitCam(2 + CamEx); 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; } testStep = 3; bLight = true; InitCam(FPN_Len + +CamEx); m_Xfer.Grab(); waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = FPN_L; wpf = new CMOSTestLib.WaitingProcFunc(FPNTest_Light); if (!waitProc.Execute(wpf, "FPN明场采集", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } MessageBox.Show("请转入暗场,点击确定继续"); bLight = false; waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = FPN_L; wpf = new CMOSTestLib.WaitingProcFunc(FPNTest_Light); if (!waitProc.Execute(wpf, "FPN暗场采集", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } waitProc = new CMOSTestLib.WaitingProc(); waitProc.MaxProgress = 2 * FPN_L * FPN_Ns; wpf = new CMOSTestLib.WaitingProcFunc(FPNTest_ProcData); if (!waitProc.Execute(wpf, "FPN数据处理", CMOSTestLib.WaitingType.None, "")) { textBox1.AppendText("用户终止自动测试\r\n"); toolStrip1.Enabled = true; return; } MessageBox.Show("FPN测试完成"); }
void FPNTest_Light(object LockWatingThread) { byte[] yByteArray; uint lsup = SystemParam.eStart + (uint)(Calc1.saturation * FPN_Per / 100) * SystemParam.eStep; for (int k = 0; k < FPN_L; k++) { rxFrame = 0; uint ls = (uint)(lsup / FPN_L * (k + 1)); Calc2.y50 = new double[m_Buffers.Height, m_Buffers.Width]; int nCount = FPN_Ns / FPN_Len; this.Invoke((EventHandler)(delegate { if (bLight) { textBox1.AppendText("开始" + (FPN_Per / FPN_L * (k + 1)).ToString("F2") + "%曝光明场采集\r\n"); } else { textBox1.AppendText("开始" + (FPN_Per / FPN_L * (k + 1)).ToString("F2") + "%曝光暗场采集\r\n"); } toolStripLabel3.Text = (ls * SystemParam.Ts).ToString("F2") + " ms"; })); NopCam((ushort)(FPN_Len + +CamEx), ls); int saveindex = 0; for (int i = 0; i < nCount; i++) { if (waitProc.HasBeenCancelled()) { return; } SerialFunc.SerialCommand3((ushort)(FPN_Len + +CamEx), ls); if (!WaitCam(FPN_Len + CamEx)) { i--; continue; } if (bLight) { for (int j = 1; j < FPN_Len + 1; j++) { saveindex++; m_Buffers.Save(FPNFile_Path + "TempPic\\Light\\" + saveindex.ToString() + ".bmp", "-format bmp", j, 0); Thread.Sleep(SystemParam.PicDelay); } for (int j = 1; j < FPN_Len + 1; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j); SystemParam.WriteTempFile(yByteArray, i * FPN_Len + j - 1, FPNFile_Path + "TempData\\Light\\" + (k + 1).ToString() + "bin"); } } else { for (int j = 1; j < FPN_Len + 1; j++) { saveindex++; m_Buffers.Save(FPNFile_Path + "TempPic\\Dark\\" + saveindex.ToString() + ".bmp", "-format bmp", j, 0); Thread.Sleep(SystemParam.PicDelay); } for (int j = 1; j < FPN_Len + 1; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j); SystemParam.WriteTempFile(yByteArray, i * FPN_Len + j - 1, FPNFile_Path + "TempData\\Dark\\" + (k + 1).ToString() + "bin"); } } } if (nCount * FPN_Len < FPN_L)//还有一个 { while (true) { int left = FPN_L - nCount * FPN_Len; rxFrame = 0; SerialFunc.SerialCommand3((ushort)(FPN_Len + +CamEx), ls); if (!WaitCam(SystemParam.Step2_len + CamEx)) { continue; } if (bLight) { for (int j = 1; j < left + 1; j++) { saveindex++; m_Buffers.Save(FPNFile_Path + "TempPic\\Light\\" + saveindex.ToString() + ".bmp", "-format bmp", j, 0); Thread.Sleep(SystemParam.PicDelay); } for (int j = 1; j < left + 1; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j); SystemParam.WriteTempFile(yByteArray, nCount * FPN_Len + j - 1, FPNFile_Path + "TempData\\Light\\" + (k + 1).ToString() + "bin"); } } else { for (int j = 1; j < left + 1; j++) { saveindex++; m_Buffers.Save(FPNFile_Path + "TempPic\\Dark\\" + saveindex.ToString() + ".bmp", "-format bmp", j, 0); Thread.Sleep(SystemParam.PicDelay); } for (int j = 1; j < left + 1; j++) { yByteArray = wfSapGUI.ReadPicDatas(m_Buffers, j); SystemParam.WriteTempFile(yByteArray, nCount * FPN_Len + j - 1, FPNFile_Path + "TempData\\Dark\\" + (k + 1).ToString() + "bin"); } } break; } } waitProc.SetProcessBar(k + 1); } waitProc.SetProcessBar(FPN_L); this.Invoke((EventHandler)(delegate { if (bLight) { textBox1.AppendText("FPN明场采集完成\r\n"); } else { textBox1.AppendText("FPN暗场采集完成\r\n"); } })); }
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); } }
private void toolStripButton1_Click(object sender, EventArgs e) { /************************************************************************/ /* 传感器参数 */ /************************************************************************/ SystemParam.cmosInfo.PixelArea = int.Parse(tbPixelArea.Text); SystemParam.cmosInfo.Lambda = int.Parse(tbLambda.Text); SystemParam.cmosInfo.RGB1 = RGB1.SelectedIndex; SystemParam.cmosInfo.RGB2 = RGB2.SelectedIndex; SystemParam.cmosInfo.RGB3 = RGB3.SelectedIndex; SystemParam.cmosInfo.RGB4 = RGB4.SelectedIndex; SystemParam.ccfPath = tbPath.Text; iniFileOP.Write("CMOS Param", "PixelArea", SystemParam.cmosInfo.PixelArea.ToString()); iniFileOP.Write("CMOS Param", "Lambda", SystemParam.cmosInfo.Lambda.ToString()); iniFileOP.Write("CMOS Param", "RGB1", SystemParam.cmosInfo.RGB1.ToString()); iniFileOP.Write("CMOS Param", "RGB2", SystemParam.cmosInfo.RGB2.ToString()); iniFileOP.Write("CMOS Param", "RGB3", SystemParam.cmosInfo.RGB3.ToString()); iniFileOP.Write("CMOS Param", "RGB4", SystemParam.cmosInfo.RGB4.ToString()); iniFileOP.Write("CMOS Param", "ccfPath", tbPath.Text); if (bRGB.Checked) { SystemParam.cmosInfo.bRGB = 1; iniFileOP.Write("CMOS Param", "bRGB", "1"); } else { SystemParam.cmosInfo.bRGB = 0; iniFileOP.Write("CMOS Param", "bRGB", "0"); } /************************************************************************/ /* 曝光测试 */ /************************************************************************/ SystemParam.ExposureTest_Ns = (int)numericUpDown1.Value; Calc1.k1 = (int)numericUpDown7.Value; Calc1.k2 = (int)numericUpDown8.Value; SystemParam.ExposurePointThreshold = (double)numericUpDown6.Value; Calc1.percent_base = (double)numericUpDown10.Value; Calc1.percent = (double)numericUpDown9.Value; SystemParam.PicDelay = (int)numericUpDown16.Value; SystemParam.WaitTimeOut = (int)numericUpDown21.Value; iniFileOP.Write("System Setting", "ExposureTest_Ns", SystemParam.ExposureTest_Ns.ToString()); iniFileOP.Write("System Setting", "k1", Calc1.k1.ToString()); iniFileOP.Write("System Setting", "k2", Calc1.k2.ToString()); iniFileOP.Write("System Setting", "percent_base", Calc1.percent_base.ToString()); iniFileOP.Write("System Setting", "percent", Calc1.percent.ToString()); iniFileOP.Write("System Setting", "PicDelay", SystemParam.PicDelay.ToString("")); iniFileOP.Write("System Setting", "WaitTimeOut", SystemParam.WaitTimeOut.ToString("")); /************************************************************************/ /* 50%曝光测试 */ /************************************************************************/ SystemParam.L = (ushort)numericUpDown2.Value; SystemParam.Step2_len = (ushort)numericUpDown3.Value; SystemParam.DarkPointPer = (double)numericUpDown4.Value; SystemParam.LightPointPer = (double)numericUpDown5.Value; iniFileOP.Write("System Setting", "L", SystemParam.L.ToString()); iniFileOP.Write("System Setting", "Step2_len", SystemParam.Step2_len.ToString()); iniFileOP.Write("System Setting", "DarkPointPer", SystemParam.DarkPointPer.ToString("F1")); iniFileOP.Write("System Setting", "LightPointPer", SystemParam.LightPointPer.ToString("F1")); iniFileOP.Write("System Setting", "FPN_Per", ((int)(numericUpDown13.Value)).ToString()); iniFileOP.Write("System Setting", "FPN_NS", ((int)(numericUpDown12.Value)).ToString()); iniFileOP.Write("System Setting", "FPN_L", ((int)(numericUpDown11.Value)).ToString()); iniFileOP.Write("System Setting", "FPN_Len", ((int)(numericUpDown14.Value)).ToString()); /************************************************************************/ /* 辐照度计算 */ /************************************************************************/ SystemParam.eInfo.Rf = (double)numericUpDown24.Value; SystemParam.eInfo.rho = (double)numericUpDown23.Value; SystemParam.eInfo.S = (double)numericUpDown22.Value; iniFileOP.Write("E Calc", "Rf", SystemParam.eInfo.Rf.ToString("F0")); iniFileOP.Write("E Calc", "rho", SystemParam.eInfo.rho.ToString("F0")); iniFileOP.Write("E Calc", "S", SystemParam.eInfo.S.ToString("F0")); SystemParam.eStart = (uint)numericUpDown17.Value; SystemParam.eStep = (uint)numericUpDown18.Value; SystemParam.BaudRate = (int)numericUpDown19.Value; iniFileOP.Write("System Run", "eStart", SystemParam.eStart.ToString()); iniFileOP.Write("System Run", "eStep", SystemParam.eStep.ToString()); iniFileOP.Write("System Run", "BaudRate", SystemParam.BaudRate.ToString()); try { SerialFunc.CloseSerialPort(); SerialFunc.OpenSerialPort(); } catch { } this.Close(); }