Commit f2064c27 LN

界面显示修改

1 个父辈 1fad1fd0
...@@ -48,6 +48,8 @@ namespace AOI ...@@ -48,6 +48,8 @@ namespace AOI
var bounds = path.GetBounds(); var bounds = path.GetBounds();
if (bounds.Width > 0 && bounds.Height > 0) if (bounds.Width > 0 && bounds.Height > 0)
{ {
try
{
Bitmap mask = new Bitmap(img.Width, img.Height); Bitmap mask = new Bitmap(img.Width, img.Height);
using (Graphics g = Graphics.FromImage(mask)) using (Graphics g = Graphics.FromImage(mask))
{ {
...@@ -56,6 +58,11 @@ namespace AOI ...@@ -56,6 +58,11 @@ namespace AOI
} }
return mask; return mask;
} }
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
} }
return null; return null;
} }
......
...@@ -13,6 +13,16 @@ namespace AOI ...@@ -13,6 +13,16 @@ namespace AOI
/// </summary> /// </summary>
public class AoiMethodRgb : AoiMethod public class AoiMethodRgb : AoiMethod
{ {
public AoiMethodRgb()
{
minR = 0;
minG = 0;
minB = 0;
maxR = 255;
maxG = 255;
maxB = 255;
}
public int minR { get; set; } public int minR { get; set; }
public int maxR { get; set; } public int maxR { get; set; }
public int minG { get; set; } public int minG { get; set; }
......
...@@ -15,7 +15,7 @@ namespace AccAOI ...@@ -15,7 +15,7 @@ namespace AccAOI
public partial class FrmAoiSetting : Asa.Theme.FlatForm public partial class FrmAoiSetting : Asa.Theme.FlatForm
{ {
private control.ABaseControl aoiControl = null; private control.ABaseControl aoiControl = null;
public Image Img = null; public static Image Img = null;
private AoiProject Project = null; private AoiProject Project = null;
public FrmAoiSetting() public FrmAoiSetting()
{ {
...@@ -40,6 +40,13 @@ namespace AccAOI ...@@ -40,6 +40,13 @@ namespace AccAOI
comType.ItemAdd("斑点分析"); comType.ItemAdd("斑点分析");
comType.ItemAdd("颜色抽取"); comType.ItemAdd("颜色抽取");
comType.Text = "Mark点设置"; comType.Text = "Mark点设置";
string defaultImg = "F:\\电路板图片\\照片 2创建于2019年4月19日 11_34_53.jpg";
if (System.IO.File.Exists(defaultImg))
{
//读取图片内容
Img = (Image)Image.FromFile(defaultImg).Clone();
imageBox1.Image = Img;
}
} }
private void btnOpenImage_Click(object sender, EventArgs e) private void btnOpenImage_Click(object sender, EventArgs e)
...@@ -57,7 +64,7 @@ namespace AccAOI ...@@ -57,7 +64,7 @@ namespace AccAOI
string fileName = openDialog.FileName; string fileName = openDialog.FileName;
//读取图片内容 //读取图片内容
this.Img = (Image)Image.FromFile(fileName).Clone(); Img = (Image)Image.FromFile(fileName).Clone();
imageBox1.Image = Img; imageBox1.Image = Img;
} }
...@@ -83,7 +90,7 @@ namespace AccAOI ...@@ -83,7 +90,7 @@ namespace AccAOI
return; return;
} }
string fileName = openDialog.FileName; string fileName = openDialog.FileName;
Project = new AoiProject(this.Img); Project = new AoiProject(Img);
Project.Load(fileName); Project.Load(fileName);
ShowPorject(); ShowPorject();
...@@ -113,14 +120,14 @@ namespace AccAOI ...@@ -113,14 +120,14 @@ namespace AccAOI
private void btnNewAoi_Click(object sender, EventArgs e) private void btnNewAoi_Click(object sender, EventArgs e)
{ {
if (this.Img == null) if (Img == null)
{ {
MessageBox.Show("清先打开图片"); MessageBox.Show("清先打开图片");
return; return;
} }
if (this.Project == null) if (this.Project == null)
{ {
Project = new AoiProject(this.Img); Project = new AoiProject(Img);
} }
if (comType.Text.Equals("")) if (comType.Text.Equals(""))
{ {
...@@ -177,8 +184,6 @@ namespace AccAOI ...@@ -177,8 +184,6 @@ namespace AccAOI
aoiControl.TitleName = method.MethodName; aoiControl.TitleName = method.MethodName;
aoiControl.TopLevel = false; aoiControl.TopLevel = false;
aoiControl.Parent = panAoi; aoiControl.Parent = panAoi;
aoiControl.Show();
aoiControl.ShowAoiInfo();
if (method.RoiPath != null) if (method.RoiPath != null)
{ {
...@@ -187,9 +192,10 @@ namespace AccAOI ...@@ -187,9 +192,10 @@ namespace AccAOI
Image threshImage = CutImage(imageBox1.Image, currPath); Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage; cutImage = threshImage;
aoiControl.currPath = currPath; aoiControl.SetCurrPath(currPath,false);
aoiControl.SetImage( threshImage);
} }
aoiControl.Show();
aoiControl.ShowAoiInfo();
} }
private void SaveCurrAoi() private void SaveCurrAoi()
{ {
...@@ -263,7 +269,7 @@ namespace AccAOI ...@@ -263,7 +269,7 @@ namespace AccAOI
{ {
try try
{ {
if (imageBox1.Image == null || this.Img == null || aoiControl == null) if (imageBox1.Image == null || Img == null || aoiControl == null)
{ {
return; return;
} }
...@@ -284,8 +290,7 @@ namespace AccAOI ...@@ -284,8 +290,7 @@ namespace AccAOI
Image threshImage = CutImage(imageBox1.Image, currPath); Image threshImage = CutImage(imageBox1.Image, currPath);
cutImage = threshImage; cutImage = threshImage;
aoiControl.currPath = currPath; aoiControl.SetCurrPath( currPath);
aoiControl.SetImage( threshImage);
}catch(Exception ex) }catch(Exception ex)
{ {
...@@ -293,6 +298,8 @@ namespace AccAOI ...@@ -293,6 +298,8 @@ namespace AccAOI
} }
private Image CutImage(Image src, GraphicsPath path) private Image CutImage(Image src, GraphicsPath path)
{ {
try
{
var bounds = path.GetBounds(); var bounds = path.GetBounds();
Bitmap b = new Bitmap(src.Width, src.Height); Bitmap b = new Bitmap(src.Width, src.Height);
using (Graphics g = Graphics.FromImage(b)) using (Graphics g = Graphics.FromImage(b))
...@@ -313,6 +320,10 @@ namespace AccAOI ...@@ -313,6 +320,10 @@ namespace AccAOI
} }
return result; return result;
} }
}catch(Exception ex)
{
Console.WriteLine("CutImage出错:" + ex.ToString());
}
return null; return null;
} }
......
...@@ -30,8 +30,6 @@ namespace AccAOI.control ...@@ -30,8 +30,6 @@ namespace AccAOI.control
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.aoiImage = new Cyotek.Windows.Forms.ImageBox();
this.btnYuan = new Asa.Theme.FlatButton();
this.btnSetArea = new Asa.Theme.FlatButton(); this.btnSetArea = new Asa.Theme.FlatButton();
this.btnClearArea = new Asa.Theme.FlatButton(); this.btnClearArea = new Asa.Theme.FlatButton();
this.panResult = new Asa.Theme.FlatPanel(); this.panResult = new Asa.Theme.FlatPanel();
...@@ -39,34 +37,16 @@ namespace AccAOI.control ...@@ -39,34 +37,16 @@ namespace AccAOI.control
this.panAreaSet = new Asa.Theme.FlatPanel(); this.panAreaSet = new Asa.Theme.FlatPanel();
this.panAreaImage = new Asa.Theme.FlatPanel(); this.panAreaImage = new Asa.Theme.FlatPanel();
this.panControl = new Asa.Theme.FlatPanel(); this.panControl = new Asa.Theme.FlatPanel();
this.btnImgType = new Asa.Theme.FlatButton();
this.aoiImage = new Cyotek.Windows.Forms.ImageBox();
this.panAreaSet.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// aoiImage
//
this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.aoiImage.Location = new System.Drawing.Point(9, 53);
this.aoiImage.Name = "aoiImage";
this.aoiImage.Size = new System.Drawing.Size(288, 182);
this.aoiImage.TabIndex = 2;
//
// btnYuan
//
this.btnYuan.ImageSize = new System.Drawing.Size(0, 0);
this.btnYuan.Inside = false;
this.btnYuan.Location = new System.Drawing.Point(108, 274);
this.btnYuan.Name = "btnYuan";
this.btnYuan.Size = new System.Drawing.Size(90, 30);
this.btnYuan.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnYuan.TabIndex = 8;
this.btnYuan.Text = "椭圆";
this.btnYuan.Click += new System.EventHandler(this.btnYuan_Click);
//
// btnSetArea // btnSetArea
// //
this.btnSetArea.ImageSize = new System.Drawing.Size(0, 0); this.btnSetArea.ImageSize = new System.Drawing.Size(0, 0);
this.btnSetArea.Inside = false; this.btnSetArea.Inside = false;
this.btnSetArea.Location = new System.Drawing.Point(12, 274); this.btnSetArea.Location = new System.Drawing.Point(104, 30);
this.btnSetArea.Name = "btnSetArea"; this.btnSetArea.Name = "btnSetArea";
this.btnSetArea.Size = new System.Drawing.Size(90, 30); this.btnSetArea.Size = new System.Drawing.Size(90, 30);
this.btnSetArea.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30))))); this.btnSetArea.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
...@@ -95,7 +75,7 @@ namespace AccAOI.control ...@@ -95,7 +75,7 @@ namespace AccAOI.control
this.panResult.Location = new System.Drawing.Point(4, 491); this.panResult.Location = new System.Drawing.Point(4, 491);
this.panResult.Name = "panResult"; this.panResult.Name = "panResult";
this.panResult.Padding = new System.Windows.Forms.Padding(6, 30, 6, 6); this.panResult.Padding = new System.Windows.Forms.Padding(6, 30, 6, 6);
this.panResult.Size = new System.Drawing.Size(298, 197); this.panResult.Size = new System.Drawing.Size(298, 330);
this.panResult.TabIndex = 5; this.panResult.TabIndex = 5;
this.panResult.Text = "结果判断"; this.panResult.Text = "结果判断";
// //
...@@ -115,6 +95,8 @@ namespace AccAOI.control ...@@ -115,6 +95,8 @@ namespace AccAOI.control
// //
this.panAreaSet.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) this.panAreaSet.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.panAreaSet.Controls.Add(this.btnImgType);
this.panAreaSet.Controls.Add(this.btnSetArea);
this.panAreaSet.Inside = false; this.panAreaSet.Inside = false;
this.panAreaSet.Location = new System.Drawing.Point(4, 244); this.panAreaSet.Location = new System.Drawing.Point(4, 244);
this.panAreaSet.Name = "panAreaSet"; this.panAreaSet.Name = "panAreaSet";
...@@ -144,18 +126,37 @@ namespace AccAOI.control ...@@ -144,18 +126,37 @@ namespace AccAOI.control
this.panControl.Location = new System.Drawing.Point(0, 0); this.panControl.Location = new System.Drawing.Point(0, 0);
this.panControl.Name = "panControl"; this.panControl.Name = "panControl";
this.panControl.Padding = new System.Windows.Forms.Padding(6, 30, 6, 6); this.panControl.Padding = new System.Windows.Forms.Padding(6, 30, 6, 6);
this.panControl.Size = new System.Drawing.Size(308, 696); this.panControl.Size = new System.Drawing.Size(309, 829);
this.panControl.TabIndex = 0; this.panControl.TabIndex = 0;
this.panControl.Text = "斑点分析"; this.panControl.Text = "斑点分析";
// //
// btnImgType
//
this.btnImgType.ImageSize = new System.Drawing.Size(0, 0);
this.btnImgType.Inside = false;
this.btnImgType.Location = new System.Drawing.Point(9, 30);
this.btnImgType.Name = "btnImgType";
this.btnImgType.Size = new System.Drawing.Size(90, 30);
this.btnImgType.StateColor = System.Drawing.Color.FromArgb(((int)(((byte)(30)))), ((int)(((byte)(30)))), ((int)(((byte)(30)))));
this.btnImgType.TabIndex = 8;
this.btnImgType.Text = "原图";
this.btnImgType.Click += new System.EventHandler(this.btnImgType_Click);
//
// aoiImage
//
this.aoiImage.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.aoiImage.Location = new System.Drawing.Point(9, 53);
this.aoiImage.Name = "aoiImage";
this.aoiImage.Size = new System.Drawing.Size(288, 182);
this.aoiImage.TabIndex = 2;
//
// ABaseControl // ABaseControl
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaptionText; this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
this.ClientSize = new System.Drawing.Size(312, 700); this.ClientSize = new System.Drawing.Size(312, 833);
this.Controls.Add(this.btnYuan);
this.Controls.Add(this.btnSetArea);
this.Controls.Add(this.btnClearArea); this.Controls.Add(this.btnClearArea);
this.Controls.Add(this.panResult); this.Controls.Add(this.panResult);
this.Controls.Add(this.panParam); this.Controls.Add(this.panParam);
...@@ -165,6 +166,7 @@ namespace AccAOI.control ...@@ -165,6 +166,7 @@ namespace AccAOI.control
this.Controls.Add(this.panControl); this.Controls.Add(this.panControl);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ABaseControl"; this.Name = "ABaseControl";
this.panAreaSet.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
...@@ -177,7 +179,7 @@ namespace AccAOI.control ...@@ -177,7 +179,7 @@ namespace AccAOI.control
protected Asa.Theme.FlatPanel panParam; protected Asa.Theme.FlatPanel panParam;
protected Asa.Theme.FlatPanel panResult; protected Asa.Theme.FlatPanel panResult;
public ImageBox aoiImage; public ImageBox aoiImage;
private Asa.Theme.FlatButton btnYuan; private Asa.Theme.FlatButton btnImgType;
public Asa.Theme.FlatPanel panControl; private Asa.Theme.FlatPanel panControl;
} }
} }
...@@ -24,35 +24,40 @@ namespace AccAOI.control ...@@ -24,35 +24,40 @@ namespace AccAOI.control
get { return panControl.Text; } get { return panControl.Text; }
set { panControl.Text = value; } set { panControl.Text = value; }
} }
protected object UpdateLock = "";
public Image GetImg() public Image GetImg()
{ {
if (this.Parent != null && this.Parent is FrmAoiSetting) return FrmAoiSetting.Img;
{
return ((FrmAoiSetting)this.Parent).Img;
}
return null;
} }
internal bool IsShowOk = false;
/// <summary> /// <summary>
/// 区域类型,1=矩形,2=圆形 /// 区域类型,1=矩形,2=圆形
/// </summary> /// </summary>
public int AreaType = 1; public int AreaType = 1;
/// <summary>
/// 显示的图片类型,1=原图,2=效果图
/// </summary>
public int ShowImageType = 2;
/// <summary> /// <summary>
/// 区域信息 /// 区域信息
/// </summary> /// </summary>
public GraphicsPath currPath = null; protected GraphicsPath currPath = null;
public ImageBox BImageBox; public ImageBox BImageBox;
public AoiMethod AoiInfo; public AoiMethod AoiInfo;
/// <summary> /// <summary>
/// 未处理的小图 /// 未处理的小图
/// </summary> /// </summary>
protected Image BaseImage = null; protected Image CutImage = null;
public void SetCurrPath(GraphicsPath path) public void SetCurrPath(GraphicsPath path, bool isUpdate = true)
{ {
this.currPath = path; this.currPath = path;
if (isUpdate)
{
UpdateImage(); UpdateImage();
}
} }
public virtual void UpdateImage() public virtual void UpdateImage()
...@@ -61,8 +66,9 @@ namespace AccAOI.control ...@@ -61,8 +66,9 @@ namespace AccAOI.control
} }
public virtual void ShowAoiInfo() public virtual void ShowAoiInfo()
{ {
IsShowOk = true;
}public virtual AoiMethod GetAoiInfo() }
public virtual AoiMethod GetAoiInfo()
{ {
return AoiInfo; return AoiInfo;
} }
...@@ -70,13 +76,13 @@ namespace AccAOI.control ...@@ -70,13 +76,13 @@ namespace AccAOI.control
private void btnSetArea_Click(object sender, EventArgs e) private void btnSetArea_Click(object sender, EventArgs e)
{ {
AreaType = 1; AreaType = 1;
panAreaSet.Text = "区域设置-矩形"; panAreaSet.Text = "区域设置 - 矩形";
} }
private void btnYuan_Click(object sender, EventArgs e) private void btnYuan_Click(object sender, EventArgs e)
{ {
AreaType = 2; AreaType = 2;
panAreaSet.Text = "区域设置-椭圆"; panAreaSet.Text = "区域设置 - 椭圆";
} }
private void btnClearArea_Click(object sender, EventArgs e) private void btnClearArea_Click(object sender, EventArgs e)
...@@ -85,5 +91,21 @@ namespace AccAOI.control ...@@ -85,5 +91,21 @@ namespace AccAOI.control
this.aoiImage.Image = null; this.aoiImage.Image = null;
} }
private void btnImgType_Click(object sender, EventArgs e)
{
if (btnImgType.Text.Equals("原图")) {
ShowImageType = 1;
btnImgType.Text = "效果图";
panAreaImage.Text = "区域图 - 原图";
}
else
{
ShowImageType = 2;
btnImgType.Text = "原图";
panAreaImage.Text = "区域图像 - 效果图";
}
UpdateImage();
}
} }
} }
...@@ -126,6 +126,7 @@ ...@@ -126,6 +126,7 @@
this.txtminArea.Padding = new System.Windows.Forms.Padding(3); this.txtminArea.Padding = new System.Windows.Forms.Padding(3);
this.txtminArea.Size = new System.Drawing.Size(74, 30); this.txtminArea.Size = new System.Drawing.Size(74, 30);
this.txtminArea.TabIndex = 17; this.txtminArea.TabIndex = 17;
this.txtminArea.Text = "0";
// //
// txtmaxArea // txtmaxArea
// //
...@@ -136,6 +137,7 @@ ...@@ -136,6 +137,7 @@
this.txtmaxArea.Padding = new System.Windows.Forms.Padding(3); this.txtmaxArea.Padding = new System.Windows.Forms.Padding(3);
this.txtmaxArea.Size = new System.Drawing.Size(74, 30); this.txtmaxArea.Size = new System.Drawing.Size(74, 30);
this.txtmaxArea.TabIndex = 18; this.txtmaxArea.TabIndex = 18;
this.txtmaxArea.Text = "-1";
// //
// flatLabel5 // flatLabel5
// //
...@@ -164,6 +166,7 @@ ...@@ -164,6 +166,7 @@
this.txtmaxNum.Padding = new System.Windows.Forms.Padding(3); this.txtmaxNum.Padding = new System.Windows.Forms.Padding(3);
this.txtmaxNum.Size = new System.Drawing.Size(74, 30); this.txtmaxNum.Size = new System.Drawing.Size(74, 30);
this.txtmaxNum.TabIndex = 22; this.txtmaxNum.TabIndex = 22;
this.txtmaxNum.Text = "-1";
// //
// txtminNum // txtminNum
// //
...@@ -174,6 +177,7 @@ ...@@ -174,6 +177,7 @@
this.txtminNum.Padding = new System.Windows.Forms.Padding(3); this.txtminNum.Padding = new System.Windows.Forms.Padding(3);
this.txtminNum.Size = new System.Drawing.Size(74, 30); this.txtminNum.Size = new System.Drawing.Size(74, 30);
this.txtminNum.TabIndex = 21; this.txtminNum.TabIndex = 21;
this.txtminNum.Text = "0";
// //
// flatLabel6 // flatLabel6
// //
......
...@@ -9,6 +9,7 @@ using System.Threading.Tasks; ...@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using AOI; using AOI;
using OpenCvSharp.Blob; using OpenCvSharp.Blob;
using System.Threading;
namespace AccAOI.control namespace AccAOI.control
{ {
...@@ -45,6 +46,9 @@ namespace AccAOI.control ...@@ -45,6 +46,9 @@ namespace AccAOI.control
txtminArea.Text = MethodBlob.minArea.ToString(); txtminArea.Text = MethodBlob.minArea.ToString();
txtmaxNum.Text = MethodBlob.maxNum.ToString(); txtmaxNum.Text = MethodBlob.maxNum.ToString();
txtminNum.Text = MethodBlob.minNum.ToString(); txtminNum.Text = MethodBlob.minNum.ToString();
IsShowOk = true;
UpdateImage();
} }
} }
...@@ -77,17 +81,53 @@ namespace AccAOI.control ...@@ -77,17 +81,53 @@ namespace AccAOI.control
} }
public override void UpdateImage() public override void UpdateImage()
{ {
if (BaseImage == null) if (!IsShowOk)
{
return;
}
if (Monitor.TryEnter(UpdateLock))
{
try
{
Image BaseImage = GetImg();
if (BaseImage == null || currPath == null)
{ {
return; return;
} }
GetAoiInfo(); GetAoiInfo();
Image outImage = null; Image cutImage, dstCutImage = null;
List<CvBlob> list = new List<CvBlob>(); List<CvBlob> list = new List<CvBlob>();
float result = MethodBlob.GetBlobNum(BaseImage, out outImage, out list); float result = MethodBlob.GetBlobNum(BaseImage, out cutImage, out dstCutImage, out list);
if (cutImage != null && dstCutImage != null)
{
txtNumResult.Text = result.ToString(); txtNumResult.Text = result.ToString();
this.aoiImage.Image = outImage; if (ShowImageType.Equals(1))
{
this.aoiImage.Image = cutImage;
this.CutImage = dstCutImage;
}
else
{
this.aoiImage.Image = dstCutImage;
this.CutImage = cutImage;
}
}
GC.Collect();
}
catch (Exception ex)
{
Console.WriteLine("UpdateImage出错:" + ex.ToString());
}
finally
{
Monitor.Exit(UpdateLock);
}
}
else
{
Console.WriteLine("UpdateImage执行失败,未得到锁");
}
} }
private void btnUpdate_Click(object sender, EventArgs e) private void btnUpdate_Click(object sender, EventArgs e)
......
...@@ -88,11 +88,6 @@ ...@@ -88,11 +88,6 @@
this.panResult.Location = new System.Drawing.Point(4, 688); this.panResult.Location = new System.Drawing.Point(4, 688);
this.panResult.Size = new System.Drawing.Size(298, 131); this.panResult.Size = new System.Drawing.Size(298, 131);
// //
// panControl
//
this.panControl.Size = new System.Drawing.Size(308, 826);
this.panControl.Text = "颜色抽取";
//
// flatLabel5 // flatLabel5
// //
this.flatLabel5.Inside = false; this.flatLabel5.Inside = false;
...@@ -149,6 +144,7 @@ ...@@ -149,6 +144,7 @@
this.txtMaxR.Padding = new System.Windows.Forms.Padding(3); this.txtMaxR.Padding = new System.Windows.Forms.Padding(3);
this.txtMaxR.Size = new System.Drawing.Size(74, 30); this.txtMaxR.Size = new System.Drawing.Size(74, 30);
this.txtMaxR.TabIndex = 26; this.txtMaxR.TabIndex = 26;
this.txtMaxR.Text = "255";
this.txtMaxR.TextChanged += new System.EventHandler(this.txtMinR_TextChanged); this.txtMaxR.TextChanged += new System.EventHandler(this.txtMinR_TextChanged);
// //
// txtMinR // txtMinR
...@@ -160,6 +156,7 @@ ...@@ -160,6 +156,7 @@
this.txtMinR.Padding = new System.Windows.Forms.Padding(3); this.txtMinR.Padding = new System.Windows.Forms.Padding(3);
this.txtMinR.Size = new System.Drawing.Size(74, 30); this.txtMinR.Size = new System.Drawing.Size(74, 30);
this.txtMinR.TabIndex = 25; this.txtMinR.TabIndex = 25;
this.txtMinR.Text = "0";
this.txtMinR.TextChanged += new System.EventHandler(this.txtMinR_TextChanged); this.txtMinR.TextChanged += new System.EventHandler(this.txtMinR_TextChanged);
// //
// flatLabel2 // flatLabel2
...@@ -189,6 +186,7 @@ ...@@ -189,6 +186,7 @@
this.txtMaxG.Padding = new System.Windows.Forms.Padding(3); this.txtMaxG.Padding = new System.Windows.Forms.Padding(3);
this.txtMaxG.Size = new System.Drawing.Size(74, 30); this.txtMaxG.Size = new System.Drawing.Size(74, 30);
this.txtMaxG.TabIndex = 30; this.txtMaxG.TabIndex = 30;
this.txtMaxG.Text = "255";
this.txtMaxG.TextChanged += new System.EventHandler(this.txtMinR_TextChanged); this.txtMaxG.TextChanged += new System.EventHandler(this.txtMinR_TextChanged);
// //
// txtMinG // txtMinG
...@@ -200,6 +198,7 @@ ...@@ -200,6 +198,7 @@
this.txtMinG.Padding = new System.Windows.Forms.Padding(3); this.txtMinG.Padding = new System.Windows.Forms.Padding(3);
this.txtMinG.Size = new System.Drawing.Size(74, 30); this.txtMinG.Size = new System.Drawing.Size(74, 30);
this.txtMinG.TabIndex = 29; this.txtMinG.TabIndex = 29;
this.txtMinG.Text = "0";
this.txtMinG.TextChanged += new System.EventHandler(this.txtMinR_TextChanged); this.txtMinG.TextChanged += new System.EventHandler(this.txtMinR_TextChanged);
// //
// flatLabel6 // flatLabel6
...@@ -230,6 +229,7 @@ ...@@ -230,6 +229,7 @@
this.txtMaxB.Padding = new System.Windows.Forms.Padding(3); this.txtMaxB.Padding = new System.Windows.Forms.Padding(3);
this.txtMaxB.Size = new System.Drawing.Size(74, 30); this.txtMaxB.Size = new System.Drawing.Size(74, 30);
this.txtMaxB.TabIndex = 34; this.txtMaxB.TabIndex = 34;
this.txtMaxB.Text = "255";
this.txtMaxB.TextChanged += new System.EventHandler(this.txtMinR_TextChanged); this.txtMaxB.TextChanged += new System.EventHandler(this.txtMinR_TextChanged);
// //
// txtMinB // txtMinB
...@@ -241,6 +241,7 @@ ...@@ -241,6 +241,7 @@
this.txtMinB.Padding = new System.Windows.Forms.Padding(3); this.txtMinB.Padding = new System.Windows.Forms.Padding(3);
this.txtMinB.Size = new System.Drawing.Size(74, 30); this.txtMinB.Size = new System.Drawing.Size(74, 30);
this.txtMinB.TabIndex = 33; this.txtMinB.TabIndex = 33;
this.txtMinB.Text = "0";
this.txtMinB.TextChanged += new System.EventHandler(this.txtMinR_TextChanged); this.txtMinB.TextChanged += new System.EventHandler(this.txtMinR_TextChanged);
// //
// flatLabel8 // flatLabel8
...@@ -368,7 +369,6 @@ ...@@ -368,7 +369,6 @@
this.Controls.Add(this.flatLabel3); this.Controls.Add(this.flatLabel3);
this.Name = "AoiRgbControl"; this.Name = "AoiRgbControl";
this.TitleName = "颜色抽取"; this.TitleName = "颜色抽取";
this.Controls.SetChildIndex(this.panControl, 0);
this.Controls.SetChildIndex(this.aoiImage, 0); this.Controls.SetChildIndex(this.aoiImage, 0);
this.Controls.SetChildIndex(this.panParam, 0); this.Controls.SetChildIndex(this.panParam, 0);
this.Controls.SetChildIndex(this.panResult, 0); this.Controls.SetChildIndex(this.panResult, 0);
......
...@@ -9,6 +9,7 @@ using System.Threading.Tasks; ...@@ -9,6 +9,7 @@ using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using AOI; using AOI;
using Asa.Theme; using Asa.Theme;
using System.Threading;
namespace AccAOI.control namespace AccAOI.control
{ {
...@@ -24,12 +25,12 @@ namespace AccAOI.control ...@@ -24,12 +25,12 @@ namespace AccAOI.control
if (this.AoiInfo is AoiMethodRgb) if (this.AoiInfo is AoiMethodRgb)
{ {
methodRgb = (AoiMethodRgb)AoiInfo; methodRgb = (AoiMethodRgb)AoiInfo;
//txtMinR.Text = methodRgb.minR.ToString(); txtMinR.Text = methodRgb.minR.ToString();
//txtMaxR.Text = methodRgb.maxR.ToString(); txtMaxR.Text = methodRgb.maxR.ToString();
//txtMinG.Text = methodRgb.minG.ToString(); txtMinG.Text = methodRgb.minG.ToString();
// txtMaxG.Text = methodRgb.maxG.ToString(); txtMaxG.Text = methodRgb.maxG.ToString();
// txtMaxB.Text = methodRgb.maxB.ToString(); txtMaxB.Text = methodRgb.maxB.ToString();
// txtMinB.Text = methodRgb.minB.ToString(); txtMinB.Text = methodRgb.minB.ToString();
SetTbValue(tbMinR, methodRgb.minR); SetTbValue(tbMinR, methodRgb.minR);
SetTbValue(tbMaxR, methodRgb.maxR); SetTbValue(tbMaxR, methodRgb.maxR);
SetTbValue(tbMinG, methodRgb.minG); SetTbValue(tbMinG, methodRgb.minG);
...@@ -38,6 +39,9 @@ namespace AccAOI.control ...@@ -38,6 +39,9 @@ namespace AccAOI.control
SetTbValue(tbMinB, methodRgb.minB); SetTbValue(tbMinB, methodRgb.minB);
txtminRate.Text = methodRgb.minRate.ToString(); txtminRate.Text = methodRgb.minRate.ToString();
txtmaxRate.Text = methodRgb.maxRate.ToString(); txtmaxRate.Text = methodRgb.maxRate.ToString();
IsShowOk = true;
UpdateImage();
} }
} }
...@@ -74,7 +78,16 @@ namespace AccAOI.control ...@@ -74,7 +78,16 @@ namespace AccAOI.control
public override void UpdateImage() public override void UpdateImage()
{ {
if (BaseImage == null) if (!IsShowOk)
{
return;
}
if (Monitor.TryEnter(UpdateLock))
{
try
{
Image BaseImage = GetImg();
if (BaseImage == null || currPath == null)
{ {
return; return;
} }
...@@ -82,9 +95,37 @@ namespace AccAOI.control ...@@ -82,9 +95,37 @@ namespace AccAOI.control
Image cutImg = null; Image cutImg = null;
Image dstCutImg = null; Image dstCutImg = null;
float rate = methodRgb.GetRate(BaseImage, out cutImg, out dstCutImg); float rate = methodRgb.GetRate(BaseImage, out cutImg, out dstCutImg);
if (cutImg != null && dstCutImg != null)
{
txtRate.Text = rate.ToString(); txtRate.Text = rate.ToString();
if (ShowImageType.Equals(1))
{
this.aoiImage.Image = cutImg; this.aoiImage.Image = cutImg;
this.CutImage = dstCutImg;
}
else
{
this.aoiImage.Image = dstCutImg;
this.CutImage = cutImg;
}
}
GC.Collect();
}
catch (Exception ex)
{
Console.WriteLine("UpdateImage出错:" + ex.ToString());
}
finally
{
Monitor.Exit(UpdateLock);
}
}
else
{
Console.WriteLine("UpdateImage执行失败,未得到锁");
}
} }
private void btnUpdate_Click(object sender, EventArgs e) private void btnUpdate_Click(object sender, EventArgs e)
...@@ -134,6 +175,7 @@ namespace AccAOI.control ...@@ -134,6 +175,7 @@ namespace AccAOI.control
return; return;
} }
text.Text = value.ToString(); text.Text = value.ToString();
UpdateImage();
} }
private void SetTbValue(TrackBar tb, int value) private void SetTbValue(TrackBar tb, int value)
{ {
...@@ -141,7 +183,16 @@ namespace AccAOI.control ...@@ -141,7 +183,16 @@ namespace AccAOI.control
{ {
return; return;
} }
if (value < tb.Minimum)
{
tb.Value = tb.Minimum;
}else if (value > tb.Maximum)
{
tb.Value = tb.Maximum;
}else
{
tb.Value = value; tb.Value = value;
} }
} }
}
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!