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; // } // } //} }
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); }