Commit e104a243 LN

AOI检测增加修正功能。

1 个父辈 a852911b
......@@ -50,6 +50,7 @@ namespace TSA_V
this.picCurr = new System.Windows.Forms.PictureBox();
this.label1 = new System.Windows.Forms.Label();
this.picStand = new System.Windows.Forms.PictureBox();
this.btnUpdateImg = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.panel4.SuspendLayout();
this.panel2.SuspendLayout();
......@@ -194,6 +195,7 @@ namespace TSA_V
//
this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel3.Controls.Add(this.btnUpdateImg);
this.panel3.Controls.Add(this.listErrorView);
this.panel3.Controls.Add(this.chbAllShow);
this.panel3.Controls.Add(this.label2);
......@@ -212,10 +214,10 @@ namespace TSA_V
| System.Windows.Forms.AnchorStyles.Right)));
this.listErrorView.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listErrorView.HideSelection = false;
this.listErrorView.Location = new System.Drawing.Point(3, 33);
this.listErrorView.Location = new System.Drawing.Point(3, 45);
this.listErrorView.MultiSelect = false;
this.listErrorView.Name = "listErrorView";
this.listErrorView.Size = new System.Drawing.Size(325, 253);
this.listErrorView.Size = new System.Drawing.Size(325, 241);
this.listErrorView.TabIndex = 299;
this.listErrorView.UseCompatibleStateImageBehavior = false;
this.listErrorView.View = System.Windows.Forms.View.List;
......@@ -275,6 +277,20 @@ namespace TSA_V
this.picStand.TabIndex = 297;
this.picStand.TabStop = false;
//
// btnUpdateImg
//
this.btnUpdateImg.BackColor = System.Drawing.SystemColors.Control;
this.btnUpdateImg.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnUpdateImg.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnUpdateImg.Location = new System.Drawing.Point(198, 3);
this.btnUpdateImg.Name = "btnUpdateImg";
this.btnUpdateImg.Size = new System.Drawing.Size(130, 40);
this.btnUpdateImg.TabIndex = 303;
this.btnUpdateImg.Text = "修正";
this.btnUpdateImg.UseVisualStyleBackColor = false;
this.btnUpdateImg.Visible = false;
this.btnUpdateImg.Click += new System.EventHandler(this.btnUpdateImg_Click);
//
// FrmAOICheck
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
......@@ -319,5 +335,6 @@ namespace TSA_V
private AccImageBox picResult;
private System.Windows.Forms.CheckBox chbAllShow;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.Button btnUpdateImg;
}
}
\ No newline at end of file
......@@ -13,6 +13,8 @@ using System.Windows.Forms;
using TSA_V.Common;
using TSA_V.DeviceLibrary;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.Serialization.Formatters.Binary;
namespace TSA_V
{
......@@ -23,6 +25,7 @@ namespace TSA_V
private DateTime showTime = DateTime.Now;
private DateTime endTime = DateTime.Now;
private bool IsCheck = false;
private bool IsUpdate = false;
/// <summary>
/// 检测结果,0=未知,1=OK,2=NG
/// </summary>
......@@ -32,10 +35,13 @@ namespace TSA_V
{
InitializeComponent();
CurrProject = currAoi;
updateMName = new List<string>();
}
private void FrmCamera_Load(object sender, EventArgs e)
{
FormStatus(false);
btnUpdateImg.Visible = false;
timer1.Start();
lblCurrWorkTime.Visible = true;
//默认显示程序配置的 图片
......@@ -73,7 +79,14 @@ namespace TSA_V
}
private void timer1_Tick(object sender, EventArgs e)
{
if (IsUpdate)
{
}
else
{
btnRun.Visible = !IsCheck;
}
TimeSpan span = DateTime.Now - showTime;
if (!IsCheck)
......@@ -153,6 +166,18 @@ namespace TSA_V
camera = AccAOI.camera.CameraManager.hikNameList.ToArray().FirstOrDefault();
}
Image currImage = CameraManager.GetCamerImage(camera);
if (currImage == null)
{
string file = @"G:\test.bmp";
if (File.Exists(file))
{
//从本地加载图片
Bitmap aa = new Bitmap(file);
currImage = DeepClone(aa);
}
}
if (currImage != null)
{
//Bitmap bitmap = new Bitmap(currImage);
......@@ -169,6 +194,10 @@ namespace TSA_V
// pictureBox1.Image = outImage;
}
else
{
this.picResult.Image = currImage;
}
result = 1;
endTime = DateTime.Now;
string ngList = "NG:\r\n";
......@@ -264,7 +293,7 @@ namespace TSA_V
timer1.Stop();
this.Close();
}
private ResultBean selectResultBean = null;
private void listErrorView_SelectedIndexChanged(object sender, EventArgs e)
{
if (listErrorView.SelectedItems != null && listErrorView.SelectedItems.Count > 0)
......@@ -275,9 +304,19 @@ namespace TSA_V
{
ResultBean bean = beans[0];
picStand.Image = bean.standardRoiImage;
picCurr.Image = bean.currentRoiImage;
picCurr.Image =DeepClone( bean.currentRoiImage);
picResult.SelectionRegion = bean.roiPath;
//如果结果NG,可以修正
if(!bean.result && (!updateMName.Contains(bean.MethodName)))
{
selectResultBean = bean;
btnUpdateImg.Visible = true;
}
else
{
btnUpdateImg.Visible = false;
}
//Graphics g = picResult.CreateGraphics();
//g.DrawPath(new Pen(Color.Orange), bean.roiPath);
//g.Dispose();
......@@ -309,5 +348,87 @@ namespace TSA_V
}
listErrorView_SelectedIndexChanged(null, null);
}
private string getSaveImagePath(string aoiFileName, ResultBean selectResultBean)
{
string path = Path.GetDirectoryName(aoiFileName);
string fileName = Path.GetFileNameWithoutExtension(aoiFileName);
System.Drawing.PointF[] pts = selectResultBean.roiPath.PathPoints;
string pPath = "";
for (int i = 0; i < pts.Length; i++)
{
pPath += (int)pts[i].X + "-" + (int)pts[i].Y + "_";
}
return Path.Combine(path, fileName + @"\" + pPath + @"\");
}
private List<string> updateMName = new List<string>();
private void btnUpdateImg_Click(object sender, EventArgs e)
{
if (selectResultBean == null)
{
return;
}
if (picCurr.Image == null)
{
return;
}
try
{
DialogResult result = MessageBox.Show(ResourceCulture.GetString("SureUpdateMethod", "确定修正{0}?",
new string[] { selectResultBean.MethodName }), ResourceCulture.GetString("提示"),
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if(result != DialogResult.Yes)
{
return;
}
using (Image image = DeepClone(selectResultBean.currentRoiImage))
{
string savePath = getSaveImagePath(BoardManager.CurrBoard.GetAoiFileName(), selectResultBean);
if (!Directory.Exists(savePath))
{
Directory .CreateDirectory(savePath);
}
string imageName = DateTime.Now.ToString("yy-MM-dd-HH-mm-ss-") + DateTime.Now.Millisecond + ".bmp";
image.Save(savePath + imageName, ImageFormat.Bmp);
IsUpdate = true;
btnRun.Visible = true;
btnUpdateImg.Visible = false;
updateMName.Add(selectResultBean.MethodName);
LogUtil.info($" {BoardManager.CurrBoard} 修正 {selectResultBean.MethodName} 成功,图片保存到:" + savePath + imageName);
}
}
catch (Exception ex)
{
LogUtil.error($" {BoardManager.CurrBoard} 修正 {selectResultBean.MethodName}出错:" + ex.ToString());
}
}
[HandleProcessCorruptedStateExceptions]
public static T DeepClone<T>(T _object)
{
try
{
T dstobject;
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, _object);
mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
dstobject = (T)bf.Deserialize(mStream);
mStream.Close();
}
return dstobject;
}
catch (Exception e)
{
LogUtil.info("GetStringCenterA" + e.ToString());
return default;
}
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!