Commit 1b971ff5 LN

增加颜色匹配界面

1 个父辈 bdc5a88c
...@@ -14,7 +14,7 @@ namespace AOI ...@@ -14,7 +14,7 @@ namespace AOI
/// ///
/// </summary> /// </summary>
/// <param name="name">名称</param> /// <param name="name">名称</param>
/// <param name="type">类型,1=mark点。2=斑点分析,3=颜色抽取,4=模板匹配</param> /// <param name="type">类型,1=mark点。2=斑点分析,3=颜色抽取,4=模板匹配,5=颜色匹配</param>
public ResultBean(string name,int type,double targetMinV,double targetMaxV) public ResultBean(string name,int type,double targetMinV,double targetMaxV)
{ {
this.MethodName = name; this.MethodName = name;
...@@ -55,7 +55,7 @@ namespace AOI ...@@ -55,7 +55,7 @@ namespace AOI
public double percentValue; public double percentValue;
/// <summary> /// <summary>
/// 类型,1=mark点。2=斑点分析,3=颜色抽取,4=模板匹配 /// 类型,1=mark点。2=斑点分析,3=颜色抽取,4=模板匹配,5=颜色匹配
/// </summary> /// </summary>
public int MethodType = 0; public int MethodType = 0;
......
...@@ -23,7 +23,7 @@ namespace AOI ...@@ -23,7 +23,7 @@ namespace AOI
public override ResultBean Check(Image standardImage, Image imageToCheck) public override ResultBean Check(Image standardImage, Image imageToCheck)
{ {
ResultBean resultBean = new ResultBean(MethodName,4,SamePercent,SamePercent); ResultBean resultBean = new ResultBean(MethodName,5,SamePercent,SamePercent);
bool needCut = true; bool needCut = true;
Image standardRoiImg = GetRoiImage(standardImage, needCut); Image standardRoiImg = GetRoiImage(standardImage, needCut);
......
...@@ -42,6 +42,7 @@ namespace AccAOI ...@@ -42,6 +42,7 @@ namespace AccAOI
ControlType.AOIBlob = AOIResourceCulture.GetValue("斑点分析"); ControlType.AOIBlob = AOIResourceCulture.GetValue("斑点分析");
ControlType.AOIRGB = AOIResourceCulture.GetValue("颜色抽取"); ControlType.AOIRGB = AOIResourceCulture.GetValue("颜色抽取");
ControlType.Match = AOIResourceCulture.GetValue("模板匹配"); ControlType.Match = AOIResourceCulture.GetValue("模板匹配");
ControlType.ColorMatch = AOIResourceCulture.GetValue("颜色匹配");
} }
private static void LoadData() private static void LoadData()
{ {
...@@ -197,7 +198,7 @@ namespace AccAOI ...@@ -197,7 +198,7 @@ namespace AccAOI
{ {
string value = defaultMap[key]; string value = defaultMap[key];
lines.Add("" + key + "=" + value + ""); lines.Add("" + key + "=" + value + "");
Console.WriteLine("" + key + "=" + value + "");
} }
string filepath = Application.StartupPath + "\\logs\\"; string filepath = Application.StartupPath + "\\logs\\";
if (!Directory.Exists(filepath)) if (!Directory.Exists(filepath))
...@@ -205,6 +206,7 @@ namespace AccAOI ...@@ -205,6 +206,7 @@ namespace AccAOI
Directory.CreateDirectory(filepath); Directory.CreateDirectory(filepath);
} }
File.WriteAllLines(filepath + "AOIResourceLog.txt", lines.ToArray()); File.WriteAllLines(filepath + "AOIResourceLog.txt", lines.ToArray());
Console.WriteLine("结束打印缺少的文字配置"); Console.WriteLine("结束打印缺少的文字配置");
} }
private static string spiltStr = "_"; private static string spiltStr = "_";
......
...@@ -74,6 +74,12 @@ ...@@ -74,6 +74,12 @@
<Compile Include="AOIResourceCulture.cs" /> <Compile Include="AOIResourceCulture.cs" />
<Compile Include="camera\CameraManager.cs" /> <Compile Include="camera\CameraManager.cs" />
<Compile Include="ControlUtil.cs" /> <Compile Include="ControlUtil.cs" />
<Compile Include="control\AoiColorMatchControl.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="control\AoiColorMatchControl.Designer.cs">
<DependentUpon>AoiColorMatchControl.cs</DependentUpon>
</Compile>
<Compile Include="control\AioTempMatchControl.cs"> <Compile Include="control\AioTempMatchControl.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
...@@ -125,6 +131,9 @@ ...@@ -125,6 +131,9 @@
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AoiColorMatchControl.resx">
<DependentUpon>AoiColorMatchControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="control\AioTempMatchControl.resx"> <EmbeddedResource Include="control\AioTempMatchControl.resx">
<DependentUpon>AioTempMatchControl.cs</DependentUpon> <DependentUpon>AioTempMatchControl.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
......
using AccAOI.control; using AccAOI.control;
using AOI; using AOI;
using OpenCvSharp.Blob;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -28,6 +29,9 @@ namespace AccAOI ...@@ -28,6 +29,9 @@ namespace AccAOI
else if (method is AoiTemplateMethod) else if (method is AoiTemplateMethod)
{ {
return ControlType.Match; return ControlType.Match;
}else if(method is AoiColorMatchMethod)
{
return ControlType.ColorMatch;
} }
return ""; return "";
} }
...@@ -50,6 +54,9 @@ namespace AccAOI ...@@ -50,6 +54,9 @@ namespace AccAOI
else if (type.Equals(ControlType.Match)) else if (type.Equals(ControlType.Match))
{ {
methodInfo = new AoiTemplateMethod(); methodInfo = new AoiTemplateMethod();
}else if (type.Equals(ControlType.ColorMatch))
{
methodInfo = new AoiColorMatchMethod();
} }
return methodInfo; return methodInfo;
} }
...@@ -72,9 +79,57 @@ namespace AccAOI ...@@ -72,9 +79,57 @@ namespace AccAOI
else if (method is AoiTemplateMethod) else if (method is AoiTemplateMethod)
{ {
aoiControl = new control.AioTempMatchControl(); aoiControl = new control.AioTempMatchControl();
}else if(method is AoiColorMatchMethod)
{
aoiControl = new control.AoiColorMatchControl();
} }
return aoiControl; return aoiControl;
} }
public static string GetResultsStr(List<ResultBean> result)
{
string msg = "";
bool isOk = true;
foreach (ResultBean bean in result)
{
if (bean.MethodType.Equals(2))
{
msg += (bean.result ? "✔ " : "✘ ") + bean.MethodName + "\r\n";
if (bean.checkData != null)
{
List<CvBlob> list = (List<CvBlob>)bean.checkData;
list = (from m in list orderby m.Area descending select m).ToList<CvBlob>();
msg += " " + AOIResourceCulture.GetValue("实际值") + ":" + bean.percentValue + " " + AOIResourceCulture.GetValue("目标范围") + ":[" + bean.targetMinValue + " , " + bean.targetMaxValue + "] \r\n";
string text = " " + AOIResourceCulture.GetValue("编号").PadLeft(5, ' ') + AOIResourceCulture.GetValue("面积↓").PadLeft(8, ' ') + AOIResourceCulture.GetValue("X坐标").PadLeft(10, ' ') +
AOIResourceCulture.GetValue("Y坐标").PadLeft(10, ' ');
int index = 1;
// Console.WriteLine(bean.MethodName + "共有【" + list.Count + "】条CvBlob");
foreach (CvBlob cv in list)
{
text += "\r\n" + " " + index.ToString().PadLeft(5, ' ') + cv.Area.ToString().PadLeft(12, ' ') + Math.Round(cv.Centroid.X, 2).ToString().PadLeft(12, ' ') +
Math.Round(cv.Centroid.Y, 2).ToString().PadLeft(12, ' ');
index++;
}
msg += text + "\r\n";
}
}
else if (bean.MethodType.Equals(1) || bean.MethodType.Equals(4) || bean.MethodType.Equals(5))
{
msg += (bean.result ? "✔ " : "✘ ") + bean.MethodName + " (" + bean.targetMinValue + "/" + bean.percentValue + "%)" + "\r\n";
}
else
{
msg += (bean.result ? "✔ " : "✘ ") + bean.MethodName + "\r\n";
msg += " " + AOIResourceCulture.GetValue("实际值") + ":" + bean.percentValue + " " + AOIResourceCulture.GetValue("目标范围") + ":[" + bean.targetMinValue + " , " + bean.targetMaxValue + "] \r\n";
}
if (!bean.result)
{
isOk = false;
}
}
return "Result: " + (isOk ? "OK" : "NG") + "\r\n" + msg;
}
} }
public class ControlType public class ControlType
{ {
...@@ -94,5 +149,10 @@ namespace AccAOI ...@@ -94,5 +149,10 @@ namespace AccAOI
/// 模板匹配 /// 模板匹配
/// </summary> /// </summary>
public static string Match = AOIResourceCulture.GetValue("模板匹配"); public static string Match = AOIResourceCulture.GetValue("模板匹配");
/// <summary>
/// 模板匹配
/// </summary>
public static string ColorMatch = AOIResourceCulture.GetValue("颜色匹配");
} }
} }
...@@ -94,6 +94,7 @@ namespace AccAOI ...@@ -94,6 +94,7 @@ namespace AccAOI
comType.ItemAdd(ControlType.AOIBlob); comType.ItemAdd(ControlType.AOIBlob);
comType.ItemAdd(ControlType.AOIRGB); comType.ItemAdd(ControlType.AOIRGB);
comType.ItemAdd(ControlType.Match); comType.ItemAdd(ControlType.Match);
comType.ItemAdd(ControlType.ColorMatch);
comType.Text = ControlType.Mark; comType.Text = ControlType.Mark;
} }
...@@ -505,56 +506,12 @@ namespace AccAOI ...@@ -505,56 +506,12 @@ namespace AccAOI
} }
else else
{ {
lblTestResult.Text = GetResultsStr(result); lblTestResult.Text = ControlUtil. GetResultsStr(result);
} }
GC.Collect(); GC.Collect();
CanSel = true; CanSel = true;
} }
public static string GetResultsStr(List<ResultBean> result)
{
string msg = "";
bool isOk = true;
foreach (ResultBean bean in result)
{
if (bean.MethodType.Equals(2))
{
msg += (bean.result ? "✔ " : "✘ ") + bean.MethodName + "\r\n";
if (bean.checkData != null)
{
List<CvBlob> list = (List<CvBlob>)bean.checkData;
list = (from m in list orderby m.Area descending select m).ToList<CvBlob>();
msg += " " + AOIResourceCulture.GetValue("实际值") + ":" + bean.percentValue + " " + AOIResourceCulture.GetValue("目标范围") + ":[" + bean.targetMinValue + " , " + bean.targetMaxValue + "] \r\n";
string text = " " + AOIResourceCulture.GetValue("编号").PadLeft(5, ' ') + AOIResourceCulture.GetValue("面积↓").PadLeft(8, ' ') + AOIResourceCulture.GetValue("X坐标").PadLeft(10, ' ') +
AOIResourceCulture.GetValue("Y坐标").PadLeft(10, ' ');
int index = 1;
// Console.WriteLine(bean.MethodName + "共有【" + list.Count + "】条CvBlob");
foreach (CvBlob cv in list)
{
text += "\r\n" + " " + index.ToString().PadLeft(5, ' ') + cv.Area.ToString().PadLeft(12, ' ') + Math.Round(cv.Centroid.X, 2).ToString().PadLeft(12, ' ') +
Math.Round(cv.Centroid.Y, 2).ToString().PadLeft(12, ' ');
index++;
}
msg += text + "\r\n";
}
}
else if (bean.MethodType.Equals(1) || bean.MethodType.Equals(4))
{
msg += (bean.result ? "✔ " : "✘ ") + bean.MethodName + " ("+bean.targetMinValue+"/" + bean.percentValue + "%)" + "\r\n";
}
else
{
msg += (bean.result ? "✔ " : "✘ ") + bean.MethodName + "\r\n";
msg += " " + AOIResourceCulture.GetValue("实际值")+":"+bean.percentValue+" " + AOIResourceCulture.GetValue("目标范围")+":[" +bean.targetMinValue+" , " + bean.targetMaxValue + "] \r\n";
}
if (!bean.result)
{
isOk = false;
}
}
return "Result: " + (isOk ? "OK" : "NG") + "\r\n" + msg;
}
private void btnDel_Click(object sender, EventArgs e) private void btnDel_Click(object sender, EventArgs e)
{ {
if (BaseImg == null) if (BaseImg == null)
...@@ -799,9 +756,6 @@ namespace AccAOI ...@@ -799,9 +756,6 @@ namespace AccAOI
{ {
//保存原来的 //保存原来的
AoiMethod OldMethod = aoiControl.GetAoiInfo(); AoiMethod OldMethod = aoiControl.GetAoiInfo();
AoiMethod methodInfo = OldMethod.GetClone(); AoiMethod methodInfo = OldMethod.GetClone();
string text = ControlUtil.GetMethodType(methodInfo); string text = ControlUtil.GetMethodType(methodInfo);
string defaultName = Project.methodMap.Values.Count.ToString().PadLeft(2, '0') + "_" + text; string defaultName = Project.methodMap.Values.Count.ToString().PadLeft(2, '0') + "_" + text;
......
...@@ -73,10 +73,21 @@ AioTempMatchControl_btnSetArea_Text=ellipse ...@@ -73,10 +73,21 @@ AioTempMatchControl_btnSetArea_Text=ellipse
AoiBlobControl_lblList_Text=Area of a list: AoiBlobControl_lblList_Text=Area of a list:
AoiBlobControl_btnImgType_Text=original AoiBlobControl_btnImgType_Text=original
AoiBlobControl_btnSetArea_Text=ellipse AoiBlobControl_btnSetArea_Text=ellipse
AoiColorMatchControl_panResult_Text=result judgment
AoiColorMatchControl_btnTest_Text=test result
AoiColorMatchControl_panParam_Text=parameter setting
AoiColorMatchControl_flatLabel3_Text=similarity:
AoiColorMatchControl_panAreaSet_Text=Locale - rectangle
AoiColorMatchControl_btnClearArea_Text=Clear
AoiColorMatchControl_btnImgType_Text=original
AoiColorMatchControl_btnSetArea_Text=ellipse
AoiColorMatchControl_panAreaImage_Text=Regional image
图像校准点=Image calibration point 图像校准点=Image calibration point
斑点分析=Spot analysis 斑点分析=Spot analysis
颜色抽取=Color extraction 颜色抽取=Color extraction
模板匹配=Template matching 模板匹配=Template matching
颜色匹配=color matching
效果图=rendering Image 效果图=rendering Image
区域图 - 原图=Area map - original 区域图 - 原图=Area map - original
面积列表:=Area of a list: 面积列表:=Area of a list:
......
...@@ -73,10 +73,21 @@ AioTempMatchControl_btnSetArea_Text=椭圆 ...@@ -73,10 +73,21 @@ AioTempMatchControl_btnSetArea_Text=椭圆
AoiBlobControl_lblList_Text=面积列表: AoiBlobControl_lblList_Text=面积列表:
AoiBlobControl_btnImgType_Text=原图 AoiBlobControl_btnImgType_Text=原图
AoiBlobControl_btnSetArea_Text=椭圆 AoiBlobControl_btnSetArea_Text=椭圆
AoiColorMatchControl_panResult_Text=结果判断
AoiColorMatchControl_btnTest_Text=测试结果
AoiColorMatchControl_panParam_Text=参数设置
AoiColorMatchControl_flatLabel3_Text=相似度:
AoiColorMatchControl_panAreaSet_Text=区域设置 - 矩形
AoiColorMatchControl_btnClearArea_Text=清除
AoiColorMatchControl_btnImgType_Text=原图
AoiColorMatchControl_btnSetArea_Text=椭圆
AoiColorMatchControl_panAreaImage_Text=区域图像 - 效果图
图像校准点=图像校准点 图像校准点=图像校准点
斑点分析=斑点分析 斑点分析=斑点分析
颜色抽取=颜色抽取 颜色抽取=颜色抽取
模板匹配=模板匹配 模板匹配=模板匹配
颜色匹配=颜色匹配
效果图=效果图 效果图=效果图
区域图 - 原图=区域图 - 原图 区域图 - 原图=区域图 - 原图
面积列表:=面积列表: 面积列表:=面积列表:
...@@ -113,4 +124,4 @@ FrmMethodName_btnCancel_Text=取消 ...@@ -113,4 +124,4 @@ FrmMethodName_btnCancel_Text=取消
英文=英文 英文=英文
请输入正确名称(长度 2~30)=请输入正确名称(长度 2~30) 请输入正确名称(长度 2~30)=请输入正确名称(长度 2~30)
目标范围=目标范围 目标范围=目标范围
实际值= 实际值
\ No newline at end of file \ No newline at end of file
实际值= 实际值
\ No newline at end of file \ No newline at end of file
...@@ -58,34 +58,25 @@ namespace AccAOI.control ...@@ -58,34 +58,25 @@ namespace AccAOI.control
private void btnTest_Click(object sender, EventArgs e) private void btnTest_Click(object sender, EventArgs e)
{ {
if (this.AoiInfo is AoiMarkMethod) if (this.AoiInfo is AoiMarkMethod)
{ {
Image checkImg = FrmAoiSetting.TestImage;
// string fileName = txtImage.Text.ToString();
Image checkImg = FrmAoiSetting.TestImage;
//if (File.Exists(fileName))
//{
// //读取图片内容
// // checkImg = (Image)Image.FromFile(fileName).Clone();
// Image file = (Image)Image.FromFile(fileName);
// checkImg = new Bitmap(file);
// file.Dispose();
//}
if (checkImg == null) if (checkImg == null)
{ {
MyMessage.Show("请选择测试图片"); MyMessage.Show("请选择测试图片");
return; return;
checkImg = FrmAoiSetting.BaseImg;
} }
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
AoiMarkMethod mark = (AoiMarkMethod)AoiInfo; AoiMarkMethod mark = (AoiMarkMethod)AoiInfo;
double sameValue = 0; double sameValue = 0;
Image result= mark.FixImage(FrmAoiSetting.BaseImg, checkImg,out sameValue); Image result = mark.FixImage(FrmAoiSetting.BaseImg, checkImg, out sameValue);
TimeSpan span = DateTime.Now - time; TimeSpan span = DateTime.Now - time;
lblResult.Text = "";
if (result == null) if (result == null)
{ {
this.aoiImage.Image = null; this.aoiImage.Image = null;
lblResult.ForeColor = Color.Red ; lblResult.ForeColor = Color.Red;
lblResult.Text =AOIResourceCulture.GetValue( "Mark区域无效")+" ("+sameValue+"%)"; lblResult.Text = AOIResourceCulture.GetValue("Mark区域无效") + " (" + sameValue + "%)";
} }
else else
{ {
...@@ -94,9 +85,8 @@ namespace AccAOI.control ...@@ -94,9 +85,8 @@ namespace AccAOI.control
lblResult.Text = "OK" + " (" + sameValue + "%)"; lblResult.Text = "OK" + " (" + sameValue + "%)";
this.aoiImage.Image = result; this.aoiImage.Image = result;
} }
lblTime.Text= "times :" + Math.Round(span.TotalSeconds, 1)+ "s"; lblTime.Text = "times :" + Math.Round(span.TotalSeconds, 1) + "s";
} }
} }
public override void UpdateImage() public override void UpdateImage()
......
...@@ -57,31 +57,22 @@ namespace AccAOI.control ...@@ -57,31 +57,22 @@ namespace AccAOI.control
{ {
if (this.AoiInfo is AoiTemplateMethod) if (this.AoiInfo is AoiTemplateMethod)
{ {
//string fileName = txtImage.Text.ToString();
Image checkImg = FrmAoiSetting.TestImage; Image checkImg = FrmAoiSetting.TestImage;
//if (File.Exists(fileName))
//{
// //读取图片内容
// //checkImg = (Image)Image.FromFile(fileName).Clone();
// Image file = (Image)Image.FromFile(fileName);
// checkImg = new Bitmap(file);
// file.Dispose();
//}
if (checkImg == null) if (checkImg == null)
{ {
MyMessage.Show("请选择测试图片"); MyMessage.Show("请选择测试图片");
return; return;
checkImg = FrmAoiSetting.BaseImg;
} }
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
AoiTemplateMethod Match = (AoiTemplateMethod)AoiInfo; AoiTemplateMethod Match = (AoiTemplateMethod)AoiInfo;
ResultBean result= Match.Check(FrmAoiSetting.BaseImg, checkImg); ResultBean result = Match.Check(FrmAoiSetting.BaseImg, checkImg);
TimeSpan span = DateTime.Now - time; TimeSpan span = DateTime.Now - time;
lblResult.Text = "";
if (result == null) if (result == null)
{ {
this.aoiImage.Image = null; this.aoiImage.Image = null;
lblResult.ForeColor = Color.Red ; lblResult.ForeColor = Color.Red;
lblResult.Text = AOIResourceCulture.GetValue("匹配失败") + " (0%)"; lblResult.Text = AOIResourceCulture.GetValue("匹配失败") + " (0%)";
} }
else else
...@@ -92,16 +83,15 @@ namespace AccAOI.control ...@@ -92,16 +83,15 @@ namespace AccAOI.control
{ {
lblResult.ForeColor = Color.Red; lblResult.ForeColor = Color.Red;
} }
lblResult.Text += " (" + result.percentValue + "%)"; lblResult.Text += " (" + result.percentValue + "%)";
if (result.currentRoiImage != null) if (result.currentRoiImage != null)
{ {
SetCurrImageType(2); SetCurrImageType(2);
this.aoiImage.Image = result.currentRoiImage; this.aoiImage.Image = result.currentRoiImage;
} }
} }
lblTime.Text= "times :" + Math.Round(span.TotalSeconds, 1)+ "s"; lblTime.Text = "times :" + Math.Round(span.TotalSeconds, 1) + "s";
} }
} }
public override void UpdateImage() public override void UpdateImage()
......
namespace AccAOI.control
{
partial class AoiColorMatchControl
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lblResult = new System.Windows.Forms.Label();
this.btnTest = new Asa.Theme.FlatButton();
this.lblTime = new System.Windows.Forms.Label();
this.trackBarSamePercent = new System.Windows.Forms.TrackBar();
this.flatLabel3 = new Asa.Theme.FlatLabel();
this.txtSamePercent = new Asa.Theme.FlatText();
this.panParam.SuspendLayout();
this.panResult.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBarSamePercent)).BeginInit();
this.SuspendLayout();
//
// panParam
//
this.panParam.Controls.Add(this.txtSamePercent);
this.panParam.Controls.Add(this.trackBarSamePercent);
this.panParam.Controls.Add(this.flatLabel3);
this.panParam.Size = new System.Drawing.Size(298, 88);
//
// panResult
//
this.panResult.Controls.Add(this.lblTime);
this.panResult.Controls.Add(this.btnTest);
this.panResult.Controls.Add(this.lblResult);
this.panResult.Location = new System.Drawing.Point(4, 413);
this.panResult.Size = new System.Drawing.Size(298, 410);
//
// lblResult
//
this.lblResult.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.lblResult.Font = new System.Drawing.Font("微软雅黑", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblResult.ForeColor = System.Drawing.Color.Red;
this.lblResult.Location = new System.Drawing.Point(8, 88);
this.lblResult.Name = "lblResult";
this.lblResult.Size = new System.Drawing.Size(283, 24);
this.lblResult.TabIndex = 4;
this.lblResult.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnTest
//
this.btnTest.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnTest.Font = new System.Drawing.Font("宋体", 9F);
this.btnTest.ImageSize = new System.Drawing.Size(0, 0);
this.btnTest.Inside = false;
this.btnTest.Location = new System.Drawing.Point(92, 36);
this.btnTest.Name = "btnTest";
this.btnTest.Size = new System.Drawing.Size(115, 30);
this.btnTest.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnTest.TabIndex = 5;
this.btnTest.Text = "测试结果";
this.btnTest.Click += new System.EventHandler(this.btnTest_Click);
//
// lblTime
//
this.lblTime.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.lblTime.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblTime.ForeColor = System.Drawing.Color.Green;
this.lblTime.Location = new System.Drawing.Point(8, 123);
this.lblTime.Name = "lblTime";
this.lblTime.Size = new System.Drawing.Size(283, 24);
this.lblTime.TabIndex = 8;
this.lblTime.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// trackBarSamePercent
//
this.trackBarSamePercent.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.trackBarSamePercent.Location = new System.Drawing.Point(125, 40);
this.trackBarSamePercent.Maximum = 100;
this.trackBarSamePercent.Name = "trackBarSamePercent";
this.trackBarSamePercent.Size = new System.Drawing.Size(165, 45);
this.trackBarSamePercent.TabIndex = 12;
this.trackBarSamePercent.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBarSamePercent.Value = 50;
this.trackBarSamePercent.ValueChanged += new System.EventHandler(this.trackBarSamePercent_ValueChanged);
//
// flatLabel3
//
this.flatLabel3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.flatLabel3.Font = new System.Drawing.Font("宋体", 9F);
this.flatLabel3.Inside = false;
this.flatLabel3.Location = new System.Drawing.Point(6, 37);
this.flatLabel3.Name = "flatLabel3";
this.flatLabel3.Size = new System.Drawing.Size(70, 30);
this.flatLabel3.TabIndex = 11;
this.flatLabel3.Text = "相似度:";
this.flatLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtSamePercent
//
this.txtSamePercent.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.txtSamePercent.Font = new System.Drawing.Font("宋体", 9F);
this.txtSamePercent.Inside = false;
this.txtSamePercent.Location = new System.Drawing.Point(82, 37);
this.txtSamePercent.Name = "txtSamePercent";
this.txtSamePercent.Padding = new System.Windows.Forms.Padding(3);
this.txtSamePercent.Size = new System.Drawing.Size(41, 30);
this.txtSamePercent.TabIndex = 26;
this.txtSamePercent.Text = "50";
this.txtSamePercent.TextChanged += new System.EventHandler(this.txtSamePercent_TextChanged);
//
// AioTempMatchControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(312, 833);
this.Name = "AioTempMatchControl";
this.TitleName = "颜色匹配";
this.panParam.ResumeLayout(false);
this.panParam.PerformLayout();
this.panResult.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBarSamePercent)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label lblResult;
private Asa.Theme.FlatButton btnTest;
private System.Windows.Forms.Label lblTime;
private System.Windows.Forms.TrackBar trackBarSamePercent;
private Asa.Theme.FlatLabel flatLabel3;
private Asa.Theme.FlatText txtSamePercent;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AOI;
using System.Threading;
using System.Drawing.Drawing2D;
using System.IO;
using Asa.Theme;
namespace AccAOI.control
{
public partial class AoiColorMatchControl : ABaseControl
{
public AoiColorMatchControl()
{
InitializeComponent();
}
public override AoiMethod GetAoiInfo()
{
if (this.AoiInfo is AoiColorMatchMethod)
{
AoiColorMatchMethod method = (AoiColorMatchMethod)AoiInfo;
if (currPath != null)
{
method.RoiPath = currPath;
}
int value =trackBarSamePercent.Value;
SetText(txtSamePercent, trackBarSamePercent.Value);
// int value = trackBarSamePercent.Value;
method.SamePercent = value;
AoiInfo = method;
}
return AoiInfo;
}
public override void ShowAoiInfo()
{
if (this.AoiInfo is AoiColorMatchMethod)
{
AoiColorMatchMethod method = (AoiColorMatchMethod)AoiInfo;
trackBarSamePercent.Value = (int)method.SamePercent;
IsShowOk = true;
SetCurrImageType(1);
UpdateImage();
}
}
private void btnTest_Click(object sender, EventArgs e)
{
if (this.AoiInfo is AoiColorMatchMethod)
{
Image checkImg = FrmAoiSetting.TestImage;
if (checkImg == null)
{
MyMessage.Show("请选择测试图片");
return;
}
DateTime time = DateTime.Now;
AoiColorMatchMethod Match = (AoiColorMatchMethod)AoiInfo;
ResultBean result = Match.Check(FrmAoiSetting.BaseImg, checkImg);
TimeSpan span = DateTime.Now - time;
lblResult.Text = "";
if (result == null)
{
this.aoiImage.Image = null;
lblResult.ForeColor = Color.Red;
lblResult.Text = AOIResourceCulture.GetValue("匹配失败") + " (0%)";
}
else
{
lblResult.ForeColor = Color.Green;
//lblResult.Text =result.result? "OK" :"NG" ;
if (!result.result)
{
lblResult.ForeColor = Color.Red;
}
lblResult.Text += " (" + result.percentValue + "%)";
if (result.currentRoiImage != null)
{
SetCurrImageType(2);
this.aoiImage.Image = result.currentRoiImage;
}
}
lblTime.Text = "times :" + Math.Round(span.TotalSeconds, 1) + "s";
}
}
public override void UpdateImage()
{
if (!IsShowOk)
{
return;
}
if (Monitor.TryEnter(UpdateLock))
{
try
{
int value = trackBarSamePercent.Value;
SetText(txtSamePercent, trackBarSamePercent.Value);
Image BaseImage = GetImg();
if (BaseImage == null || currPath == null)
{
return;
}
GetAoiInfo();
AoiColorMatchMethod MatchMethod = (AoiColorMatchMethod)AoiInfo;
MatchMethod.RoiPath = currPath;
if (ShowImageType.Equals(1))
{
Image cutImage = MatchMethod.GetRoiImage(BaseImage, true);
aoiImage.Image = cutImage;
}
else
{
aoiImage.Image = null;
}
GC.Collect();
}
catch (Exception ex)
{
Console.WriteLine("UpdateImage出错:" + ex.ToString());
}
finally
{
Monitor.Exit(UpdateLock);
}
}
else
{
Console.WriteLine("UpdateImage执行失败,未得到锁");
}
}
//private void btnOpenImage_Click(object sender, EventArgs e)
//{
// System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
// openDialog.Title = AOIResourceCulture.GetValue("打开本地图片");
// 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;
// txtImage.Text = fileName;
//}
private void trackBarSamePercent_ValueChanged(object sender, EventArgs e)
{
UpdateImage();
}
private void SetTbValue(TrackBar tb, int value)
{
if (tb.Value.Equals(value.ToString()))
{
return;
}
if (value < tb.Minimum)
{
tb.Value = tb.Minimum;
}
else if (value > tb.Maximum)
{
tb.Value = tb.Maximum;
}
else
{
tb.Value = value;
}
UpdateImage();
}
private void SetText(FlatText text, int value)
{
if (text.Text.ToString().Equals(value.ToString()))
{
return;
}
text.Text = value.ToString();
}
private void txtSamePercent_TextChanged(object sender, EventArgs e)
{
int value = AOIFormUtil.GetIntValue(txtSamePercent);
SetTbValue(trackBarSamePercent, value);
UpdateImage();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file \ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!