Commit 90fb296f SK

Mark 搜索区域显示

1 个父辈 adc71ed4
...@@ -74,7 +74,10 @@ namespace AOI ...@@ -74,7 +74,10 @@ namespace AOI
resultImg = image; resultImg = image;
return resultBeans; return resultBeans;
} }
/// <summary>
/// 保存项目
/// </summary>
/// <param name="filePath"></param>
public void Save(string filePath) public void Save(string filePath)
{ {
Dictionary<string, string> projectMap = new Dictionary<string, string>(); Dictionary<string, string> projectMap = new Dictionary<string, string>();
...@@ -95,7 +98,10 @@ namespace AOI ...@@ -95,7 +98,10 @@ namespace AOI
projectMap.Add("methodMap", methodMapJson); projectMap.Add("methodMap", methodMapJson);
JsonUtil.SerializeObjectToFile(projectMap,filePath,false); JsonUtil.SerializeObjectToFile(projectMap,filePath,false);
} }
/// <summary>
/// 加载项目
/// </summary>
/// <param name="filePath"></param>
public void Load(string filePath) public void Load(string filePath)
{ {
Dictionary<string, string> projectMap = JsonUtil.DeserializeJsonToObjectFromFile<Dictionary<string, string>>(filePath); Dictionary<string, string> projectMap = JsonUtil.DeserializeJsonToObjectFromFile<Dictionary<string, string>>(filePath);
......
...@@ -16,9 +16,40 @@ namespace AOI ...@@ -16,9 +16,40 @@ namespace AOI
public class AoiMarkMethod : AoiMethod public class AoiMarkMethod : AoiMethod
{ {
/// <summary> /// <summary>
/// 搜索区域路径 /// 放大RoiPath作为SearchPath
/// </summary> /// </summary>
public GraphicsPath SearchPath; public float SearchPathZoom = 2.0f;
/// <summary>
/// 放大RoiPath作为SearchPath
/// </summary>
/// <param name="zoom">放大倍率</param>
/// <returns></returns>
public GraphicsPath GetSearchPath()
{
if(RoiPath != null && SearchPathZoom > 0)
{
GraphicsPath SearchPath = new GraphicsPath(RoiPath.PathPoints, RoiPath.PathTypes);
Matrix matrix = new Matrix();
matrix.Scale(SearchPathZoom, SearchPathZoom);
SearchPath.Transform(matrix);
var oldBounds = this.RoiPath.GetBounds();
var newBounds = SearchPath.GetBounds();
var oldCenterX = oldBounds.X + oldBounds.Width / 2;
var oldCenterY = oldBounds.Y + oldBounds.Height / 2;
var newCenterX = newBounds.X + newBounds.Width / 2;
var newCenterY = newBounds.Y + newBounds.Height / 2;
matrix.Reset();
matrix.Translate(oldCenterX - newCenterX, oldCenterY - newCenterY);
SearchPath.Transform(matrix);
return SearchPath;
}
return RoiPath;
}
/// <summary> /// <summary>
/// 根据Mark点校正相机获取的图片 /// 根据Mark点校正相机获取的图片
...@@ -44,6 +75,7 @@ namespace AOI ...@@ -44,6 +75,7 @@ namespace AOI
//标准图中的Mart区域 //标准图中的Mart区域
Image markImage = GetRoiImage(standardImage, RoiPath, needCut); Image markImage = GetRoiImage(standardImage, RoiPath, needCut);
//搜索区域 //搜索区域
var SearchPath = GetSearchPath();
Image searchImage = GetRoiImage(imageToCheck, SearchPath, needCut); Image searchImage = GetRoiImage(imageToCheck, SearchPath, needCut);
if (markImage != null && searchImage != null) if (markImage != null && searchImage != null)
{ {
......
...@@ -198,7 +198,7 @@ namespace AccAOI ...@@ -198,7 +198,7 @@ namespace AccAOI
//Image threshImage = CutImage(imageBox1.Image, currPath); //Image threshImage = CutImage(imageBox1.Image, currPath);
//cutImage = threshImage; //cutImage = threshImage;
aoiControl.SetCurrPath(currPath,false); aoiControl.SetCurrPath(currPath,true);
} }
aoiControl.Show(); aoiControl.Show();
aoiControl.ShowAoiInfo(); aoiControl.ShowAoiInfo();
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.flatLabel1 = new Asa.Theme.FlatLabel(); this.flatLabel1 = new Asa.Theme.FlatLabel();
this.flatTextSearch = new Asa.Theme.FlatText(); this.flatTextSearchZoom = new Asa.Theme.FlatText();
this.flatLabel2 = new Asa.Theme.FlatLabel(); this.flatLabel2 = new Asa.Theme.FlatLabel();
this.lblResult = new System.Windows.Forms.Label(); this.lblResult = new System.Windows.Forms.Label();
this.btnTest = new Asa.Theme.FlatButton(); this.btnTest = new Asa.Theme.FlatButton();
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
// panParam // panParam
// //
this.panParam.Controls.Add(this.flatLabel2); this.panParam.Controls.Add(this.flatLabel2);
this.panParam.Controls.Add(this.flatTextSearch); this.panParam.Controls.Add(this.flatTextSearchZoom);
this.panParam.Controls.Add(this.flatLabel1); this.panParam.Controls.Add(this.flatLabel1);
// //
// panResult // panResult
...@@ -58,15 +58,15 @@ ...@@ -58,15 +58,15 @@
this.flatLabel1.TabIndex = 0; this.flatLabel1.TabIndex = 0;
this.flatLabel1.Text = "搜索区域:"; this.flatLabel1.Text = "搜索区域:";
// //
// flatTextSearch // flatTextSearchZoom
// //
this.flatTextSearch.Font = new System.Drawing.Font("宋体", 9F); this.flatTextSearchZoom.Font = new System.Drawing.Font("宋体", 9F);
this.flatTextSearch.Inside = false; this.flatTextSearchZoom.Inside = false;
this.flatTextSearch.Location = new System.Drawing.Point(175, 50); this.flatTextSearchZoom.Location = new System.Drawing.Point(175, 50);
this.flatTextSearch.Name = "flatTextSearch"; this.flatTextSearchZoom.Name = "flatTextSearchZoom";
this.flatTextSearch.Size = new System.Drawing.Size(95, 30); this.flatTextSearchZoom.Size = new System.Drawing.Size(95, 30);
this.flatTextSearch.TabIndex = 1; this.flatTextSearchZoom.TabIndex = 1;
this.flatTextSearch.Text = "2"; this.flatTextSearchZoom.Text = "2";
// //
// flatLabel2 // flatLabel2
// //
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
#endregion #endregion
private Asa.Theme.FlatLabel flatLabel2; private Asa.Theme.FlatLabel flatLabel2;
private Asa.Theme.FlatText flatTextSearch; private Asa.Theme.FlatText flatTextSearchZoom;
private Asa.Theme.FlatLabel flatLabel1; private Asa.Theme.FlatLabel flatLabel1;
private System.Windows.Forms.Label lblResult; private System.Windows.Forms.Label lblResult;
private Asa.Theme.FlatButton btnTest; private Asa.Theme.FlatButton btnTest;
......
...@@ -8,6 +8,8 @@ using System.Text; ...@@ -8,6 +8,8 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using AOI; using AOI;
using System.Threading;
using System.Drawing.Drawing2D;
namespace AccAOI.control namespace AccAOI.control
{ {
...@@ -19,11 +21,19 @@ namespace AccAOI.control ...@@ -19,11 +21,19 @@ namespace AccAOI.control
} }
public override AoiMethod GetAoiInfo() public override AoiMethod GetAoiInfo()
{ {
if (this.AoiInfo is AoiMarkMethod)
{
AoiMarkMethod method = (AoiMarkMethod)AoiInfo;
float.TryParse(flatTextSearchZoom.Text, out float zoom);
method.SearchPathZoom = zoom;
if (currPath != null) if (currPath != null)
{ {
this.AoiInfo.RoiPath = currPath; method.RoiPath = currPath;
}
AoiInfo = method;
} }
return base.GetAoiInfo(); return AoiInfo;
} }
private void btnTest_Click(object sender, EventArgs e) private void btnTest_Click(object sender, EventArgs e)
...@@ -34,6 +44,7 @@ namespace AccAOI.control ...@@ -34,6 +44,7 @@ namespace AccAOI.control
Image result= mark.FixImage(FrmAoiSetting.Img, FrmAoiSetting.Img); Image result= mark.FixImage(FrmAoiSetting.Img, FrmAoiSetting.Img);
if (result == null) if (result == null)
{ {
this.aoiImage.Image = null;
lblResult.ForeColor = Color.Red ; lblResult.ForeColor = Color.Red ;
lblResult.Text = "Mark区域无效"; lblResult.Text = "Mark区域无效";
} }
...@@ -46,5 +57,45 @@ namespace AccAOI.control ...@@ -46,5 +57,45 @@ namespace AccAOI.control
} }
} }
public override void UpdateImage()
{
if (!IsShowOk)
{
return;
}
if (Monitor.TryEnter(UpdateLock))
{
try
{
Image BaseImage = GetImg();
if (BaseImage == null || currPath == null)
{
return;
}
GetAoiInfo();
AoiMarkMethod markMethod= (AoiMarkMethod)AoiInfo;
GraphicsPath searchPath = markMethod.GetSearchPath();
BImageBox.ShowPath(searchPath, Color.Yellow);
GC.Collect();
}
catch (Exception ex)
{
Console.WriteLine("UpdateImage出错:" + ex.ToString());
}
finally
{
Monitor.Exit(UpdateLock);
}
}
else
{
Console.WriteLine("UpdateImage执行失败,未得到锁");
}
}
} }
} }
...@@ -732,6 +732,7 @@ namespace Acc.ImageBox ...@@ -732,6 +732,7 @@ namespace Acc.ImageBox
this.Cursor = cursor; this.Cursor = cursor;
} }
private void StartResize(PointF anchor) private void StartResize(PointF anchor)
{ {
CancelEventArgs e; CancelEventArgs e;
......
...@@ -86,6 +86,10 @@ namespace Acc.ImageBox ...@@ -86,6 +86,10 @@ namespace Acc.ImageBox
private GraphicsPath _selectionRegion = new GraphicsPath(); private GraphicsPath _selectionRegion = new GraphicsPath();
private GraphicsPath _pathToShow;
private Color _pathColor;
private bool _shortcutsEnabled; private bool _shortcutsEnabled;
private bool _showPixelGrid; private bool _showPixelGrid;
...@@ -1537,6 +1541,7 @@ namespace Acc.ImageBox ...@@ -1537,6 +1541,7 @@ namespace Acc.ImageBox
{ {
if(value == null) { if(value == null) {
value = new GraphicsPath(); value = new GraphicsPath();
_pathToShow = null;
} }
_selectionRegion = value; _selectionRegion = value;
this.OnSelectionRegionChanged(EventArgs.Empty); this.OnSelectionRegionChanged(EventArgs.Empty);
...@@ -2643,7 +2648,7 @@ namespace Acc.ImageBox ...@@ -2643,7 +2648,7 @@ namespace Acc.ImageBox
/// </summary> /// </summary>
public virtual void SelectNone() public virtual void SelectNone()
{ {
this.SelectionRegion = new GraphicsPath(); this.SelectionRegion = null;
} }
/// <summary> /// <summary>
...@@ -3161,10 +3166,25 @@ namespace Acc.ImageBox ...@@ -3161,10 +3166,25 @@ namespace Acc.ImageBox
/// </param> /// </param>
protected virtual void DrawSelection(PaintEventArgs e) protected virtual void DrawSelection(PaintEventArgs e)
{ {
DrawPath(e.Graphics, this.SelectionRegion, true, this.SelectionColor);
if (_pathToShow != null)
{
DrawPath(e.Graphics, this._pathToShow, false, this._pathColor);
}
}
e.Graphics.SetClip(this.GetInsideViewPort(true)); /// <summary>
/// 画路径
/// </summary>
/// <param name="g"></param>
/// <param name="path"></param>
/// <param name="needFill"></param>
/// <param name="color"></param>
private void DrawPath(Graphics g, GraphicsPath path, bool needFill, Color color)
{
g.SetClip(this.GetInsideViewPort(true));
GraphicsPath newPath = new GraphicsPath(this.SelectionRegion.PathPoints, this.SelectionRegion.PathTypes); GraphicsPath newPath = new GraphicsPath(path.PathPoints, path.PathTypes);
Matrix matrix = new Matrix(); Matrix matrix = new Matrix();
matrix.Scale((float)this.ZoomFactor, (float)this.ZoomFactor); matrix.Scale((float)this.ZoomFactor, (float)this.ZoomFactor);
newPath.Transform(matrix); newPath.Transform(matrix);
...@@ -3176,21 +3196,26 @@ namespace Acc.ImageBox ...@@ -3176,21 +3196,26 @@ namespace Acc.ImageBox
matrix.Translate(offsetX, offsetY); matrix.Translate(offsetX, offsetY);
newPath.Transform(matrix); newPath.Transform(matrix);
//rect = this.GetOffsetRectangle(this.SelectionRegion); if (needFill)
{
using (Brush brush = new SolidBrush(Color.FromArgb(128, this.SelectionColor))) using (Brush brush = new SolidBrush(Color.FromArgb(128, color)))
{ {
e.Graphics.FillPath(brush, newPath); g.FillPath(brush, newPath);
}
} }
using (Pen pen = new Pen(this.SelectionColor)) using (Pen pen = new Pen(color))
{ {
//e.Graphics.DrawRectangle(pen, rect.X, rect.Y, rect.Width, rect.Height); g.DrawPath(pen, newPath);
}
e.Graphics.DrawPath(pen, newPath); g.ResetClip();
} }
e.Graphics.ResetClip(); public void ShowPath(GraphicsPath path, Color color)
{
_pathToShow = path;
_pathColor = color;
} }
/// <summary> /// <summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!