1、修复找线工具的selectObject无法实时跟随的问题

2、可以重定义找线工具的初始位置
3、在工具初始化时加入防止其他事件更改UI参数的逻辑,以解决工具参数无法保存的bug
This commit is contained in:
liu.wenjie
2022-04-08 17:05:31 +08:00
parent 8f7a1e0ffd
commit 07a7a051d8
13 changed files with 197 additions and 77 deletions

View File

@@ -16,10 +16,53 @@ namespace FindLineTool
/// </summary>
public PosXYU inputPose = new PosXYU();
/// <summary>
/// 输入姿态
/// </summary>
public HTuple inputPoseHomMat2D = new HTuple();
/// <summary>
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
>>>>>>> 751e985 (1线selectObject无法实时跟随的问题)
=======
>>>>>>> 8c64a4f (1线selectObject无法实时跟随的问题)
=======
>>>>>>> 751e985 (1线selectObject无法实时跟随的问题)
/// 位置修正姿态
/// </summary>
public HTuple changePoseHomMat2D = new HTuple();
/// <summary>
/// 制作模板时的位姿
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
=======
=======
>>>>>>> fa76389 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> b070592 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> fa76389 (FindLine工具无法位置跟随的问题)
/// 制作模板时的输入位姿
>>>>>>> b070592 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> 751e985 (1线selectObject无法实时跟随的问题)
=======
>>>>>>> 8c64a4f (1线selectObject无法实时跟随的问题)
=======
>>>>>>> 751e985 (1线selectObject无法实时跟随的问题)
/// </summary>
public PosXYU templatePose = new PosXYU();
/// <summary>
/// 修改的位姿
/// </summary>
public HTuple changedPose = new HTuple();
/// <summary>
/// 卡尺
/// </summary>
public HObject contoursDisp = null;
@@ -50,7 +93,11 @@ namespace FindLineTool
/// <summary>
/// 新的跟随姿态变化后的预期线信息
/// </summary>
HTuple newExpectLineStartRow = new HTuple(200), newExpectLineStartCol = new HTuple(200), newExpectLineEndRow = new HTuple(200), newExpectLineEndCol = new HTuple(600);
public HTuple modelStartRow = new HTuple(200), modelStartCol = new HTuple(200), modelEndRow = new HTuple(200), modelEndCol = new HTuple(600);
/// <summary>
/// 新的跟随姿态变化后的预期线信息
/// </summary>
public HTuple newExpectLineStartRow = new HTuple(200), newExpectLineStartCol = new HTuple(200), newExpectLineEndRow = new HTuple(200), newExpectLineEndCol = new HTuple(600);
///// <summary>
///// 区域中心行坐标
///// </summary>
@@ -214,7 +261,16 @@ namespace FindLineTool
FormFindLine.Instance.myHwindow.DispHWindow.ClearWindow();
DispImage();
}
// 更新模板线的位置,并生成变换矩阵
public void UpdateModelLineLocation()
{
// 计算新的位置线和转换之后位置线之间的差异,再将差异补偿到模板位置线中
HOperatorSet.VectorToSimilarity(new HTuple(newExpectLineStartRow, newExpectLineEndRow), new HTuple(newExpectLineStartCol, newExpectLineEndCol),
new HTuple(expectLineStartRow, expectLineEndRow), new HTuple(expectLineStartCol, expectLineEndCol), out changePoseHomMat2D);
// 更新位置
HOperatorSet.AffineTransPixel(changePoseHomMat2D, modelStartRow, modelStartCol, out modelStartRow, out modelStartCol);
HOperatorSet.AffineTransPixel(changePoseHomMat2D, modelEndRow, modelEndCol, out modelEndRow, out modelEndCol);
}
public override void Run(SoftwareRunState softwareRunState)
{
@@ -235,20 +291,62 @@ namespace FindLineTool
{
UpdateImage();
}
if (inputPose != null)
if (inputPoseHomMat2D != null)
{
HTuple Row = inputPose.X - templatePose.X;
HTuple Col = inputPose.Y - templatePose.Y;
HTuple angle = inputPose.U - templatePose.U;
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
//对预期线的起始点做放射变换
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelStartRow, modelStartCol, out newExpectLineStartRow, out newExpectLineStartCol);
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelEndRow, modelEndCol, out newExpectLineEndRow, out newExpectLineEndCol);
=======
=======
>>>>>>> fa76389 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> b070592 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> fa76389 (FindLine工具无法位置跟随的问题)
//HTuple Row = inputPose.X - templatePose.X;
//HTuple Col = inputPose.Y - templatePose.Y;
//HTuple angle = inputPose.U - templatePose.U;
HTuple _homMat2D;
HOperatorSet.HomMat2dIdentity(out _homMat2D);
HOperatorSet.HomMat2dRotate(_homMat2D, (HTuple)(angle), (HTuple)templatePose.X, (HTuple)templatePose.Y, out _homMat2D);
HOperatorSet.HomMat2dTranslate(_homMat2D, (HTuple)(Row), (HTuple)(Col), out _homMat2D);
//HTuple _homMat2D;
//HOperatorSet.HomMat2dIdentity(out _homMat2D);
//HOperatorSet.HomMat2dRotate(_homMat2D, (HTuple)(angle), (HTuple)templatePose.X, (HTuple)templatePose.Y, out _homMat2D);
//HOperatorSet.HomMat2dTranslate(_homMat2D, (HTuple)(Row), (HTuple)(Col), out _homMat2D);
//对预期线的起始点做放射变换
HOperatorSet.AffineTransPixel(_homMat2D, (HTuple)expectLineStartRow, (HTuple)expectLineStartCol, out newExpectLineStartRow, out newExpectLineStartCol);
HOperatorSet.AffineTransPixel(_homMat2D, (HTuple)expectLineEndRow, (HTuple)expectLineEndCol, out newExpectLineEndRow, out newExpectLineEndCol);
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, (HTuple)expectLineStartRow, (HTuple)expectLineStartCol, out newExpectLineStartRow, out newExpectLineStartCol);
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, (HTuple)expectLineEndRow, (HTuple)expectLineEndCol, out newExpectLineEndRow, out newExpectLineEndCol);
<<<<<<< HEAD
<<<<<<< HEAD
<<<<<<< HEAD
>>>>>>> b070592 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> fa76389 (FindLine工具无法位置跟随的问题)
=======
//对预期线的起始点做放射变换
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelStartRow, modelStartCol, out newExpectLineStartRow, out newExpectLineStartCol);
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelEndRow, modelEndCol, out newExpectLineEndRow, out newExpectLineEndCol);
>>>>>>> 751e985 (1线selectObject无法实时跟随的问题)
=======
//对预期线的起始点做放射变换
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelStartRow, modelStartCol, out newExpectLineStartRow, out newExpectLineStartCol);
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelEndRow, modelEndCol, out newExpectLineEndRow, out newExpectLineEndCol);
>>>>>>> 8c64a4f (1线selectObject无法实时跟随的问题)
=======
>>>>>>> b070592 (FindLine工具无法位置跟随的问题)
=======
>>>>>>> fa76389 (FindLine工具无法位置跟随的问题)
=======
//对预期线的起始点做放射变换
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelStartRow, modelStartCol, out newExpectLineStartRow, out newExpectLineStartCol);
HOperatorSet.AffineTransPixel(inputPoseHomMat2D, modelEndRow, modelEndCol, out newExpectLineEndRow, out newExpectLineEndCol);
>>>>>>> 751e985 (1线selectObject无法实时跟随的问题)
}
else
{

View File

@@ -34,6 +34,9 @@
<Reference Include="halcondotnet">
<HintPath>C:\Program Files\MVTec\HALCON-19.05-Progress\bin\dotnet20\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="SunnyUI">
<HintPath>..\VisionEdit\bin\Debug\ThirdLib\SunnyUI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />

View File

@@ -59,7 +59,7 @@ namespace FindLineTool
myFindLine.inputImage = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as HObject;
break;
case "InputPos":
myFindLine.inputPose = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as PosXYU;
myFindLine.inputPoseHomMat2D = myJob.GetToolInfoByToolName(sourceToolName).GetOutput(toolItem).value as HTuple;
break;
default:
break;

View File

@@ -71,6 +71,7 @@ namespace FindLineTool
this.label7 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.label9 = new System.Windows.Forms.Label();
this.btnSetModelPose = new Sunny.UI.UISymbolButton();
this.toolStrip1.SuspendLayout();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
@@ -189,6 +190,7 @@ namespace FindLineTool
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnSetModelPose);
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.tbx_minScore);
this.groupBox1.Controls.Add(this.label5);
@@ -544,6 +546,20 @@ namespace FindLineTool
this.label9.TabIndex = 105;
this.label9.Text = "起点列坐标:";
//
// btnSetModelPose
//
this.btnSetModelPose.Cursor = System.Windows.Forms.Cursors.Hand;
this.btnSetModelPose.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnSetModelPose.IsScaled = false;
this.btnSetModelPose.Location = new System.Drawing.Point(40, 437);
this.btnSetModelPose.MinimumSize = new System.Drawing.Size(1, 1);
this.btnSetModelPose.Name = "btnSetModelPose";
this.btnSetModelPose.Size = new System.Drawing.Size(352, 35);
this.btnSetModelPose.Symbol = 361771;
this.btnSetModelPose.TabIndex = 334;
this.btnSetModelPose.Text = "标定为模板位置";
this.btnSetModelPose.Click += new System.EventHandler(this.btnSetModelPose_Click);
//
// FormFindLine
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -624,5 +640,6 @@ namespace FindLineTool
private System.Windows.Forms.ToolStripStatusLabel lb_RunStatus;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private System.Windows.Forms.ToolStripStatusLabel lb_RunTime;
private Sunny.UI.UISymbolButton btnSetModelPose;
}
}

