Commit 3589303b LN

1

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