Commit c00b7345 LN

增加测试效果图显示。

1 个父辈 4645d3ac
......@@ -14,7 +14,10 @@ namespace AOI
{
public class AoiProject
{
private AoiProject()
{
}
public AoiProject(Image theImage)
{
this.standardImage = theImage;
......@@ -102,13 +105,15 @@ namespace AOI
/// 加载项目
/// </summary>
/// <param name="filePath"></param>
public string Load(string filePath)
public static AoiProject Load(string filePath, out string msg)
{
msg = "";
try
{
AoiProject aoiProject = new AoiProject();
Dictionary<string, string> projectMap = JsonUtil.DeserializeJsonToObjectFromFile<Dictionary<string, string>>(filePath);
string base64Img = projectMap["base64Img"];
this.standardImage = Base64Util.ToImage(base64Img);
aoiProject.standardImage = Base64Util.ToImage(base64Img);
string methodMapJson = projectMap["methodMap"];
var jsonMap = JsonUtil.DeserializeJsonToObject<Dictionary<string, string>>(methodMapJson);
foreach (var item in jsonMap)
......@@ -123,14 +128,17 @@ namespace AOI
string PathDataStr = obj.Value<string>("PathDataStr");
PathData pathData = JsonUtil.DeserializeJsonToObject<PathData>(PathDataStr);
aoiMethod.RoiPath = new GraphicsPath(pathData.Points, pathData.Types);
methodMap.Add(item.Key, aoiMethod);
return "";
aoiProject.methodMap.Add(item.Key, aoiMethod);
}
}catch(Exception ex)
return aoiProject;
}
catch (Exception ex)
{
return ex.ToString();
msg = ex.ToString();
return null;
}
return "";
}
......
......@@ -69,6 +69,7 @@ namespace AOI
if(resultImage != null)
{
resultBean.result = true;
resultBean.currentRoiImage = resultImage;
}
return resultBean;
}
......@@ -152,10 +153,10 @@ namespace AOI
Mat fixedMat = new Mat();
Cv2.WarpAffine(matToCheck, fixedMat, affine,new OpenCvSharp.Size(standardImage.Width, standardImage.Height));
//var fixedMat = FixImage(affine, matToCheck);
Image markImage = GetRoiImage(ImageUtil.ToImage(fixedMat), RoiPath, true);
//Cv2.ImShow("Fixed", ImageUtil.ToMat(markImage));
//return ImageUtil.ToImage(fixedMat);
return markImage;
//Image markImage = GetRoiImage(ImageUtil.ToImage(fixedMat), RoiPath, true);
// return markImage;
// Cv2.ImShow("Fixed", ImageUtil.ToMat(markImage));
return ImageUtil.ToImage(fixedMat);
}
//bool needCut = false;
////标准图中的Mart区域
......
......@@ -45,6 +45,11 @@ namespace AccAOI
this.imageBox1 = new Acc.ImageBox.AccImageBox();
this.btnExcute = new Asa.Theme.FlatButton();
this.btnDel = new Asa.Theme.FlatButton();
this.btnImageChange = new Asa.Theme.FlatButton();
this.flatButton1 = new Asa.Theme.FlatButton();
this.flatButton2 = new Asa.Theme.FlatButton();
this.testImageBox1 = new Acc.ImageBox.AccImageBox();
this.lblCurrImage = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// aoiList
......@@ -54,9 +59,9 @@ namespace AccAOI
this.aoiList.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.aoiList.Index = -1;
this.aoiList.Inside = false;
this.aoiList.Location = new System.Drawing.Point(9, 223);
this.aoiList.Location = new System.Drawing.Point(9, 153);
this.aoiList.Name = "aoiList";
this.aoiList.Size = new System.Drawing.Size(287, 409);
this.aoiList.Size = new System.Drawing.Size(287, 477);
this.aoiList.TabIndex = 2;
this.aoiList.IndexChanged += new System.EventHandler(this.aoiList_IndexChanged);
//
......@@ -64,7 +69,7 @@ namespace AccAOI
//
this.btnOpenPro.ImageSize = new System.Drawing.Size(0, 0);
this.btnOpenPro.Inside = false;
this.btnOpenPro.Location = new System.Drawing.Point(28, 115);
this.btnOpenPro.Location = new System.Drawing.Point(28, 40);
this.btnOpenPro.Name = "btnOpenPro";
this.btnOpenPro.Size = new System.Drawing.Size(109, 30);
this.btnOpenPro.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
......@@ -76,7 +81,7 @@ namespace AccAOI
//
this.btnSavePro.ImageSize = new System.Drawing.Size(0, 0);
this.btnSavePro.Inside = false;
this.btnSavePro.Location = new System.Drawing.Point(153, 115);
this.btnSavePro.Location = new System.Drawing.Point(153, 40);
this.btnSavePro.Name = "btnSavePro";
this.btnSavePro.Size = new System.Drawing.Size(109, 30);
this.btnSavePro.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
......@@ -88,7 +93,7 @@ namespace AccAOI
//
this.btnNewAoi.ImageSize = new System.Drawing.Size(0, 0);
this.btnNewAoi.Inside = false;
this.btnNewAoi.Location = new System.Drawing.Point(153, 151);
this.btnNewAoi.Location = new System.Drawing.Point(153, 76);
this.btnNewAoi.Name = "btnNewAoi";
this.btnNewAoi.Size = new System.Drawing.Size(109, 30);
this.btnNewAoi.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
......@@ -100,18 +105,18 @@ namespace AccAOI
//
this.btnOpenImage.ImageSize = new System.Drawing.Size(0, 0);
this.btnOpenImage.Inside = false;
this.btnOpenImage.Location = new System.Drawing.Point(28, 79);
this.btnOpenImage.Location = new System.Drawing.Point(1032, 40);
this.btnOpenImage.Name = "btnOpenImage";
this.btnOpenImage.Size = new System.Drawing.Size(109, 30);
this.btnOpenImage.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnOpenImage.TabIndex = 10;
this.btnOpenImage.Text = "打开本地图片";
this.btnOpenImage.Text = "选择基准图片";
this.btnOpenImage.Click += new System.EventHandler(this.btnOpenImage_Click);
//
// flatLabel1
//
this.flatLabel1.Inside = false;
this.flatLabel1.Location = new System.Drawing.Point(23, 43);
this.flatLabel1.Location = new System.Drawing.Point(649, 40);
this.flatLabel1.Name = "flatLabel1";
this.flatLabel1.Size = new System.Drawing.Size(80, 30);
this.flatLabel1.TabIndex = 11;
......@@ -122,7 +127,7 @@ namespace AccAOI
this.cmbCameraList.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.cmbCameraList.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbCameraList.Inside = false;
this.cmbCameraList.Location = new System.Drawing.Point(104, 43);
this.cmbCameraList.Location = new System.Drawing.Point(730, 40);
this.cmbCameraList.Name = "cmbCameraList";
this.cmbCameraList.Size = new System.Drawing.Size(158, 30);
this.cmbCameraList.TabIndex = 12;
......@@ -131,12 +136,12 @@ namespace AccAOI
//
this.btnGetCameraImg.ImageSize = new System.Drawing.Size(0, 0);
this.btnGetCameraImg.Inside = false;
this.btnGetCameraImg.Location = new System.Drawing.Point(153, 79);
this.btnGetCameraImg.Location = new System.Drawing.Point(908, 40);
this.btnGetCameraImg.Name = "btnGetCameraImg";
this.btnGetCameraImg.Size = new System.Drawing.Size(109, 30);
this.btnGetCameraImg.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnGetCameraImg.TabIndex = 13;
this.btnGetCameraImg.Text = "相机获取图片";
this.btnGetCameraImg.Text = "获取基准图片";
this.btnGetCameraImg.Click += new System.EventHandler(this.btnGetCameraImg_Click);
//
// comType
......@@ -144,7 +149,7 @@ namespace AccAOI
this.comType.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.comType.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.comType.Inside = false;
this.comType.Location = new System.Drawing.Point(28, 151);
this.comType.Location = new System.Drawing.Point(28, 76);
this.comType.Name = "comType";
this.comType.Size = new System.Drawing.Size(109, 30);
this.comType.TabIndex = 14;
......@@ -165,11 +170,11 @@ namespace AccAOI
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.imageBox1.DragHandleSize = 9;
this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Location = new System.Drawing.Point(625, 115);
this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionColor = System.Drawing.Color.Blue;
this.imageBox1.SelectionMode = Acc.ImageBox.ImageBoxSelectionMode.Rectangle;
this.imageBox1.Size = new System.Drawing.Size(637, 592);
this.imageBox1.Size = new System.Drawing.Size(637, 517);
this.imageBox1.TabIndex = 4;
this.imageBox1.SelectionRegionChanged += new System.EventHandler(this.imageBox1_SelectionRegionChanged);
//
......@@ -177,7 +182,7 @@ namespace AccAOI
//
this.btnExcute.ImageSize = new System.Drawing.Size(0, 0);
this.btnExcute.Inside = false;
this.btnExcute.Location = new System.Drawing.Point(153, 187);
this.btnExcute.Location = new System.Drawing.Point(153, 112);
this.btnExcute.Name = "btnExcute";
this.btnExcute.Size = new System.Drawing.Size(109, 30);
this.btnExcute.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
......@@ -189,7 +194,7 @@ namespace AccAOI
//
this.btnDel.ImageSize = new System.Drawing.Size(0, 0);
this.btnDel.Inside = false;
this.btnDel.Location = new System.Drawing.Point(28, 187);
this.btnDel.Location = new System.Drawing.Point(28, 112);
this.btnDel.Name = "btnDel";
this.btnDel.Size = new System.Drawing.Size(109, 30);
this.btnDel.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
......@@ -197,10 +202,76 @@ namespace AccAOI
this.btnDel.Text = "删除";
this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
//
// btnImageChange
//
this.btnImageChange.ImageSize = new System.Drawing.Size(0, 0);
this.btnImageChange.Inside = false;
this.btnImageChange.Location = new System.Drawing.Point(779, 76);
this.btnImageChange.Name = "btnImageChange";
this.btnImageChange.Size = new System.Drawing.Size(109, 30);
this.btnImageChange.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnImageChange.TabIndex = 18;
this.btnImageChange.Text = "切换为测试图片";
this.btnImageChange.Click += new System.EventHandler(this.btnImageChange_Click);
//
// flatButton1
//
this.flatButton1.ImageSize = new System.Drawing.Size(0, 0);
this.flatButton1.Inside = false;
this.flatButton1.Location = new System.Drawing.Point(908, 76);
this.flatButton1.Name = "flatButton1";
this.flatButton1.Size = new System.Drawing.Size(109, 30);
this.flatButton1.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.flatButton1.TabIndex = 20;
this.flatButton1.Text = "获取测试图片";
this.flatButton1.Click += new System.EventHandler(this.flatButton1_Click);
//
// flatButton2
//
this.flatButton2.ImageSize = new System.Drawing.Size(0, 0);
this.flatButton2.Inside = false;
this.flatButton2.Location = new System.Drawing.Point(1032, 76);
this.flatButton2.Name = "flatButton2";
this.flatButton2.Size = new System.Drawing.Size(109, 30);
this.flatButton2.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.flatButton2.TabIndex = 19;
this.flatButton2.Text = "选择测试图片";
this.flatButton2.Click += new System.EventHandler(this.flatButton2_Click);
//
// testImageBox1
//
this.testImageBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.testImageBox1.BackColor = System.Drawing.Color.Silver;
this.testImageBox1.DragHandleSize = 9;
this.testImageBox1.Location = new System.Drawing.Point(668, 101);
this.testImageBox1.Name = "testImageBox1";
this.testImageBox1.SelectionColor = System.Drawing.Color.Blue;
this.testImageBox1.Size = new System.Drawing.Size(561, 421);
this.testImageBox1.TabIndex = 21;
this.testImageBox1.Visible = false;
//
// lblCurrImage
//
this.lblCurrImage.AutoSize = true;
this.lblCurrImage.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblCurrImage.ForeColor = System.Drawing.Color.Green;
this.lblCurrImage.Location = new System.Drawing.Point(628, 87);
this.lblCurrImage.Name = "lblCurrImage";
this.lblCurrImage.Size = new System.Drawing.Size(74, 22);
this.lblCurrImage.TabIndex = 22;
this.lblCurrImage.Text = "基准图:";
//
// FrmAoiSetting
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(1271, 641);
this.Controls.Add(this.lblCurrImage);
this.Controls.Add(this.testImageBox1);
this.Controls.Add(this.flatButton1);
this.Controls.Add(this.flatButton2);
this.Controls.Add(this.btnImageChange);
this.Controls.Add(this.btnDel);
this.Controls.Add(this.btnExcute);
this.Controls.Add(this.panAoi);
......@@ -218,7 +289,9 @@ namespace AccAOI
this.Name = "FrmAoiSetting";
this.Text = "AOI";
this.Load += new System.EventHandler(this.FrmAoiSetting_Load);
this.Shown += new System.EventHandler(this.FrmAoiSetting_Shown);
this.ResumeLayout(false);
this.PerformLayout();
}
......@@ -238,5 +311,10 @@ namespace AccAOI
private System.Windows.Forms.Panel panAoi;
private Asa.Theme.FlatButton btnExcute;
private Asa.Theme.FlatButton btnDel;
private Asa.Theme.FlatButton btnImageChange;
private Asa.Theme.FlatButton flatButton1;
private Asa.Theme.FlatButton flatButton2;
private AccImageBox testImageBox1;
private System.Windows.Forms.Label lblCurrImage;
}
}
\ No newline at end of file
......@@ -15,7 +15,8 @@ namespace AccAOI
public partial class FrmAoiSetting : Asa.Theme.FlatForm
{
private control.ABaseControl aoiControl = null;
public static Image Img = null;
public static Image BaseImg = null;
public static Image TestImage = null;
private AoiProject Project = null;
private bool CanSel = true;
private string DefaultPath = "";
......@@ -30,8 +31,10 @@ namespace AccAOI
this.WindowState = FormWindowState.Maximized;
if (!programPath.Equals("") && (image != null))
{
Project = new AoiProject(image);
string result = Project.Load(programPath);
BaseImg = image;
// Project = new AoiProject(image);
string result = "";
Project= AoiProject.Load(programPath,out result);
if (!result.Equals(""))
{
MessageBox.Show("加载项目" + programPath + "失败:\r\n" + result);
......@@ -52,8 +55,8 @@ namespace AccAOI
if (System.IO.File.Exists(defaultImg))
{
//读取图片内容
Img = (Image)Image.FromFile(defaultImg).Clone();
imageBox1.Image = Img;
BaseImg = (Image)Image.FromFile(defaultImg).Clone();
imageBox1.Image = BaseImg;
}
}
......@@ -73,8 +76,16 @@ namespace AccAOI
string fileName = openDialog.FileName;
//读取图片内容
Img = (Image)Image.FromFile(fileName).Clone();
imageBox1.Image = Img;
BaseImg = (Image)Image.FromFile(fileName).Clone();
if (Project != null)
{
Project.standardImage = BaseImg;
}
imageBox1.Image = BaseImg;
if (imageBox1.Visible.Equals(false))
{
btnImageChange_Click(null, null);
}
}
private void btnGetCameraImg_Click(object sender, EventArgs e)
......@@ -103,8 +114,9 @@ namespace AccAOI
return;
}
string fileName = openDialog.FileName;
Project = new AoiProject(Img);
string msg = Project.Load(fileName);
// Project = new AoiProject(BaseImg);
string msg = "";
Project = AoiProject.Load(fileName, out msg);
if (!msg.Equals(""))
{
MessageBox.Show("加载项目" + fileName + "失败:\r\n" + msg);
......@@ -140,14 +152,14 @@ namespace AccAOI
private void btnNewAoi_Click(object sender, EventArgs e)
{
if (Img == null)
if (BaseImg == null)
{
MessageBox.Show("清先打开图片");
MessageBox.Show("清先选择基准图片");
return;
}
if (this.Project == null)
{
Project = new AoiProject(Img);
Project = new AoiProject(BaseImg);
}
if (comType.Text.Equals(""))
{
......@@ -170,7 +182,7 @@ namespace AccAOI
CanSel = false;
imageBox1.SelectNone();
imageBox1.Image = Img;
imageBox1.Image = BaseImg;
CanSel = true;
if (aoiControl == null)
{
......@@ -284,7 +296,7 @@ namespace AccAOI
{
return;
}
if (imageBox1.Image == null || Img == null || aoiControl == null)
if (imageBox1.Image == null || BaseImg == null || aoiControl == null)
{
return;
}
......@@ -301,7 +313,7 @@ namespace AccAOI
{
SaveCurrAoi();
CanSel = false;
if (Img == null)
if (BaseImg == null)
{
return;
}
......@@ -309,19 +321,28 @@ namespace AccAOI
{
return;
}
if (TestImage == null)
{
MessageBox.Show("请选择测试图片");
return;
}
Image outImage = null;
List<ResultBean> result = Project.CheckAll(Img, out outImage);
List<ResultBean> result = Project.CheckAll(TestImage, out outImage);
if (outImage != null)
{
this.imageBox1.SelectNone();
this.imageBox1.Image = outImage;
if (!this.testImageBox1.Visible)
{
btnImageChange_Click(null, null);
}
this.testImageBox1.SelectNone();
this.testImageBox1.Image = outImage;
}
CanSel = true;
}
private void btnDel_Click(object sender, EventArgs e)
{
if (Img == null)
if (BaseImg == null)
{
return;
}
......@@ -343,5 +364,61 @@ namespace AccAOI
}
}
private void btnImageChange_Click(object sender, EventArgs e)
{
if (testImageBox1.Visible)
{
testImageBox1.Visible = false;
imageBox1.Visible = true;
btnImageChange.Text = "显示测试图片";
lblCurrImage.Text = "基准图:";
lblCurrImage.ForeColor = Color.Green;
}
else
{
testImageBox1.Visible = true;
imageBox1.Visible = false;
btnImageChange.Text = "显示基准图片";
lblCurrImage.Text = "测试/效果图:";
lblCurrImage.ForeColor = Color.Orange;
}
}
private void flatButton2_Click(object sender, EventArgs e)
{
System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
openDialog.Title = "打开本地图片";
openDialog.Filter = "All Supported Images (*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png)|*.bmp;*.dib;*.rle;*.gif;*.jpg;*.png|Bitmaps (*.bmp;*.dib;*.rle)|*.bmp;*.dib;*.rle|Graphics Interchange Format (*.gif)|*.gif|Joint Photographic Experts (*.jpg)|*.jpg|Portable Network Graphics (*.png)|*.png|All Files (*.*)|*.*";
openDialog.DefaultExt = "png";
//openDialog.DefaultExt = "png";
System.Windows.Forms.DialogResult result = openDialog.ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string fileName = openDialog.FileName;
//读取图片内容
TestImage = (Image)Image.FromFile(fileName).Clone();
testImageBox1.Image = TestImage;
if (testImageBox1.Visible.Equals(false))
{
btnImageChange_Click(null, null);
}
}
private void FrmAoiSetting_Shown(object sender, EventArgs e)
{
testImageBox1.Size = imageBox1.Size;
testImageBox1.Location = imageBox1.Location;
testImageBox1.Visible = false;
}
private void flatButton1_Click(object sender, EventArgs e)
{
}
}
}
......@@ -27,7 +27,7 @@ namespace AccAOI.control
protected object UpdateLock = "";
public Image GetImg()
{
return FrmAoiSetting.Img;
return FrmAoiSetting.BaseImg;
}
internal bool IsShowOk = false;
/// <summary>
......
......@@ -56,11 +56,11 @@ namespace AccAOI.control
}
if (checkImg == null)
{
checkImg = FrmAoiSetting.Img;
checkImg = FrmAoiSetting.BaseImg;
}
DateTime time = DateTime.Now;
AoiMarkMethod mark = (AoiMarkMethod)AoiInfo;
Image result= mark.FixImage(FrmAoiSetting.Img, checkImg);
Image result= mark.FixImage(FrmAoiSetting.BaseImg, checkImg);
TimeSpan span = DateTime.Now - time;
if (result == null)
{
......
......@@ -55,11 +55,11 @@ namespace AccAOI.control
}
if (checkImg == null)
{
checkImg = FrmAoiSetting.Img;
checkImg = FrmAoiSetting.BaseImg;
}
DateTime time = DateTime.Now;
AoiTemplateMethod Match = (AoiTemplateMethod)AoiInfo;
ResultBean result= Match.Check(FrmAoiSetting.Img, checkImg);
ResultBean result= Match.Check(FrmAoiSetting.BaseImg, checkImg);
TimeSpan span = DateTime.Now - time;
if (result == null)
{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!