Commit 90fb296f SK

Mark 搜索区域显示

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