1、所有工具参数以Job分隔进行保存到本地

2、PMA工具修改
This commit is contained in:
liu.wenjie
2022-05-11 08:21:47 +08:00
parent 9dcba19b67
commit 900ea68f69
15 changed files with 71 additions and 97 deletions

Binary file not shown.

View File

@@ -29,7 +29,8 @@ namespace CommonMethods
/// <summary>
/// 工具窗体,由于无法对Form进行序列化所以作为静态变量
/// </summary>
public static Form FormTool { get; set; }
[NonSerialized]
public Form FormTool = new Form();
/// <summary>
/// 工具窗体名
/// </summary>
@@ -54,11 +55,16 @@ namespace CommonMethods
/// 工具运行结果
/// </summary>
public ToolRunStatu toolRunStatu { get; set; }
/// <summary>
/// 绑定的JOB名称
/// </summary>
public string bingingJobName { get; set; }
public IToolInfo()
{
enable = true;
toolType = ToolType.None;
toolName = string.Empty;
bingingJobName = string.Empty;
tool = new object();
toolInput = new List<ToolIO>();
toolOutput = new List<ToolIO>();

14
DataStruct/ConfigData.cs Normal file
View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataStruct
{
[Serializable]
public class ConfigData
{
public static string ConfigPath { get; set; } = @"D:\VisionSystem\";
}
}

View File

@@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigData.cs" />
<Compile Include="DataStruct.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

View File

@@ -87,8 +87,14 @@ namespace FindLineTool
chBDispRec.Checked = myFindLine.dispRec;
chBDispCross.Checked = myFindLine.dispCross;
//// 将要编辑的线显示
selected_drawing_object = myFindLine.inputPoseHomMat2D.Length != 0? HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, new HTuple[] { myFindLine.newExpectLineStartRow, myFindLine.newExpectLineStartCol, myFindLine.newExpectLineEndRow, myFindLine.newExpectLineEndCol })
:HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, new HTuple[] {myFindLine.modelStartRow, myFindLine.modelStartCol, myFindLine.modelEndRow, myFindLine.modelEndCol });
if(myFindLine.inputPoseHomMat2D.Type != HTupleType.EMPTY)
{
selected_drawing_object = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, new HTuple[] { myFindLine.newExpectLineStartRow, myFindLine.newExpectLineStartCol, myFindLine.newExpectLineEndRow, myFindLine.newExpectLineEndCol });
}
else
{
selected_drawing_object = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, new HTuple[] { myFindLine.modelStartRow, myFindLine.modelStartCol, myFindLine.modelEndRow, myFindLine.modelEndCol });
}
GC.KeepAlive(selected_drawing_object);
selected_drawing_object.OnSelect(OnSelectDrawingObject);
selected_drawing_object.OnAttach(OnSelectDrawingObject);

View File

