using ImageToolKits; using OpenCvSharp; using ProductionControl.Utils; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ProductionControl.UI { public partial class FrmGetPosByPic : Form { private SizeLibProp sizeLibProp; List pickARoi = new List(); Mat Img; string _Path; public FrmGetPosByPic(SizeLibProp prop) { pickARoi.Clear(); sizeLibProp = prop; InitializeComponent(); //lbPoslist.Items.Clear(); } private void FrmGetPosByPic_Load(object sender, EventArgs e) { List roi = new List(); if (File.Exists(sizeLibProp.MapPath)) { Img = new Mat(sizeLibProp.MapPath); //this.imageBox1.RefreshWindow(Img); if (sizeLibProp.GetPointList.Length == (14 * 2)) { for (int i = 0; i < 14; i++) { //string pos = sizeLibProp.GetPointList[5 + 2 * i].ToString() + "," + sizeLibProp.GetPointList[5 + 2 * i +1].ToString(); //lbPoslist.Items.Add(pos); ImageBox.BaseDrawParam point = new ImageBox.Point((float)sizeLibProp.GetPointList[2 * i + 1], (float)sizeLibProp.GetPointList[2 * i]); roi.Add(point); pickARoi.Add(point); } imageBox1.RefreshWindow(Img, roi); imageBox1.Refresh(); } else if (sizeLibProp.GetPointList.Length > 0) MessageBox.Show("点位数据错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string maop_path = FileUtil.selectFile(); if (File.Exists(maop_path)) { _Path = maop_path; sizeLibProp.MapPath = maop_path; Img = new Mat(maop_path); this.imageBox1.RefreshWindow(Img); } else { MessageBox.Show("无图纸图片加载!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } private void tsbtnSetPTPos_Click(object sender, EventArgs e) { if ((imageBox1.DrawParam != null) && ((imageBox1.DrawParam as ImageBox.Point).IsValid())) { bool isSame = false; foreach (var t in pickARoi) { if (((t as ImageBox.Point).Row == (imageBox1.DrawParam as ImageBox.Point).Row) && ((t as ImageBox.Point).Column == (imageBox1.DrawParam as ImageBox.Point).Column)) isSame = true; } if (!isSame) pickARoi.Add(imageBox1.DrawParam); else MessageBox.Show("点位相同!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void tsbtnSetLinePos_Click(object sender, EventArgs e) { if ((imageBox1.DrawParam != null) && ((imageBox1.DrawParam as ImageBox.Point).IsValid())) { bool isSame = false; foreach (var t in pickARoi) { if (((t as ImageBox.Point).Row == (imageBox1.DrawParam as ImageBox.Point).Row) && ((t as ImageBox.Point).Column == (imageBox1.DrawParam as ImageBox.Point).Column)) isSame = true; } if (!isSame) pickARoi.Add(imageBox1.DrawParam); else MessageBox.Show("点位相同!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void tsbtnShowPos_Click(object sender, EventArgs e) { imageBox1.RefreshWindow(Img, pickARoi, ImageBox.ImageModeEnum.Zoom); } private void tsbtnClear_Click(object sender, EventArgs e) { if (MessageBox.Show("是否清空所有点位?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { pickARoi.Clear(); this.imageBox1.RefreshWindow(Img); } } private void tsbtnClose_Click(object sender, EventArgs e) { this.Close(); } private void tsbtnSave_Click(object sender, EventArgs e) { if (pickARoi.Count == 14) { sizeLibProp.GetPointList = new double[14 * 2]; for (int i = 0; i < 14; i++) { sizeLibProp.GetPointList[2 * i] = (pickARoi[i] as ImageBox.Point).Column; sizeLibProp.GetPointList[2 * i + 1] = (pickARoi[i] as ImageBox.Point).Row; } sizeLibProp.MapPath = _Path; this.DialogResult = DialogResult.OK; } else if (pickARoi.Count >0) MessageBox.Show("点位设置错误,点数不对!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error); else { sizeLibProp.GetPointList = new double[14 * 2]; for (int i = 0; i < 14; i++) { sizeLibProp.GetPointList[2 * i] = 0; sizeLibProp.GetPointList[2 * i + 1] = 0; } } } } }