sift匹配输出变换矩阵
This commit is contained in:
parent
c1d7ac6902
commit
97d75b9139
@ -111,6 +111,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
SetProperty(ref _RawValue, r);
|
||||
}
|
||||
break;
|
||||
case "String":
|
||||
case "Double":
|
||||
SetProperty(ref _RawValue, value);
|
||||
break;
|
||||
@ -197,14 +198,8 @@ namespace PLCSharp.VVMs.Vision
|
||||
else
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
case "Double":
|
||||
return ((double)val).ToString("F4");
|
||||
|
||||
case "Barcode":
|
||||
if (val is Barcode b)
|
||||
return $"位置:(X:{b.Box.X:F4}, Y:{b.Box.Y:F4}) 内容:({b.Info})";
|
||||
else
|
||||
return val?.ToString() ?? "";
|
||||
case "String":
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
default:
|
||||
return val?.ToString() ?? "";
|
||||
|
||||
@ -462,6 +462,10 @@ public partial class VisionConfigViewModel
|
||||
newFlow.StringParams["TemplateName"] = "SIFT_Template";
|
||||
newFlow.StringParams["SiftMatch_PosVar"] = "SIFT匹配_Pos";
|
||||
newFlow.StringParams["SiftMatch_OffsetVar"] = "SIFT匹配_Offset";
|
||||
newFlow.StringParams["SiftMatch_MatVar"] = "SIFT匹配_矩阵";
|
||||
newFlow.BoolParams["SiftMatch_OutPos"] = true;
|
||||
newFlow.BoolParams["SiftMatch_OutOffset"] = true;
|
||||
newFlow.BoolParams["SiftMatch_OutMat"] = true;
|
||||
break;
|
||||
case VisionFlowType.XFeat匹配:
|
||||
newFlow.DoubleParams["DetectThresh"] = 0.01;
|
||||
|
||||
@ -82,16 +82,24 @@
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="绝对位置变量" VerticalAlignment="Center" ToolTip="匹配到的绝对位置写入此 Pos 变量" />
|
||||
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding SelectVisionFlow.StringParams[SiftMatch_PosVar], Mode=TwoWay, TargetNullValue=SIFT匹配_Pos}" />
|
||||
<CheckBox Grid.Row="0" Grid.Column="2" Margin="5,0" VerticalAlignment="Center" IsChecked="{Binding SelectVisionFlow.BoolParams[SiftMatch_OutPos]}" />
|
||||
|
||||
<TextBlock Grid.Row="1" Text="相对位移变量" VerticalAlignment="Center" ToolTip="相对位移写入此 Pos 变量" />
|
||||
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding SelectVisionFlow.StringParams[SiftMatch_OffsetVar], Mode=TwoWay, TargetNullValue=SIFT匹配_Offset}" />
|
||||
<CheckBox Grid.Row="1" Grid.Column="2" Margin="5,0" VerticalAlignment="Center" IsChecked="{Binding SelectVisionFlow.BoolParams[SiftMatch_OutOffset]}" />
|
||||
|
||||
<TextBlock Grid.Row="2" Text="变换矩阵变量" VerticalAlignment="Center" ToolTip="变换矩阵写入此 String 变量" />
|
||||
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding SelectVisionFlow.StringParams[SiftMatch_MatVar], Mode=TwoWay, TargetNullValue=SIFT匹配_矩阵}" />
|
||||
<CheckBox Grid.Row="2" Grid.Column="2" Margin="5,0" VerticalAlignment="Center" IsChecked="{Binding SelectVisionFlow.BoolParams[SiftMatch_OutMat]}" />
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
|
||||
|
||||
@ -181,21 +181,46 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
|
||||
func.Params.ResultDoubles["SiftMatch_Score"] = Math.Round(inlierRatio * 100, 1);
|
||||
|
||||
// ===== 9. 局部变量 =====
|
||||
var posVar = func.Params.Variables.FirstOrDefault(v => v.Name == posVarName);
|
||||
if (posVar == null)
|
||||
// 绝对位置(勾选时输出)
|
||||
if (!item.BoolParams.TryGetValue("SiftMatch_OutPos", out bool b) || b)
|
||||
{
|
||||
posVar = new LocalVariableItem(posVarName, "Pos", new Pos());
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(posVar));
|
||||
var posVar = func.Params.Variables.FirstOrDefault(v => v.Name == posVarName);
|
||||
if (posVar == null)
|
||||
{
|
||||
posVar = new LocalVariableItem(posVarName, "Pos", new Pos());
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(posVar));
|
||||
}
|
||||
posVar.RawValue = new Pos(Math.Round(tx, 3), Math.Round(ty, 3), 0, Math.Round(deltaAngle, 3));
|
||||
}
|
||||
posVar.RawValue = new Pos(Math.Round(tx, 3), Math.Round(ty, 3), 0, Math.Round(deltaAngle, 3));
|
||||
|
||||
var offVar = func.Params.Variables.FirstOrDefault(v => v.Name == offsetVarName);
|
||||
if (offVar == null)
|
||||
// 相对位移(勾选时输出)
|
||||
if (!item.BoolParams.TryGetValue("SiftMatch_OutOffset", out bool bo) || bo)
|
||||
{
|
||||
offVar = new LocalVariableItem(offsetVarName, "Pos", new Pos());
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar));
|
||||
var offVar = func.Params.Variables.FirstOrDefault(v => v.Name == offsetVarName);
|
||||
if (offVar == null)
|
||||
{
|
||||
offVar = new LocalVariableItem(offsetVarName, "Pos", new Pos());
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(offVar));
|
||||
}
|
||||
offVar.RawValue = new Pos(Math.Round(offsetX, 3), Math.Round(offsetY, 3), 0, Math.Round(deltaAngle, 3));
|
||||
}
|
||||
|
||||
// 变换矩阵(勾选时输出)
|
||||
if (!item.BoolParams.TryGetValue("SiftMatch_OutMat", out bool bm) || bm)
|
||||
{
|
||||
string matVarName = item.StringParams.TryGetValue("SiftMatch_MatVar", out var mn)
|
||||
&& !string.IsNullOrEmpty(mn) ? mn : "SIFT匹配_矩阵";
|
||||
var matVar = func.Params.Variables.FirstOrDefault(v => v.Name == matVarName);
|
||||
if (matVar == null)
|
||||
{
|
||||
matVar = new LocalVariableItem(matVarName, "String", MatExtension.SerializeAffineMat(H));
|
||||
System.Windows.Application.Current.Dispatcher.Invoke(() => func.Params.Variables.Add(matVar));
|
||||
}
|
||||
else
|
||||
{
|
||||
matVar.RawValue = MatExtension.SerializeAffineMat(H);
|
||||
}
|
||||
}
|
||||
offVar.RawValue = new Pos(Math.Round(offsetX, 3), Math.Round(offsetY, 3), 0, Math.Round(deltaAngle, 3));
|
||||
|
||||
// ===== 10. 可视化 =====
|
||||
Mat colorSrc = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user