@@ -76,7 +76,8 @@ namespace HalconTool
/// <summary>
/// 输出图像
/// </summary>
public HObject outputImage = null;
[NonSerialized]
public HObject outputImage = new HObject();
/// <summary>
/// 输出图像的路径
/// </summary>
@@ -98,7 +99,7 @@ namespace HalconTool
}
else
{
if (currentImageIndex <= L_imageFile.Count)
if (currentImageIndex <= L_imageFile.Count && L_imageFile.Count != 0)
{
currentImageIndex = currentImageIndex == L_imageFile.Count ? 0 : currentImageIndex;
outputImageFilePath = L_imageFile[currentImageIndex];

View File

@@ -29,10 +29,6 @@ namespace PMAlignTool
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPMAlignTool));
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle();
this.statusStrip = new System.Windows.Forms.StatusStrip();
this.lb_RunStatus = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
@@ -123,7 +119,7 @@ namespace PMAlignTool
this.ckb_showFeature = new System.Windows.Forms.CheckBox();
this.ckb_showCross = new System.Windows.Forms.CheckBox();
this.tabPage3 = new System.Windows.Forms.TabPage();
this.dgv_matchResult = new Sunny.UI.UIDataGridView();
this.dgv_matchResult = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -1550,21 +1546,7 @@ namespace PMAlignTool
//
// dgv_matchResult
//
dataGridViewCellStyle1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
this.dgv_matchResult.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
this.dgv_matchResult.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;
this.dgv_matchResult.BackgroundColor = System.Drawing.Color.White;
this.dgv_matchResult.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle2.ForeColor = System.Drawing.Color.White;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dgv_matchResult.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2;
this.dgv_matchResult.ColumnHeadersHeight = 32;
this.dgv_matchResult.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
this.dgv_matchResult.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgv_matchResult.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
@@ -1572,62 +1554,36 @@ namespace PMAlignTool
this.Column4,
this.Column5});
this.dgv_matchResult.Dock = System.Windows.Forms.DockStyle.Fill;
this.dgv_matchResult.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnEnter;
this.dgv_matchResult.EnableHeadersVisualStyles = false;
this.dgv_matchResult.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.dgv_matchResult.GridColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
this.dgv_matchResult.Location = new System.Drawing.Point(0, 0);
this.dgv_matchResult.Name = "dgv_matchResult";
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle3.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255)))));
dataGridViewCellStyle3.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle3.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(48)))), ((int)(((byte)(48)))), ((int)(((byte)(48)))));
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(80)))), ((int)(((byte)(160)))), ((int)(((byte)(255)))));
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.Color.White;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dgv_matchResult.RowHeadersDefaultCellStyle = dataGridViewCellStyle3;
this.dgv_matchResult.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader;
dataGridViewCellStyle4.BackColor = System.Drawing.Color.White;
this.dgv_matchResult.RowsDefaultCellStyle = dataGridViewCellStyle4;
this.dgv_matchResult.RowTemplate.Height = 23;
this.dgv_matchResult.SelectedIndex = -1;
this.dgv_matchResult.ShowGridLine = true;
this.dgv_matchResult.Size = new System.Drawing.Size(392, 568);
this.dgv_matchResult.TabIndex = 0;
//
// Column1
//
this.Column1.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
this.Column1.HeaderText = "编号";
this.Column1.HeaderText = "序号";
this.Column1.Name = "Column1";
this.Column1.Width = 66;
//
// Column2
//
this.Column2.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.Column2.HeaderText = "分值";
this.Column2.Name = "Column2";
//
// Column3
//
this.Column3.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
this.Column3.HeaderText = "行";
this.Column3.Name = "Column3";
this.Column3.Width = 50;
//
// Column4
//
this.Column4.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
this.Column4.HeaderText = "列";
this.Column4.Name = "Column4";
this.Column4.Width = 50;
//
// Column5
//
this.Column5.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.ColumnHeader;
this.Column5.HeaderText = "角度";
this.Column5.Name = "Column5";
this.Column5.Width = 66;
//
// FormPMAlignTool
//
@@ -1788,6 +1744,6 @@ namespace PMAlignTool
private System.Windows.Forms.DataGridViewTextBoxColumn Column3;
private System.Windows.Forms.DataGridViewTextBoxColumn Column4;
private System.Windows.Forms.DataGridViewTextBoxColumn Column5;
public Sunny.UI.UIDataGridView dgv_matchResult;
public System.Windows.Forms.DataGridView dgv_matchResult;
}
}

View File

@@ -33,7 +33,8 @@ namespace PMAlignTool
{
myToolInfo = (IToolInfo)pmalign;
myPMAlign = (PMAlign)myToolInfo.tool;
myPMAlign.toolName = myToolInfo.FormToolName;
myPMAlign.toolName = myToolInfo.toolName;
myPMAlign.bingdingJobName = myToolInfo.bingingJobName;
myPMAlign.DispImage();
}
}

View File

