void FPNTest_ProcData(object LockWatingThread) { string strName = FPNFile_Path + "FPN_L" + FPN_L.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bin"; /************************************************************************/ /* FPN_y */ /************************************************************************/ miu_y = new List <double>(); for (int i = 0; i < FPN_L; i++) { FPN_y = new ushort[m_Buffers.Height, m_Buffers.Width]; ysave = new byte[SystemParam.ByteLen4Pic]; for (int j = 0; j < FPN_Ns; j++) { byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, j, FPNFile_Path + "TempData\\Light\\" + (i + 1).ToString() + "bin"); ushort[,] pic = wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { FPN_y[m, n] += pic[m, n]; } } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBarPerformStep(); } double miu = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { FPN_y[m, n] = (ushort)(FPN_y[m, n] / FPN_Ns); miu += FPN_y[m, n]; } } ysave = wfSapGUI.ReTransPicDatas(FPN_y, m_Buffers.Height, m_Buffers.Width); SystemParam.WriteTempFile(ysave, i, strName); miu = miu / m_Buffers.Height / m_Buffers.Width; miu_y.Add(miu); } this.Invoke((EventHandler)(delegate { textBox1.AppendText("FPN明场数据处理完成\r\n"); })); strName = FPNFile_Path + "FPN_D" + FPN_L.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bin"; /************************************************************************/ /* FPN_y */ /************************************************************************/ miu_ydark = new List <double>(); for (int i = 0; i < FPN_L; i++) { FPN_y = new ushort[m_Buffers.Height, m_Buffers.Width]; ysave = new byte[SystemParam.ByteLen4Pic]; for (int j = 0; j < FPN_Ns; j++) { byte[] p = SystemParam.ReadTempFile(SystemParam.ByteLen4Pic, j, FPNFile_Path + "TempData\\Dark\\" + (i + 1).ToString() + "bin"); ushort[,] pic = wfSapGUI.TransPicDatas(p, m_Buffers.Height, m_Buffers.Width, m_Buffers.PixelDepth); for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { FPN_y[m, n] += pic[m, n]; } } if (waitProc.HasBeenCancelled()) { return; } waitProc.SetProcessBarPerformStep(); } double miu = 0; for (int m = 0; m < m_Buffers.Height; m++) { for (int n = 0; n < m_Buffers.Width; n++) { FPN_y[m, n] = (ushort)(FPN_y[m, n] / FPN_Ns); miu += FPN_y[m, n]; } } ysave = wfSapGUI.ReTransPicDatas(FPN_y, m_Buffers.Height, m_Buffers.Width); SystemParam.WriteTempFile(ysave, i, strName); miu = miu / m_Buffers.Height / m_Buffers.Width; miu_ydark.Add(miu); } this.Invoke((EventHandler)(delegate { textBox1.AppendText("FPN暗场数据处理完成\r\n"); })); TextLog.AddTextLog("--------------" + DateTime.Now.ToString() + "----------------", FPNFile_Path + "FPN" + FPN_L.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", false); TextLog.AddTextLog(String.Format("{0,-11}{1,-11}{2,-11}", "曝光时间", "明场均值", "暗场均值"), FPNFile_Path + "FPN" + FPN_L.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", false); uint lsup = SystemParam.eStart + (uint)(Calc1.saturation * FPN_Per / 100) * SystemParam.eStep; for (int i = 0; i < FPN_L; i++) { uint ls = (uint)(lsup / FPN_L * (i + 1)); double t = ((double)(ls)) * SystemParam.Ts; TextLog.AddTextLog(String.Format("{0,-15}{1,-15}{2,-15}", t.ToString("F3"), miu_y[i].ToString("F6"), miu_ydark[i].ToString("F6")), FPNFile_Path + "FPN" + FPN_L.ToString() + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", false); } }
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"); })); }
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"); } })); }