private void RunExport() { HTuple WindowID = HWinCtrl.HalconID; HDevExp.RunHalcon(WindowID); this.Invoke((MethodInvoker) delegate { SetFinished(); Run.Enabled = true; }); }
private void RunExport() { HTuple WindowID = hWindowControlWPF1.HalconID; HDevExp.RunHalcon(WindowID); this.Dispatcher.Invoke(new Action(() => { labelStatus.Content = "Finished."; buttonRun.IsEnabled = true; })); }
void RunCheck() { Stopwatch sw = new Stopwatch(); sw.Start(); //计时开始 string strLog = null; //判断用变量 try { int judgeFlag = 1; HDevelopExport HD = new HDevelopExport(); HD.RunHalcon(HWCWPF.HalconWindow); //HD.cs_Quality[] 结果数组 for (int i = 0; i < HD.cs_Quality.Length; i++) { strLog += HD.cs_Quality[i].F.ToString("f2") + ","; //log输出用 resultList[i].Content = HD.cs_Quality[i].F.ToString("f2"); //界面显示 if (HD.cs_Quality[i].F > Convert.ToDouble(spectable.Rows[i][1])) { this.judgeList[i].Content = "OK"; this.judgeList[i].Foreground = new SolidColorBrush(Color.FromRgb(0, 255, 0)); } else { judgeList[i].Content = "NG"; this.judgeList[i].Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0)); HOperatorSet.SetColor(HWCWPF.HalconWindow, "red"); HOperatorSet.SetDraw(HWCWPF.HalconWindow, "margin"); HOperatorSet.SetLineWidth(HWCWPF.HalconWindow, 3); HOperatorSet.DispCircle(HWCWPF.HalconWindow, HD.cs_y[i], HD.cs_x[i], 20); judgeFlag = -1; } } //总的判断 if (judgeFlag == 1) { this.finalLbl.Content = "OK"; this.finalLbl.Foreground = new SolidColorBrush(Colors.Green); using (SoundPlayer player = new SoundPlayer()) { string location = System.Environment.CurrentDirectory + "/OK.wav"; player.SoundLocation = location; player.Play(); } okCount++; okCountLbl.Content = okCount; } else { this.finalLbl.Content = "NG"; this.finalLbl.Foreground = new SolidColorBrush(Colors.Red); using (SoundPlayer player = new SoundPlayer()) { string location = System.Environment.CurrentDirectory + "/NG.wav"; player.SoundLocation = location; player.Play(); } ngCount++; ngCountLbl.Content = ngCount; } } catch (Exception Err) { MessageBox.Show(Err.Message); LogSet(Err.Message); } finally { GC.Collect(); } //计时结束 sw.Stop(); TimeSpan ts = sw.Elapsed; tactLbl.Content = ts.TotalSeconds.ToString("0.000"); insLog(strLog); }
/// <summary> /// 检测函数 /// </summary> private void Detect() { pbImage.Visible = false; hWindowCtrl.Visible = true; if (imgOri != null) { Int32 nDefects = 0; Int32 nMode = 0; // detection method selection String strFullFileName; if (string.IsNullOrEmpty(ParamSetting.ImageSavePath)) { ParamSetting.ImageSavePath = Application.StartupPath; } strFullFileName = ParamSetting.ImageSavePath + "\\" + strFileName; // save temp image imgOri.Save(strFullFileName); switch (nMode) { case 0: // method 0: dynamic thresholding detectInstanceDyn = new HDevelopExport(); detectInstanceDyn.InitHalcon(); if (File.Exists(strFullFileName)) { detectInstanceDyn.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, ParamSetting.MeasureParam.MinArea, ParamSetting.MeasureParam.FilterSize, ParamSetting.MeasureParam.DynamicRange, out nDefects); } break; case 1: // method 1: normal thresholding detectInstanceNorm = new HDevelopExport1(); detectInstanceNorm.InitHalcon(); if (File.Exists(strFullFileName)) { detectInstanceNorm.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, ParamSetting.MeasureParam.MinArea, ParamSetting.MeasureParam.GrayThreshold, out nDefects); } break; } if (nDefects > 0) { lblResult.Text = "NG"; lblResult.BackColor = Color.Red; if (!string.IsNullOrEmpty(ParamSetting.ImageSavePath)) { strSavePathNG = ParamSetting.ImageSavePath + "\\" + DateTime.Now.ToShortDateString().Replace("/", "-") + "\\NG"; CheckAndCreatePath(strSavePathNG); if (pbImage.Image != null) { pbImage.Image.Save(strSavePathNG + "\\" + strFileName); } } } else { lblResult.Text = "OK"; lblResult.BackColor = Color.Green; if (!string.IsNullOrEmpty(ParamSetting.ImageSavePath)) { strSavePathOK = ParamSetting.ImageSavePath + "\\" + DateTime.Now.ToShortDateString().Replace("/", "-") + "\\OK"; CheckAndCreatePath(strSavePathOK); if (pbImage.Image != null) { pbImage.Image.Save(strSavePathOK + "\\" + strFileName); } } } } pbImage.Image = imgOri; }
private void Form1_Load(object sender, EventArgs e) { HDevelopExport hd = new HDevelopExport(); hd.RunHalcon(hWindowControl1.HalconWindow); }
public void threadMethod() { //我们一共有了两个窗体控件的句柄,一个是hWindowControl2的,用于显示静态图像,一个是hWindowControl1的,用于显示视频图像 HD.RunHalcon(hWindowControl1.HalconWindow); }
private void Button1_Click(object sender, EventArgs e) { HDevelop.RunHalcon(hWindowControl1.HalconWindow); }
private void button1_Click(object sender, EventArgs e) { string file = ""; if (comboBox1.Text.ToUpper() == "TOP") { mSizdType = SideType.TOP; file = "车顶.txt"; offsetImgageX = offsetImgageXTop; offsetImgageY = offsetImgageYTop; } else if (comboBox1.Text.ToUpper() == "LEFT") { mSizdType = SideType.LEFT; file = "侧边.txt"; offsetImgageX = offsetImgageXLft; offsetImgageY = offsetImgageYLft; } else { MessageBox.Show("选择面"); return; } int countAdd = 0; //Y方向的间隔 补齐参数 老的是10 if (System.IO.File.Exists(file) == false) { MessageBox.Show("File :" + file + " not exist"); return; } FileStream fs = new FileStream(file, FileMode.Open); StreamReader sr = new StreamReader(fs); obj_MotorP.Clear(); obj_MotorP2P.Clear(); string str; XYZ tempXyz; long count = 0; obj_xyz.Clear(); int[][] buffer; while ((str = sr.ReadLine()) != null) { string[] temp = str.Split(' '); if (temp.Length != 3) { continue; } tempXyz.x = (int)double.Parse(temp[0]) + offsetImgageX; tempXyz.y = double.Parse(temp[1]) - offsetImgageY; tempXyz.z = double.Parse(temp[2]); if (obj_xyz.Count == 0) { obj_xyz.Add(tempXyz); } else { if (tempXyz.x != obj_xyz[obj_xyz.Count - 1].x) { obj_xyz.Add(tempXyz); } } } Bitmap bt = new Bitmap(1080, 3000); for (int w = 0; w < bt.Width; w++) { for (int h = 0; h < bt.Height; h++) { bt.SetPixel(w, h, System.Drawing.Color.FromArgb(0, 0, 0)); } } for (int i = 0; i < obj_xyz.Count; i++) { //bt.SetPixel(obj_xyz[i].x, (int)obj_xyz[i].y, System.Drawing.Color.FromArgb(255, 255, 255)); if (i > 1) { int offset = obj_xyz[i].x - obj_xyz[i - 1].x;//补齐 x 方向的缺点 if (offset > 1 && offset < 10 && obj_xyz[i].y == obj_xyz[i - 1].y) { for (int index = 0; index < offset; index++) { bt.SetPixel(obj_xyz[i].x - index, (int)obj_xyz[i].y, System.Drawing.Color.FromArgb(255, 255, 255)); for (int indexAdd = 0; indexAdd < countAdd; indexAdd++) { bt.SetPixel(obj_xyz[i].x - index, (int)obj_xyz[i].y + indexAdd, System.Drawing.Color.FromArgb(255, 255, 255)); } } } else { bt.SetPixel(obj_xyz[i].x, (int)obj_xyz[i].y, System.Drawing.Color.FromArgb(255, 255, 255)); for (int indexAdd = 0; indexAdd < countAdd; indexAdd++) //补齐Y方向 { bt.SetPixel(obj_xyz[i].x, (int)obj_xyz[i].y + indexAdd, System.Drawing.Color.FromArgb(255, 255, 255)); } } } else { bt.SetPixel(obj_xyz[i].x, (int)obj_xyz[i].y, System.Drawing.Color.FromArgb(255, 255, 255)); for (int index = 0; index < 10; index++)// 补齐y 方向的间隔 { bt.SetPixel(obj_xyz[i].x, (int)obj_xyz[i].y + index, System.Drawing.Color.FromArgb(255, 255, 255)); } } } sr.Close(); fs.Close(); bt.Save("Conv2.bmp", System.Drawing.Imaging.ImageFormat.Bmp); if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = bt; List <Str_Ht> lsHT = new List <Str_Ht>(); HDevelopExport hd = new HDevelopExport(); hd.RunHalcon(ref lsHT, mSizdType); GetNewImage(lsHT); }
private void btnCalc_Click(object sender, EventArgs e) { HDevelopExport hd = new HDevelopExport(); hd.RunHalcon(hWindowControl1.HalconWindow); }
/* 检测按钮事件 */ private void btnDetect_Click(object sender, EventArgs e) { pbImage.Visible = false; hWindowCtrl.Visible = true; if (imgOri != null) { Int32 nDefects = 0; Int32 nMode = 1; String strFullFileName; if (strSavePath == "") { strSavePath = Application.StartupPath; } strFullFileName = strSavePath + strFileName; // save temp image imgOri.Save(strFullFileName); switch (nMode) { case 0: // method 0: dynamic thresholding detectInstanceDyn = new HDevelopExport(); detectInstanceDyn.InitHalcon(); if (File.Exists(strFullFileName)) { detectInstanceDyn.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, myConfig.面积, myConfig.滤波尺寸, myConfig.动态二值化阈值, out nDefects); } break; case 1: // method 1: normal thresholding detectInstanceNorm = new HDevelopExport1(); detectInstanceNorm.InitHalcon(); if (File.Exists(strFullFileName)) { detectInstanceNorm.RunHalcon(hWindowCtrl.HalconWindow, strFullFileName, myConfig.面积, myConfig.灰度值, out nDefects); } break; } if (nDefects > 0) { lblResult.Text = "NG"; lblResult.BackColor = Color.Red; if (strSavePath != null && strSavePath.Length != 0) { strSavePathNG = strSavePath + "\\NG"; CheckAndCreatePath(strSavePathNG); if (pbImage.Image != null) { pbImage.Image.Save(strSavePathNG + "\\" + strFileName); } } } else { lblResult.Text = "OK"; lblResult.BackColor = Color.Green; if (strSavePath != null && strSavePath.Length != 0) { strSavePathOK = strSavePath + "\\OK"; CheckAndCreatePath(strSavePathOK); if (pbImage.Image != null) { pbImage.Image.Save(strSavePathOK + "\\" + strFileName); } } } } pbImage.Image = imgOri; }
private void btnCreateRoi_Click(object sender, EventArgs e) { HDevelopExport HD = new HDevelopExport(); HD.RunHalcon(hWindowControl1.HalconWindow); }