private void CreateCSVBtn_Click(object sender, EventArgs e) { //部分变量暂时是通过写死的方式; Button btn = sender as Button; try { int Threshold1 = 40; int Threshold2 = 100; int Threshold3 = 50; string FilePath = ""; string Sufix = ""; btn.Enabled = false; eRadErr RadRes = eRadErr.OK; if (this.murasholdbox1.Text == "" || this.murasholdbox2.Text == "") { MessageBox.Show("请设置MuraThreshold参数!"); return; } if (SelectHighPass == null) { MessageBox.Show("请选择高通滤波数据生成方式!"); return; } float mThreshold1 = Convert.ToSingle(this.murasholdbox1.Text); float mThreshold2 = Convert.ToSingle(this.murasholdbox2.Text); List <Task> Taskls = new List <Task>(); FolderBrowserDialog folder = new FolderBrowserDialog(); folder.Description = "选择所有文件存放的目录"; if (folder.ShowDialog() == DialogResult.OK) { FilePath = folder.SelectedPath; } foreach (Pattern patinfo in SelectModelRecipe.PatternArray) { string ImgPath = ""; double t1 = 0, t2 = 0, t3 = 0; float muraNum = 0; switch (patinfo.Color) { case "R": ImgPath = $"{FilePath}\\Red{patinfo.Gary}.bmp"; break; case "B": ImgPath = $"{FilePath}\\blue{patinfo.Gary}.bmp"; break; case "G": ImgPath = $"{FilePath}\\Green{patinfo.Gary}.bmp"; break; default: break; } if (!File.Exists(ImgPath)) { MessageBox.Show(ImgPath); return; } StringBuilder SbImgPath = new StringBuilder(ImgPath); StringBuilder SbCsvPath = new StringBuilder(ImgPath.Replace(".bmp", ".csv").Trim()); Taskls.Add(Task.Factory.StartNew(() => { int Res = ImgProc.ImageProc(SbImgPath, SbCsvPath, patinfo.Size, Threshold1, Threshold2, Threshold3, patinfo.Threshold4, SelectModelRecipe.Width, SelectModelRecipe.Height, patinfo.OffsetH, patinfo.OffsetW, patinfo.Scale, true, true, true, ref t1, ref t2, ref t3, 100, ref muraNum, mThreshold1, mThreshold2); string ResMsg = ImgProc.GetErrorInfo((ImgProErrorCode)Res); if (Res == (int)ImgProErrorCode.ImageError_Success) { ShowLog($"{Path.GetFileName(ImgPath)} Result:{ResMsg}", WriteLogType.Action); } else { ShowLog($"{Path.GetFileName(ImgPath)} Result:{ResMsg}", WriteLogType.Error); } })); } Task.WaitAll(Taskls.ToArray()); switch (SelectHighPass) { case HighPassStyle.Open: Sufix = $"_HighPass_{50}"; RadRes = RaydiumAPI.DoCreateBin(FilePath, "./DMR_CFG.rad", Sufix); break; case HighPassStyle.Close: Sufix = ""; RadRes = RaydiumAPI.DoCreateBin(FilePath, "./DMR_CFG.rad", Sufix); break; case HighPassStyle.ClsAndSaveOpData: Sufix = ""; RadRes = RaydiumAPI.DoCreateBin(FilePath, "./DMR_CFG.rad", Sufix); Sufix = $"_HighPass_{50}"; RaydiumAPI.DoCreateBin(FilePath, "./DMR_CFG.rad", Sufix); break; case HighPassStyle.OpAndSaveClsData: Sufix = $"_HighPass_{50}"; RadRes = RaydiumAPI.DoCreateBin(FilePath, "./DMR_CFG.rad", Sufix); Sufix = ""; RaydiumAPI.DoCreateBin(FilePath, "./DMR_CFG.rad", Sufix); break; default: break; } if (RadRes != eRadErr.OK) { MessageBox.Show($"补偿数据生成失败!ErrorCode:{RadRes}"); return; } MessageBox.Show("Finished!"); } catch (Exception ex) { throw new Exception(ex.Message); } finally { btn.Enabled = true; } }
private void CreatePicBtn_Click(object sender, EventArgs e) { Pattern SelectPicInfo = null; string FilePath = FileDialog("图片|*.bmp|所有文件|*.*"); if (FilePath == "") { return; } string FileName = Path.GetFileName(FilePath); foreach (Pattern patnInfo in SelectModelRecipe.PatternArray) { if (FileName.Contains(patnInfo.Color) && FileName.Contains(patnInfo.Gary.ToString())) { SelectPicInfo = patnInfo; break; } } string ErrorMessage = ""; StringBuilder sbPicPath = new StringBuilder(FilePath); StringBuilder CsvPicPath = new StringBuilder(FilePath.Replace(".bmp", ".csv")); if (this.shold1txtBox.Text == "" || this.shold2txtBox.Text == "" || this.shold3txtBox.Text == "") { MessageBox.Show("输入的数据不能为空!!"); return; } int Threshold1 = Convert.ToInt32(this.shold1txtBox.Text); int Threshold2 = Convert.ToInt32(this.shold2txtBox.Text); int Threshold3 = Convert.ToInt32(this.shold3txtBox.Text); double t1 = 0, t2 = 0, t3 = 0; float muraNum = 0; float mThreshold1 = 0.4F; float mThreshold2 = 0.05F; Task.Run(() => { Button btn = sender as Button; try { btn.Invoke(new Action(() => { btn.Enabled = false; })); int Res = ImgProc.ImageProc(sbPicPath, CsvPicPath, SelectPicInfo.Size, Threshold1, Threshold2, Threshold3, SelectPicInfo.Threshold4, SelectModelRecipe.Width, SelectModelRecipe.Height, SelectPicInfo.OffsetH, SelectPicInfo.OffsetW, SelectPicInfo.Scale, true, true, true, ref t1, ref t2, ref t3, 100, ref muraNum, mThreshold1, mThreshold2); ErrorMessage = ImgProc.GetErrorInfo((ImgProErrorCode)Res); MessageBox.Show(ErrorMessage); if (Res != (int)ImgProErrorCode.ImageError_Success) { ShowLog(ErrorMessage, WriteLogType.Error); } else { ShowLog(ErrorMessage, WriteLogType.Action); } } catch (Exception ex) { throw; } finally { btn.Invoke(new Action(() => { btn.Enabled = true; })); } }); }