View File

@@ -67,8 +67,10 @@ namespace FindLineTool
myHwindow.Dock = DockStyle.Fill;
InitTool();
}
bool isInit = false;
private void InitTool()
{
isInit = true;
this.Text = myToolInfo.toolName;
Application.DoEvents();
@@ -84,14 +86,16 @@ namespace FindLineTool
tbx_caliperLength2.Text = myFindLine.weidth.ToString();
chBDispRec.Checked = myFindLine.dispRec;
chBDispCross.Checked = myFindLine.dispCross;
// 将要编辑的线显示
selected_drawing_object = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, new HTuple[] { myFindLine.expectLineStartRow, myFindLine.expectLineStartCol, myFindLine.expectLineEndRow, myFindLine.expectLineEndCol });
//// 将要编辑的线显示
selected_drawing_object = myFindLine.inputPoseHomMat2D != null? 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 });
GC.KeepAlive(selected_drawing_object);
selected_drawing_object.OnSelect(OnSelectDrawingObject);
selected_drawing_object.OnAttach(OnSelectDrawingObject);
selected_drawing_object.OnResize(OnSelectDrawingObject);
selected_drawing_object.OnDrag(OnSelectDrawingObject);
myHwindow.DispHWindow.AttachDrawingObjectToWindow(selected_drawing_object);
isInit = false;
}
/// <summary>
/// 参数回调
@@ -122,7 +126,7 @@ namespace FindLineTool
}
/// <summary>
/// 设定工具运行状态
/// </summary>
/// </summary>`
/// <param name="msg">运行中的信息</param>
/// <param name="status">运行状态</param>
public void SetToolStatus(string msg, ToolRunStatu status)
@@ -146,8 +150,11 @@ namespace FindLineTool
private void DispSetCheck(object sender, EventArgs e)
{
myFindLine.dispRec = chBDispRec.Checked ? true : false;
myFindLine.dispCross = chBDispCross.Checked ? true : false;
if(!isInit)
{
myFindLine.dispRec = chBDispRec.Checked ? true : false;
myFindLine.dispCross = chBDispCross.Checked ? true : false;
}
}
private void FormFindLine2_FormClosing(object sender, FormClosingEventArgs e)
@@ -157,5 +164,11 @@ namespace FindLineTool
this.Dispose();
GC.Collect();
}
private void btnSetModelPose_Click(object sender, EventArgs e)
{
myFindLine.UpdateModelLineLocation();
MessageBox.Show("模板线位置已更新");
}
}
}