diff --git a/PLCSharpWpf/Models/xfeat.onnx b/PLCSharpWpf/Models/xfeat.onnx new file mode 100644 index 0000000..fab6b7f Binary files /dev/null and b/PLCSharpWpf/Models/xfeat.onnx differ diff --git a/PLCSharpWpf/Models/xfeat.onnx.data b/PLCSharpWpf/Models/xfeat.onnx.data new file mode 100644 index 0000000..92650a3 Binary files /dev/null and b/PLCSharpWpf/Models/xfeat.onnx.data differ diff --git a/PLCSharpWpf/PLCSharp.csproj b/PLCSharpWpf/PLCSharp.csproj index 33fb3c6..a9d7dce 100644 --- a/PLCSharpWpf/PLCSharp.csproj +++ b/PLCSharpWpf/PLCSharp.csproj @@ -20,7 +20,8 @@ - + + @@ -37,6 +38,12 @@ Never + + PreserveNewest + + + PreserveNewest + PreserveNewest diff --git a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs index 3925779..24bd4c1 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.Flows.cs @@ -123,6 +123,9 @@ public partial class VisionConfigViewModel case VisionFlowType.SIFT匹配: ContentRegion = new SiftMatch(); break; + case VisionFlowType.XFeat匹配: + ContentRegion = new XFeatMatch(); + break; case VisionFlowType.点到点距离: ContentRegion = new PointToPointDistance(); break; @@ -444,6 +447,15 @@ public partial class VisionConfigViewModel newFlow.StringParams["SiftMatch_PosVar"] = "SIFT匹配_Pos"; newFlow.StringParams["SiftMatch_OffsetVar"] = "SIFT匹配_Offset"; break; + case VisionFlowType.XFeat匹配: + newFlow.DoubleParams["DetectThresh"] = 0.01; + newFlow.DoubleParams["MatchThresh"] = 0.6; + newFlow.IntParams["TopK"] = 4096; + newFlow.IntParams["MaxDim"] = 640; + newFlow.StringParams["TemplateName"] = "XFeat_Template"; + newFlow.StringParams["XFeatMatch_PosVar"] = "XFeat匹配_Pos"; + newFlow.StringParams["XFeatMatch_OffsetVar"] = "XFeat匹配_Offset"; + break; case VisionFlowType.点到点距离: newFlow.StringParams["ResultVar"] = "点到点距离"; break; diff --git a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.PublicCommands.cs b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.PublicCommands.cs index 6437cb2..7b930a7 100644 --- a/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.PublicCommands.cs +++ b/PLCSharpWpf/VVMs/Vision/VisionConfigViewModel.PublicCommands.cs @@ -755,6 +755,56 @@ public partial class VisionConfigViewModel } } + private AsyncDelegateCommand _DrawXFeatMatchROI; + public AsyncDelegateCommand DrawXFeatMatchROI => + _DrawXFeatMatchROI ??= new AsyncDelegateCommand(ExecuteDrawXFeatMatchROIAsync); + + private async Task ExecuteDrawXFeatMatchROIAsync() + { + var imageEdit = SelectedVisionFunction?.EditImageEdit; + if (imageEdit?.ImageSource == null) { SendInfoDialog("请先获取图片!"); return; } + try + { + if (SelectVisionFlow == null) return; + string roiShape = SelectVisionFlow.StringParams.TryGetValue("ROIShape", out var rs) + && !string.IsNullOrEmpty(rs) ? rs : "矩形"; + double centerX = 0, centerY = 0; + + switch (roiShape) + { + case "矩形": + { + var roi = await imageEdit.DrawROIAsync("XFeat匹配"); + if (roi == null) return; + SelectVisionFlow.DoubleParams["TemplateLeft"] = roi.Left; + SelectVisionFlow.DoubleParams["TemplateTop"] = roi.Top; + SelectVisionFlow.DoubleParams["TemplateWidth"] = roi.Width; + SelectVisionFlow.DoubleParams["TemplateHeight"] = roi.Height; + centerX = roi.Left + roi.Width / 2.0; + centerY = roi.Top + roi.Height / 2.0; + var srcMat = SelectedVisionFunction.Src; + if (srcMat != null && !srcMat.Empty()) + { + int x = Math.Clamp((int)roi.Left, 0, srcMat.Width - 1); + int y = Math.Clamp((int)roi.Top, 0, srcMat.Height - 1); + int w = Math.Min((int)roi.Width, srcMat.Width - x); + int h = Math.Min((int)roi.Height, srcMat.Height - y); + if (w > 0 && h > 0) + SaveTemplateMat(srcMat[new OpenCvSharp.Rect(x, y, w, h)].Clone()); + } + imageEdit.DrawRectVisual(roi.Left, roi.Top, roi.Width, roi.Height); + break; + } + } + SelectVisionFlow.DoubleParams["Width"] = imageEdit.ImageSource.Width; + SelectVisionFlow.DoubleParams["Height"] = imageEdit.ImageSource.Height; + SelectVisionFlow.DoubleParams["TemplateCenterX"] = centerX; + SelectVisionFlow.DoubleParams["TemplateCenterY"] = centerY; + SendInfoDialog("模板已保存"); + } + catch (Exception ex) { SendInfoDialog($"模板绘制失败:{ex.Message}"); } + } + /// /// 保存模板 Mat 到 Params(替换同名旧模板) /// diff --git a/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/XFeatMatch.xaml b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/XFeatMatch.xaml new file mode 100644 index 0000000..44b6c08 --- /dev/null +++ b/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Algorithm/XFeatMatch.xaml @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + +