Commit 3589303b LN

1

2 个父辈 fe992407 860cabb5
...@@ -12,11 +12,26 @@ namespace AOI ...@@ -12,11 +12,26 @@ namespace AOI
{ {
public abstract class AoiMethod public abstract class AoiMethod
{ {
//public string FullTypeName { get; set; }
//public string PathDatas { get; set; }
public string MethodName { get; set; } public string MethodName { get; set; }
/// <summary> /// <summary>
/// 兴趣区域路径 /// 兴趣区域路径
/// </summary> /// </summary>
public GraphicsPath RoiPath; [Newtonsoft.Json.JsonIgnore()]
public GraphicsPath RoiPath { get; set; }
public PathData GetRoiPathData()
{
if (RoiPath != null)
{
return RoiPath.PathData;
}
return null;
}
public abstract ResultBean Check(Image standardImage, Image imageToCheck); public abstract ResultBean Check(Image standardImage, Image imageToCheck);
......
...@@ -22,7 +22,7 @@ namespace AOI ...@@ -22,7 +22,7 @@ namespace AOI
/// <summary> /// <summary>
/// 标准的Image /// 标准的Image
/// </summary> /// </summary>
private Image standardImage { get; set; } public Image standardImage { get; set; }
/// <summary> /// <summary>
/// 所有的AOI方法 /// 所有的AOI方法
...@@ -68,7 +68,18 @@ namespace AOI ...@@ -68,7 +68,18 @@ namespace AOI
Dictionary<string, string> projectMap = new Dictionary<string, string>(); Dictionary<string, string> projectMap = new Dictionary<string, string>();
string base64ImgStr = Base64Util.ToBase64(this.standardImage); string base64ImgStr = Base64Util.ToBase64(this.standardImage);
projectMap.Add("base64Img", base64ImgStr); projectMap.Add("base64Img", base64ImgStr);
string methodMapJson = JsonUtil.SerializeObject(this.methodMap); var mapForJson = new Dictionary<string, string>();
foreach(var item in this.methodMap)
{
JObject obj = JObject.FromObject(item.Value);
obj.Add("FullTypeName",item.Value.GetType().FullName);
var roiPathData = item.Value.GetRoiPathData();
string roiPathDataStr = JsonUtil.SerializeObject(roiPathData);
obj.Add("PathDataStr", roiPathDataStr);
string jsonStr = JsonUtil.SerializeObject(obj);
mapForJson.Add(item.Key, jsonStr);
}
string methodMapJson = JsonUtil.SerializeObject(mapForJson);
projectMap.Add("methodMap", methodMapJson); projectMap.Add("methodMap", methodMapJson);
JsonUtil.SerializeObjectToFile(projectMap,filePath,false); JsonUtil.SerializeObjectToFile(projectMap,filePath,false);
} }
...@@ -79,7 +90,21 @@ namespace AOI ...@@ -79,7 +90,21 @@ namespace AOI
string base64Img = projectMap["base64Img"]; string base64Img = projectMap["base64Img"];
this.standardImage = Base64Util.ToImage(base64Img); this.standardImage = Base64Util.ToImage(base64Img);
string methodMapJson = projectMap["methodMap"]; string methodMapJson = projectMap["methodMap"];
this.methodMap = JsonUtil.DeserializeJsonToObject<Dictionary<string, AoiMethod>>(methodMapJson); var jsonMap = JsonUtil.DeserializeJsonToObject<Dictionary<string, string>>(methodMapJson);
foreach(var item in jsonMap)
{
JObject obj = JObject.Parse(item.Value);
string fullTypeName = obj.Value<string>("FullTypeName");
Type t = Type.GetType(fullTypeName);
JsonSerializer serializer = new JsonSerializer();
StringReader sr = new StringReader(item.Value);
object o = serializer.Deserialize(new JsonTextReader(sr), t);
AoiMethod aoiMethod = (AoiMethod)o;
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);
}
} }
......
...@@ -13,20 +13,20 @@ namespace AOI ...@@ -13,20 +13,20 @@ namespace AOI
/// </summary> /// </summary>
public class AoiMethodRgb : AoiMethod public class AoiMethodRgb : AoiMethod
{ {
public int minR = 1; public int minR { get; set; }
public int maxR = 255; public int maxR { get; set; }
public int minG = 1; public int minG { get; set; }
public int maxG = 255; public int maxG { get; set; }
public int minB = 1; public int minB { get; set; }
public int maxB = 255; public int maxB { get; set; }
/// <summary> /// <summary>
/// 抽取出的像素最小占比 /// 抽取出的像素最小占比
/// </summary> /// </summary>
public float minRate = 0; public float minRate { get; set; }
/// <summary> /// <summary>
/// 抽取出的像素最大占比 /// 抽取出的像素最大占比
/// </summary> /// </summary>
public float maxRate = 100; public float maxRate { get; set; }
public override ResultBean Check(Image standardImage, Image imageToCheck) public override ResultBean Check(Image standardImage, Image imageToCheck)
{ {
......
...@@ -66,6 +66,7 @@ namespace AOI ...@@ -66,6 +66,7 @@ namespace AOI
T t = o as T; T t = o as T;
return t; return t;
} }
/// <summary> /// <summary>
/// 解析文件到生成对象实体 /// 解析文件到生成对象实体
/// </summary> /// </summary>
......
...@@ -49,25 +49,25 @@ ...@@ -49,25 +49,25 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="control\AioMarkControl.cs"> <Compile Include="control\AioMarkControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\AioMarkControl.Designer.cs"> <Compile Include="control\AioMarkControl.Designer.cs">
<DependentUpon>AioMarkControl.cs</DependentUpon> <DependentUpon>AioMarkControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="control\AoiBlobControl.cs"> <Compile Include="control\AoiBlobControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\AoiBlobControl.Designer.cs"> <Compile Include="control\AoiBlobControl.Designer.cs">
<DependentUpon>AoiBlobControl.cs</DependentUpon> <DependentUpon>AoiBlobControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="control\ABaseControl.cs"> <Compile Include="control\ABaseControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\ABaseControl.Designer.cs"> <Compile Include="control\ABaseControl.Designer.cs">
<DependentUpon>ABaseControl.cs</DependentUpon> <DependentUpon>ABaseControl.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="control\AoiRgbControl.cs"> <Compile Include="control\AoiRgbControl.cs">
<SubType>UserControl</SubType> <SubType>Form</SubType>
</Compile> </Compile>
<Compile Include="control\AoiRgbControl.Designer.cs"> <Compile Include="control\AoiRgbControl.Designer.cs">
<DependentUpon>AoiRgbControl.cs</DependentUpon> <DependentUpon>AoiRgbControl.cs</DependentUpon>
...@@ -88,9 +88,7 @@ ...@@ -88,9 +88,7 @@
<Compile Include="imageBoxEx\DragHandle.cs" /> <Compile Include="imageBoxEx\DragHandle.cs" />
<Compile Include="imageBoxEx\DragHandleAnchor.cs" /> <Compile Include="imageBoxEx\DragHandleAnchor.cs" />
<Compile Include="imageBoxEx\DragHandleCollection.cs" /> <Compile Include="imageBoxEx\DragHandleCollection.cs" />
<Compile Include="imageBoxEx\ImageBoxEx.cs"> <Compile Include="imageBoxEx\ImageBoxEx.cs" />
<SubType>Component</SubType>
</Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="control\AioMarkControl.resx"> <EmbeddedResource Include="control\AioMarkControl.resx">
......
namespace AccAOI using Cyotek.Windows.Forms;
namespace AccAOI
{ {
partial class Form1 partial class Form1
{ {
...@@ -40,8 +42,8 @@ ...@@ -40,8 +42,8 @@
this.minB = new System.Windows.Forms.NumericUpDown(); this.minB = new System.Windows.Forms.NumericUpDown();
this.maxB = new System.Windows.Forms.NumericUpDown(); this.maxB = new System.Windows.Forms.NumericUpDown();
this.labelCount = new System.Windows.Forms.Label(); this.labelCount = new System.Windows.Forms.Label();
this.imageBoxEx1 = new AccAOI.ImageBoxEx(); this.imageBoxEx1 = new ImageBox();
this.imageBox = new AccAOI.ImageBoxEx(); this.imageBox = new ImageBox();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.maxR)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.maxR)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.minR)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.minR)).BeginInit();
...@@ -203,7 +205,7 @@ ...@@ -203,7 +205,7 @@
// //
// imageBoxEx1 // imageBoxEx1
// //
this.imageBoxEx1.DragHandleSize = 9; //this.imageBoxEx1.DragHandleSize = 9;
this.imageBoxEx1.Location = new System.Drawing.Point(475, 50); this.imageBoxEx1.Location = new System.Drawing.Point(475, 50);
this.imageBoxEx1.Name = "imageBoxEx1"; this.imageBoxEx1.Name = "imageBoxEx1";
this.imageBoxEx1.Size = new System.Drawing.Size(230, 159); this.imageBoxEx1.Size = new System.Drawing.Size(230, 159);
...@@ -212,7 +214,7 @@ ...@@ -212,7 +214,7 @@
// imageBox // imageBox
// //
this.imageBox.Dock = System.Windows.Forms.DockStyle.Fill; this.imageBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.imageBox.DragHandleSize = 9; //this.imageBox.DragHandleSize = 9;
this.imageBox.Location = new System.Drawing.Point(0, 0); this.imageBox.Location = new System.Drawing.Point(0, 0);
this.imageBox.Name = "imageBox"; this.imageBox.Name = "imageBox";
this.imageBox.SelectionColor = System.Drawing.Color.Empty; this.imageBox.SelectionColor = System.Drawing.Color.Empty;
...@@ -258,7 +260,7 @@ ...@@ -258,7 +260,7 @@
#endregion #endregion
private System.Windows.Forms.Button buttonOpen; private System.Windows.Forms.Button buttonOpen;
private ImageBoxEx imageBox; private ImageBox imageBox;
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label R; private System.Windows.Forms.Label R;
private System.Windows.Forms.NumericUpDown maxR; private System.Windows.Forms.NumericUpDown maxR;
...@@ -269,7 +271,7 @@ ...@@ -269,7 +271,7 @@
private System.Windows.Forms.NumericUpDown maxG; private System.Windows.Forms.NumericUpDown maxG;
private System.Windows.Forms.NumericUpDown minB; private System.Windows.Forms.NumericUpDown minB;
private System.Windows.Forms.NumericUpDown maxB; private System.Windows.Forms.NumericUpDown maxB;
private ImageBoxEx imageBoxEx1; private ImageBox imageBoxEx1;
private System.Windows.Forms.Label labelCount; private System.Windows.Forms.Label labelCount;
} }
} }
......
...@@ -63,11 +63,8 @@ namespace AccAOI ...@@ -63,11 +63,8 @@ namespace AccAOI
//{ //{
Matrix translateMatrix = new Matrix(); Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0); translateMatrix.Translate(100, 0);
RectangleF region = imageBox.SelectionRegion; Image threshImage = CutImage(imageBox.Image, imageBox.SelectionRegion);
GraphicsPath path = new GraphicsPath();
path.AddEllipse(region);
Image threshImage = CutImage(imageBox.Image, path);
cutImage = threshImage; cutImage = threshImage;
imageBoxEx1.Image = threshImage; imageBoxEx1.Image = threshImage;
} }
......
namespace AccAOI using Cyotek.Windows.Forms;
namespace AccAOI
{ {
partial class FrmAoiSetting partial class FrmAoiSetting
{ {
...@@ -38,7 +40,7 @@ ...@@ -38,7 +40,7 @@
this.btnGetCameraImg = new Asa.Theme.FlatButton(); this.btnGetCameraImg = new Asa.Theme.FlatButton();
this.comType = new Asa.Theme.FlatCombo(); this.comType = new Asa.Theme.FlatCombo();
this.panAoi = new System.Windows.Forms.Panel(); this.panAoi = new System.Windows.Forms.Panel();
this.imageBox1 = new AccAOI.ImageBoxEx(); this.imageBox1 = new ImageBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// aoiList // aoiList
...@@ -158,7 +160,7 @@ ...@@ -158,7 +160,7 @@
this.imageBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.imageBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.imageBox1.DragHandleSize = 9; //this.imageBox1.DragHandleSize = 9;
this.imageBox1.Location = new System.Drawing.Point(625, 40); this.imageBox1.Location = new System.Drawing.Point(625, 40);
this.imageBox1.Name = "imageBox1"; this.imageBox1.Name = "imageBox1";
this.imageBox1.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle; this.imageBox1.SelectionMode = Cyotek.Windows.Forms.ImageBoxSelectionMode.Rectangle;
...@@ -204,7 +206,7 @@ ...@@ -204,7 +206,7 @@
#endregion #endregion
private Asa.Theme.FlatList aoiList; private Asa.Theme.FlatList aoiList;
private ImageBoxEx imageBox1; private ImageBox imageBox1;
private Asa.Theme.FlatButton btnOpenPro; private Asa.Theme.FlatButton btnOpenPro;
private Asa.Theme.FlatButton btnSavePro; private Asa.Theme.FlatButton btnSavePro;
private Asa.Theme.FlatButton btnNewAoi; private Asa.Theme.FlatButton btnNewAoi;
......
...@@ -73,11 +73,6 @@ namespace AccAOI ...@@ -73,11 +73,6 @@ namespace AccAOI
private void btnOpenPro_Click(object sender, EventArgs e) private void btnOpenPro_Click(object sender, EventArgs e)
{ {
if (this.Img == null)
{
MessageBox.Show("清先打开图片");
return;
}
System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog(); System.Windows.Forms.OpenFileDialog openDialog = new System.Windows.Forms.OpenFileDialog();
openDialog.Title = "打开项目"; openDialog.Title = "打开项目";
openDialog.Filter = "(*.data)|*.data|(*.*)|*.*"; openDialog.Filter = "(*.data)|*.data|(*.*)|*.*";
...@@ -188,7 +183,7 @@ namespace AccAOI ...@@ -188,7 +183,7 @@ namespace AccAOI
if (method.RoiPath != null) if (method.RoiPath != null)
{ {
currPath = method.RoiPath; currPath = method.RoiPath;
imageBox1.SelectionRegion = method.RoiPath.GetBounds(); imageBox1.SelectionRegion = method.RoiPath;
Image threshImage = CutImage(imageBox1.Image, currPath); Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage; cutImage = threshImage;
...@@ -227,6 +222,8 @@ namespace AccAOI ...@@ -227,6 +222,8 @@ namespace AccAOI
if (Project != null) if (Project != null)
{ {
aoiList.ItemClear(); aoiList.ItemClear();
imageBox1.Image = Project.standardImage;
imageBox1.SelectionRegion = new GraphicsPath();
if (Project.methodMap.Count > 0) if (Project.methodMap.Count > 0)
{ {
foreach(string key in Project.methodMap.Keys) foreach(string key in Project.methodMap.Keys)
...@@ -273,16 +270,17 @@ namespace AccAOI ...@@ -273,16 +270,17 @@ namespace AccAOI
Matrix translateMatrix = new Matrix(); Matrix translateMatrix = new Matrix();
translateMatrix.Translate(100, 0); translateMatrix.Translate(100, 0);
RectangleF region = imageBox1.SelectionRegion; //RectangleF region = imageBox1.SelectionRegion;
currPath = new GraphicsPath(); //currPath = new GraphicsPath();
if (aoiControl.AreaType.Equals(1)) //if (aoiControl.AreaType.Equals(1))
{ //{
currPath.AddRectangle(region); // currPath.AddRectangle(region);
} //}
else //else
{ //{
currPath.AddEllipse(region); // currPath.AddEllipse(region);
} //}
currPath = imageBox1.SelectionRegion;
Image threshImage = CutImage(imageBox1.Image, currPath); Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage; cutImage = threshImage;
......
namespace AccAOI.control using Cyotek.Windows.Forms;
namespace AccAOI.control
{ {
partial class ABaseControl partial class ABaseControl
{ {
...@@ -36,7 +38,7 @@ ...@@ -36,7 +38,7 @@
this.btnClearArea = new Asa.Theme.FlatButton(); this.btnClearArea = new Asa.Theme.FlatButton();
this.btnSetArea = new Asa.Theme.FlatButton(); this.btnSetArea = new Asa.Theme.FlatButton();
this.btnYuan = new Asa.Theme.FlatButton(); this.btnYuan = new Asa.Theme.FlatButton();
this.aoiImage = new AccAOI.ImageBoxEx(); this.aoiImage = new ImageBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// panControl // panControl
...@@ -136,7 +138,7 @@ ...@@ -136,7 +138,7 @@
// //
this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.aoiImage.DragHandleSize = 9; //this.aoiImage.DragHandleSize = 9;
this.aoiImage.Location = new System.Drawing.Point(9, 53); this.aoiImage.Location = new System.Drawing.Point(9, 53);
this.aoiImage.Name = "aoiImage"; this.aoiImage.Name = "aoiImage";
this.aoiImage.Size = new System.Drawing.Size(288, 182); this.aoiImage.Size = new System.Drawing.Size(288, 182);
...@@ -171,7 +173,7 @@ ...@@ -171,7 +173,7 @@
private Asa.Theme.FlatPanel panControl; private Asa.Theme.FlatPanel panControl;
protected Asa.Theme.FlatPanel panParam; protected Asa.Theme.FlatPanel panParam;
protected Asa.Theme.FlatPanel panResult; protected Asa.Theme.FlatPanel panResult;
public ImageBoxEx aoiImage; public ImageBox aoiImage;
private Asa.Theme.FlatButton btnYuan; private Asa.Theme.FlatButton btnYuan;
} }
} }
此文件的差异太大,无法显示。
...@@ -27,6 +27,6 @@ ...@@ -27,6 +27,6 @@
/// <summary> /// <summary>
/// Zoom selection. /// Zoom selection.
/// </summary> /// </summary>
Zoom Eclipse,
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!