void InitializeDisplay() { if (_Operate != null) { this.Text = "二维码"; _Operate.AddDisplayControl(hWindowControl1); InternalMethod.SetBinding(textBox43, "Text", _Operate, "DateCodeTimeOutValue"); InternalMethod.SetBinding(numericUpDown1, "Value", _Operate, "DateCodeZoomImg"); InternalMethod.SetBinding(checkBox1, "Checked", _Operate, "DateCodeTimeOut"); InternalMethod.SetBinding(checkBox2, "Checked", _Operate, "UseBrighten"); InternalMethod.SetBinding(numericUpDown2, "Value", _Operate, "UseBrightenValue"); switch (_Operate.DateCodeRate) { case 1: radioButton1.Select(); break; case 2: radioButton2.Select(); break; case 3: radioButton3.Select(); break; } if (_Operate.SearchRegion.IsInitialized()) { hWindowControl1.HalconWindow.SetDraw("margin"); hWindowControl1.HalconWindow.SetColor("blue"); hWindowControl1.HalconWindow.DispObj(_Operate.SearchRegion); } } }
private void button3_Click(object sender, EventArgs e) { OpenFileDialog ofDialog = new OpenFileDialog(); ofDialog.InitialDirectory = Application.StartupPath; ofDialog.Filter = "位图文件(*.bmp)|*.bmp|PNG(*.png)|*.png|JPGE(*.jpge,*.jpg)|*.jpeg;*.jpg|所有图片|*.bmp;*.png;*.jpge;*.jpg"; ofDialog.FilterIndex = -1; ofDialog.Multiselect = true; ofDialog.Title = "打开一张图片"; if (ofDialog.ShowDialog() == DialogResult.OK) { string[] exts = { ".bmp", ".jpg", ".jpeg", ".jpe", ".png", ".tif", ".tiff" }; string[] file = ofDialog.FileNames; imgNameList.Clear(); foreach (var fi in file) { if (exts.Where(s => Path.GetExtension(fi).ToLower() == s).Count() != 0) { imgNameList.Add(fi); } } if (imgNameList.Count > 0) { img.ReadImage(imgNameList[0]); InternalMethod.KeepAspectRatio(hWindowControl1, img); hWindowControl1.HalconWindow.DispObj(img); toolStripProgressBar1.Maximum = imgNameList.Count; } } //using (FolderBrowserDialog dialog = new FolderBrowserDialog()) //{ // if (dialog.ShowDialog() == DialogResult.OK) // { // string fileName = dialog.SelectedPath; // try // { // Open(fileName); // } // catch (Exception exception) // { // MessageBox.Show(exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand); // return; // } // } //} }
void Display(int state, HObject obj = null) { if (DisplayControl.Count == 0) { return; } switch (state) { case 0: foreach (var v in DisplayControl) { v.HalconWindow.SetColor("blue"); v.HalconWindow.SetDraw("margin"); v.HalconWindow.DispObj(obj); } break; case 1: foreach (var v in DisplayControl) { v.HalconWindow.SetColor("blue"); v.HalconWindow.SetDraw("margin"); v.HalconWindow.DispObj(SearchRegion); } break; case 2: foreach (var v in DisplayControl) { v.HalconWindow.SetColor("green"); v.HalconWindow.SetDraw("margin"); v.HalconWindow.DispObj(DataCodeContour); } break; case 3: foreach (var v in DisplayControl) { InternalMethod.disp_message(v.HalconWindow, DataCodeString, "image", 20, 20, "green", "false"); } break; case 4: foreach (var v in DisplayControl) { InternalMethod.disp_message(v.HalconWindow, "没有找到", "image", 20, 20, "red", "false"); } break; } }
private void TrainCodeDataPro() { TrainCodeDataState = true; for (int i = 0; i < imgNameList.Count && TrainCodeDataState; i++) { try { img.ReadImage(imgNameList[i]); InternalMethod.KeepAspectRatio(hWindowControl1, img); hWindowControl1.HalconWindow.DispObj(img); this.Invoke(new Action(() => { this.Text = imgNameList[i]; toolStripProgressBar1.PerformStep(); })); } catch { continue; } if (TrainCodeDataState) { bool st = _Operate.FindDataCode(img, true); hWindowControl1.HalconWindow.SetColor("blue"); hWindowControl1.HalconWindow.SetDraw("margin"); hWindowControl1.HalconWindow.DispObj(_Operate.SearchRegion); hWindowControl1.HalconWindow.SetColor("green"); hWindowControl1.HalconWindow.DispObj(_Operate.DataCodeContour); InternalMethod.disp_message(hWindowControl1.HalconWindow, st ? _Operate.DataCodeString : "没有找到", "image", 20, 20, st ? "green" : "red", "false"); Thread.Sleep(500); } else { return; } } if (this.Created && TrainCodeDataState == true) { MessageBox.Show("训练完成"); } TrainCodeDataState = false; }
public void Open(string fileName) { string[] exts = { ".bmp", ".jpg", ".jpeg", ".jpe", ".png", ".tif", ".tiff" }; string[] file = Directory.GetFiles(fileName); foreach (var fi in file) { if (exts.Where(s => Path.GetExtension(fi).ToLower() == s).Count() != 0) { imgNameList.Add(fi); } } if (imgNameList.Count > 0) { img.ReadImage(imgNameList[0]); InternalMethod.KeepAspectRatio(hWindowControl1, img); hWindowControl1.HalconWindow.DispObj(img); } }
public void InitImage(HImage img) { this.img = new HImage(img); InternalMethod.KeepAspectRatio(hWindowControl1, img); hWindowControl1.HalconWindow.DispObj(img); }