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;
}
}
......
......@@ -64,10 +64,7 @@ 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;
}
}
......@@ -21,7 +21,8 @@ namespace Cyotek.Windows.Forms
[DefaultProperty("Image")]
[ToolboxBitmap(typeof(ImageBox), "ImageBox.bmp")]
[ToolboxItem(true)]
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */ public class ImageBox : VirtualScrollableControl
/* [Designer("Cyotek.Windows.Forms.Design.ImageBoxDesigner", Cyotek.Windows.Forms.ImageBox.Design.dll, PublicKeyToken=58daa28b0b2de221")] */
public class ImageBox : VirtualScrollableControl
{
#region Constants
......@@ -83,7 +84,7 @@ namespace Cyotek.Windows.Forms
private ImageBoxSelectionMode _selectionMode;
private RectangleF _selectionRegion;
private GraphicsPath _selectionRegion = new GraphicsPath();
private bool _shortcutsEnabled;
......@@ -892,8 +893,9 @@ namespace Cyotek.Windows.Forms
this.DrawPixelGrid(e.Graphics);
}
// draw the selection
if (this.SelectionRegion != Rectangle.Empty)
if (this.SelectionRegion != null && this.SelectionRegion.PointCount > 0)
{
this.DrawSelection(e);
}
......@@ -1526,7 +1528,7 @@ namespace Cyotek.Windows.Forms
/// </value>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual RectangleF SelectionRegion
public virtual GraphicsPath SelectionRegion
{
get { return _selectionRegion; }
set
......@@ -2378,20 +2380,26 @@ namespace Cyotek.Windows.Forms
result = null;
if (!this.SelectionRegion.IsEmpty)
var bounds = this.SelectionRegion.GetBounds();
if (this.SelectionRegion.PointCount > 0)
{
Rectangle rect;
rect = this.FitRectangle(new Rectangle((int)this.SelectionRegion.X, (int)this.SelectionRegion.Y, (int)this.SelectionRegion.Width, (int)this.SelectionRegion.Height));
if (rect.Width > 0 && rect.Height > 0)
if (bounds.Width > 0 && bounds.Height > 0)
{
result = new Bitmap(rect.Width, rect.Height);
Bitmap mask = new Bitmap(this.Image.Width, this.Image.Height);
using (Graphics g = Graphics.FromImage(mask))
{
var br = new TextureBrush(this.Image);
g.FillPath(br, this.SelectionRegion);
}
var dstRect = new RectangleF(0, 0, bounds.Width, bounds.Height);
var srcRect = new RectangleF(bounds.X, bounds.Y, bounds.Width, bounds.Height);
using (Graphics g = Graphics.FromImage(result))
{
g.DrawImage(this.Image, new Rectangle(Point.Empty, rect.Size), rect, GraphicsUnit.Pixel);
result = new Bitmap((int)bounds.Width, (int)bounds.Width);
g.DrawImage(mask, dstRect, srcRect, GraphicsUnit.Pixel);
}
return result;
}
}
......@@ -2629,20 +2637,11 @@ namespace Cyotek.Windows.Forms
}
/// <summary>
/// Creates a selection region which encompasses the entire image
/// </summary>
/// <exception cref="System.InvalidOperationException">Thrown if no image is currently set</exception>
public virtual void SelectAll()
{
this.SelectionRegion = new RectangleF(PointF.Empty, this.ViewSize);
}
/// <summary>
/// Clears any existing selection region
/// </summary>
public virtual void SelectNone()
{
this.SelectionRegion = RectangleF.Empty;
this.SelectionRegion = new GraphicsPath();
}
/// <summary>
......@@ -3160,20 +3159,36 @@ namespace Cyotek.Windows.Forms
/// </param>
protected virtual void DrawSelection(PaintEventArgs e)
{
RectangleF rect;
e.Graphics.SetClip(this.GetInsideViewPort(true));
rect = this.GetOffsetRectangle(this.SelectionRegion);
GraphicsPath newPath = new GraphicsPath(this.SelectionRegion.PathPoints, this.SelectionRegion.PathTypes);
Matrix matrix = new Matrix();
matrix.Scale((float)this.ZoomFactor, (float)this.ZoomFactor);
newPath.Transform(matrix);
var viewport = this.GetImageViewPort();
var offsetX = viewport.Left + this.Padding.Left + this.AutoScrollPosition.X;
var offsetY = viewport.Top + this.Padding.Top + this.AutoScrollPosition.Y;
matrix = new Matrix();
matrix.Translate(offsetX, offsetY);
newPath.Transform(matrix);
//rect = this.GetOffsetRectangle(this.SelectionRegion);
using (Brush brush = new SolidBrush(Color.FromArgb(128, this.SelectionColor)))
{
e.Graphics.FillRectangle(brush, rect);
e.Graphics.FillPath(brush, newPath);
}
using (Pen pen = new Pen(this.SelectionColor))
{
e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
//e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height);
e.Graphics.DrawPath(pen, newPath);
}
e.Graphics.ResetClip();
......@@ -3670,16 +3685,16 @@ namespace Cyotek.Windows.Forms
{
EventHandler<EventArgs> handler;
switch (this.SelectionMode)
{
case ImageBoxSelectionMode.Zoom:
if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
{
this.ZoomToRegion(this.SelectionRegion);
this.SelectNone();
}
break;
}
//switch (this.SelectionMode)
//{
// case ImageBoxSelectionMode.Zoom:
// if (this.SelectionRegion.Width > SelectionDeadZone && this.SelectionRegion.Height > SelectionDeadZone)
// {
// this.ZoomToRegion(this.SelectionRegion);
// this.SelectNone();
// }
// break;
//}
handler = this.Selected;
......@@ -4205,8 +4220,10 @@ namespace Cyotek.Windows.Forms
{
selection = this.FitRectangle(selection);
}
this.SelectionRegion = selection;
GraphicsPath path = new GraphicsPath();
Region re = new Region();
path.AddRectangle(selection);
this.SelectionRegion = path;
}
}
}
......
......@@ -27,6 +27,6 @@
/// <summary>
/// Zoom selection.
/// </summary>
Zoom
Eclipse,
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!