@@ -25,12 +25,20 @@ using Logger;
using System.Diagnostics;
using System.IO;
using ViewROI;
using DataStruct;
namespace PMAlignTool
{
[Serializable]
public class PMAlign : IToolBase
{
/// <summary>
/// 绑定job名称
/// </summary>
public string bingdingJobName { get; set; }
/// <summary>
/// 工具名称
/// </summary>
public string toolName { get; set; } = string.Empty;
/// <summary>
/// 输入姿态
@@ -115,12 +123,14 @@ namespace PMAlignTool
/// <summary>
/// 训练时所使用的模板图像,不点击获取图像时,不进行更新
/// </summary>
public HObject oldTrainImage { get; set; }
[NonSerialized]
public HObject oldTrainImage;
public bool isCreateModel { get; set; }
internal string pmaModelName { get; set; } = Guid.NewGuid().ToString();
/// <summary>
/// 剪出的模板图像
/// </summary>
[NonSerialized]
public HObject modelPartImage = new HObject();
/// <summary>
/// 模板位置和实际位置的姿态差异
@@ -163,7 +173,8 @@ namespace PMAlignTool
public bool isAutoConstants { get; set; }
public string modelFilePath { get; set; }
public RegionType searchRegionType { get; set; }
public HObject SearchRegion { get; set; }
[NonSerialized]
public HObject SearchRegion;
public override void Run(SoftwareRunState softwareState)
{
Stopwatch sw = new Stopwatch();
@@ -195,7 +206,6 @@ namespace PMAlignTool
//对预期线的找模板区域做放射变换
}
// UpdateParamsFromUI(); // 操作前先将UI中参数写入类
HObject findModelImg = ProcessImage(inputImage);
int ret = FindModelTemplate(findModelImg);
UpdateResultDataGridview();
@@ -220,10 +230,16 @@ namespace PMAlignTool
public void UpdateResultDataGridview()
{
FormPMAlignTool.Instance.dgv_matchResult.Rows.Clear();
//FormPMAlignTool.Instance.dgv_matchResult.Columns.Clear();
//FormPMAlignTool.Instance.dgv_matchResult.Columns.Add("num", "序号");
//FormPMAlignTool.Instance.dgv_matchResult.Columns.Add("Socre", "分值");
//FormPMAlignTool.Instance.dgv_matchResult.Columns.Add("Row", "行");
//FormPMAlignTool.Instance.dgv_matchResult.Columns.Add("Col", "列");
//FormPMAlignTool.Instance.dgv_matchResult.Columns.Add("Angle", "角度");
int count = 0;
foreach (var item in L_resultList)
{
FormPMAlignTool.Instance.dgv_matchResult.AddRow(++count, item.Socre, item.Row, item.Col, item.Angle);
FormPMAlignTool.Instance.dgv_matchResult.Rows.Add(++count, item.Socre, item.Row, item.Col, item.Angle);
}
}
@@ -355,8 +371,9 @@ namespace PMAlignTool
out scores);
}
isCreateModel = true;
HOperatorSet.WriteRegion(templateRegion, FormPMAlignTool.Instance.myToolInfo.FormToolName + ".hobj");
HOperatorSet.WriteShapeModel(modelID, pmaModelName + ".ShapeModel");
// 模板句柄信息
Directory.CreateDirectory(ConfigData.ConfigPath + $"\\{bingdingJobName}\\");
HOperatorSet.WriteShapeModel(modelID, ConfigData.ConfigPath + $"\\{bingdingJobName}\\{toolName}_{pmaModelName}.Shm");
if (scores != null && scores.Type != HTupleType.EMPTY)
{
@@ -380,12 +397,12 @@ namespace PMAlignTool
public int FindModelTemplate(HObject findModelImage)
{
if (!File.Exists(pmaModelName + ".ShapeModel"))
if (!File.Exists(ConfigData.ConfigPath + $"\\{bingdingJobName}\\{toolName}_{pmaModelName}.Shm"))
{
LoggerClass.WriteLog($"{toolName}未创建或加载模板", MsgLevel.Exception);
return -1;
}
HOperatorSet.ReadShapeModel(pmaModelName + ".ShapeModel", out modelID);
HOperatorSet.ReadShapeModel(ConfigData.ConfigPath + $"\\{bingdingJobName}\\{toolName}_{pmaModelName}.Shm", out modelID);
HObject image;
if (searchRegionType == RegionType.AllImage)
{

View File

@@ -64,7 +64,6 @@ namespace ToolLib.VisionJob
{
VisionJobParams.pVisionProject.Project.Add(jobName, new VisionJob(jobName));
FormJobManage.Instance.tabJobUnion.SelectedTab = newTab;
// newTab.Select();
}
InitJob(VisionJobParams.pVisionProject.Project[jobName]);
}
@@ -219,12 +218,12 @@ namespace ToolLib.VisionJob
string AssemblyName = VisionJobParams.pVisionProject.Project[jobName].L_toolList[i].FormToolName.Split('.')[0];
string className = VisionJobParams.pVisionProject.Project[jobName].L_toolList[i].FormToolName;
toolClass = VisionJobParams.pVisionProject.Project[jobName].L_toolList[i];
IToolInfo.FormTool = (Form)Assembly.Load(AssemblyName).CreateInstance(className, false, BindingFlags.Default, null, new object[] { toolClass }, null, null);
IToolInfo.FormTool.ShowDialog();
//VisionJobParams.myProject[jobName].L_toolList[i].SetFormTool(IToolInfo.FormTool);
//VisionJobParams.myProject[jobName].L_toolList[i].GetFormTool().ShowDialog();
//VisionJobParams.myProject[jobName].L_toolList[i].FormTool = (Form)Assembly.Load(AssemblyName).CreateInstance(className, false, BindingFlags.Default, null, new object[] { toolClass }, null, null);
//VisionJobParams.myProject[jobName].L_toolList[i].FormTool.ShowDialog();
VisionJobParams.pVisionProject.Project[jobName].L_toolList[i].bingingJobName = jobName;
//IToolInfo.FormTool = (Form)Assembly.Load(AssemblyName).CreateInstance(className, false, BindingFlags.Default, null, new object[] { toolClass }, null, null);
//IToolInfo.FormTool.ShowDialog();
VisionJobParams.pVisionProject.Project[jobName].L_toolList[i].FormTool = (Form)Assembly.Load(AssemblyName).CreateInstance(className, false, BindingFlags.Default, null, new object[] { toolClass }, null, null);
VisionJobParams.pVisionProject.Project[jobName].L_toolList[i].FormTool.Show();
}
}
}

View File

@@ -904,6 +904,7 @@ namespace ToolLib.VisionJob
}
[NonSerialized]
public FormImageWindow myHalconWindow = new FormImageWindow();
public string JobDirectoryPath { get; set; } = @"D:\VisionSystem\";
}
}

View File

@@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WeifenLuo.WinFormsUI.Docking;
namespace VisionEdit
{
public class AppConfig
{
public static DockState leftForm = DockState.DockLeft; // 功能窗体,左端停靠
public static DockState rightForm = DockState.DockRight; // 功能窗体,右端停靠
public static DockState docForm = DockState.Document; // 功能窗体,中间停靠
}
}

View File

@@ -59,7 +59,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AppConfig.cs" />
<Compile Include="FormMain.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>