优化命名
This commit is contained in:
parent
2d9639bfae
commit
c1d7ac6902
@ -95,7 +95,7 @@
|
||||
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImageToHomePage.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImagesPool.xaml.cs">
|
||||
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImageFromGlobal.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="VVMs\Vision\VisionFlowHandler\Access\ImageToFile.xaml.cs">
|
||||
|
||||
@ -44,13 +44,16 @@ public partial class VisionConfigViewModel
|
||||
{
|
||||
case VisionFlowType.从全局图像获取图片:
|
||||
case VisionFlowType.存到全局图像:
|
||||
|
||||
ContentRegion = new ImageFromGlobal();
|
||||
break;
|
||||
case VisionFlowType.图像相减:
|
||||
ContentRegion = new ImagesPool();
|
||||
ContentRegion = new ImageFromLocal();
|
||||
break;
|
||||
case VisionFlowType.从局部图像获取图片:
|
||||
case VisionFlowType.存到局部图像:
|
||||
ContentRegion = new ProcessImageSelector();
|
||||
SelectedLocalImageData = null;
|
||||
ContentRegion = new ImageFromLocal();
|
||||
|
||||
break;
|
||||
case VisionFlowType.从文件获取图片:
|
||||
ContentRegion = new ImageFromFile();
|
||||
@ -77,7 +80,7 @@ public partial class VisionConfigViewModel
|
||||
ContentRegion = new ImageToHomePage();
|
||||
break;
|
||||
case VisionFlowType.卡尺寻边:
|
||||
ContentRegion = new CaliperEdgeFind();
|
||||
ContentRegion = new CaliperFindEdge();
|
||||
break;
|
||||
case VisionFlowType.卡尺找圆:
|
||||
ContentRegion = new CaliperFindCircle();
|
||||
@ -342,6 +345,7 @@ public partial class VisionConfigViewModel
|
||||
break;
|
||||
|
||||
case VisionFlowType.存到全局图像:
|
||||
|
||||
break;
|
||||
case VisionFlowType.存到文件:
|
||||
break;
|
||||
@ -412,6 +416,7 @@ public partial class VisionConfigViewModel
|
||||
newFlow.IntParams["TileSize"] = 8;
|
||||
break;
|
||||
case VisionFlowType.图像相减:
|
||||
|
||||
break;
|
||||
case VisionFlowType.ROI解码:
|
||||
newFlow.IntParams["DecodeType"] = 0;
|
||||
@ -475,7 +480,6 @@ public partial class VisionConfigViewModel
|
||||
}
|
||||
|
||||
SelectVisionFlow = null;
|
||||
SelectedGlobalImageData = null;
|
||||
|
||||
}
|
||||
|
||||
@ -494,8 +498,6 @@ public partial class VisionConfigViewModel
|
||||
set
|
||||
{
|
||||
SetProperty(ref _SelectedCamera, value);
|
||||
if (value != null)
|
||||
SelectVisionFlow.StringParams["Camera"] = value.Name;
|
||||
|
||||
}
|
||||
}
|
||||
@ -510,42 +512,11 @@ public partial class VisionConfigViewModel
|
||||
set
|
||||
{
|
||||
SetProperty(ref _FlowSelectedVariable, value);
|
||||
|
||||
if (value != null && SelectVisionFlow != null)
|
||||
SelectVisionFlow.StringParams["Variable"] = value.Name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ImageData _SelectedGlobalImageData;
|
||||
/// <summary>
|
||||
/// 在流程中选择的全局图像
|
||||
/// </summary>
|
||||
public ImageData SelectedGlobalImageData
|
||||
{
|
||||
get { return _SelectedGlobalImageData; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _SelectedGlobalImageData, value);
|
||||
if (value != null)
|
||||
|
||||
SelectVisionFlow.StringParams["Image"] = value.Name;
|
||||
}
|
||||
}
|
||||
|
||||
private ImageData _SelectedLocalImageData;
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public ImageData SelectedLocalImageData
|
||||
{
|
||||
get { return _SelectedLocalImageData; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref _SelectedLocalImageData, value);
|
||||
if (value != null)
|
||||
SelectVisionFlow.StringParams["Image"] = value.Name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取From相机Handler
|
||||
/// </summary>
|
||||
public class GetFromCameraHandler : IVisionFlowHandler
|
||||
public class ImageFromCameraHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,4 +1,4 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
using System.IO;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
@ -6,7 +6,7 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
/// <summary>
|
||||
/// 获取From文件Handler
|
||||
/// </summary>
|
||||
public class GetFromFileHandler : IVisionFlowHandler
|
||||
public class ImageFromFileHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Access.ImagesPool"
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Access.ImageFromGlobal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@ -11,6 +11,10 @@
|
||||
<StackPanel>
|
||||
<TextBlock Text="{Binding Path=SelectVisionFlow.StringParams[Image]}" />
|
||||
|
||||
<ComboBox DisplayMemberPath="Name" ItemsSource="{Binding VisionsModel.ImageDatas}" SelectedItem="{Binding SelectedGlobalImageData}" />
|
||||
<ComboBox IsEditable="False"
|
||||
ItemsSource="{Binding VisionsModel.ImageDatas}"
|
||||
SelectedValue="{Binding SelectVisionFlow.StringParams[Image], Mode=TwoWay}"
|
||||
SelectedValuePath="Name" DisplayMemberPath="Name" />
|
||||
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -1,16 +1,16 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
{
|
||||
/// <summary>
|
||||
/// LoadImageFile.xaml 的交互逻辑
|
||||
/// ImageFromGlobal.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ImagesPool : UserControl
|
||||
public partial class ImageFromGlobal : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// ImagesPool
|
||||
/// </summary>
|
||||
public ImagesPool()
|
||||
public ImageFromGlobal()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取From全局图像Handler
|
||||
/// </summary>
|
||||
public class GetFromGlobalImageHandler : IVisionFlowHandler
|
||||
public class ImageFromGlobalHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Access.ProcessImageSelector"
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Access.ImageFromLocal"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@ -10,7 +10,9 @@
|
||||
d:DesignHeight="100" d:DesignWidth="300">
|
||||
<StackPanel>
|
||||
<Label Content="局部图像名称" />
|
||||
<ComboBox IsEditable="False" ItemsSource="{Binding SelectedVisionFunction.LocalImageDatas}" SelectedItem="{Binding SelectedLocalImageData}" DisplayMemberPath="Name" />
|
||||
|
||||
<ComboBox IsEditable="False" ItemsSource="{Binding SelectedVisionFunction.LocalImageDatas}" SelectedValue="{Binding SelectVisionFlow.StringParams[Image], Mode=TwoWay}" SelectedValuePath="Name" DisplayMemberPath="Name" />
|
||||
|
||||
<TextBlock Text="{Binding Path=SelectVisionFlow.StringParams[Image]}" />
|
||||
|
||||
</StackPanel>
|
||||
@ -5,12 +5,12 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
/// <summary>
|
||||
/// 选择/输入局部图像名称的配置控件
|
||||
/// </summary>
|
||||
public partial class ProcessImageSelector : UserControl
|
||||
public partial class ImageFromLocal : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 局部图像Selector
|
||||
/// </summary>
|
||||
public ProcessImageSelector()
|
||||
public ImageFromLocal()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// 从局部图像(局部图像)获取图片
|
||||
/// </summary>
|
||||
public class GetImageFromProcessHandler : IVisionFlowHandler
|
||||
public class ImageFromLocalHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,11 +1,11 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存图像To文件Handler
|
||||
/// </summary>
|
||||
public class SaveImageToFileHandler : IVisionFlowHandler
|
||||
public class ImageToFileHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,9 +1,9 @@
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存图像To全局Handler
|
||||
/// </summary>
|
||||
public class SaveImageToGlobalHandler : IVisionFlowHandler
|
||||
public class ImageToGlobalHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,9 +1,9 @@
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Access
|
||||
{
|
||||
/// <summary>
|
||||
/// 显示图像Handler
|
||||
/// </summary>
|
||||
public class ShowImageHandler : IVisionFlowHandler
|
||||
public class ImageToHomePageHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// 存到局部图像(局部图像)
|
||||
/// </summary>
|
||||
public class SaveImageToProcessHandler : IVisionFlowHandler
|
||||
public class ImageToLocalHandler : IVisionFlowHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// 类型
|
||||
@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm.CaliperEdgeFind"
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm.CaliperFindEdge"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@ -1,16 +1,16 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Algorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// 卡尺寻边参数配置控件
|
||||
/// </summary>
|
||||
public partial class CaliperEdgeFind : UserControl
|
||||
public partial class CaliperFindEdge : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// 卡尺边缘查找
|
||||
/// </summary>
|
||||
public CaliperEdgeFind()
|
||||
public CaliperFindEdge()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Processing.HistogramEqualize"
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Processing.HistogramEqualize"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
@ -16,8 +16,7 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="方法" VerticalAlignment="Center" />
|
||||
<ComboBox Grid.Column="1" Margin="5,0,0,0"
|
||||
SelectedIndex="{Binding SelectVisionFlow.IntParams[Method], Mode=TwoWay}">
|
||||
<ComboBox Grid.Column="1" Margin="5,0,0,0" SelectedIndex="{Binding SelectVisionFlow.IntParams[Method], Mode=TwoWay}">
|
||||
<ComboBoxItem Content="全局 (EqualizeHist)" />
|
||||
<ComboBoxItem Content="自适应 (CLAHE)" />
|
||||
</ComboBox>
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing
|
||||
{
|
||||
/// <summary>
|
||||
/// 图像相减 — func.Src 与全局图像做绝对差值。
|
||||
/// 图像相减 — func.Src 与局部图像做绝对差值。
|
||||
/// 常用于缺陷检测、变化检测。
|
||||
/// </summary>
|
||||
public class ImageSubtractHandler : IVisionFlowHandler
|
||||
@ -13,16 +13,25 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing
|
||||
public bool Execute(VisionFunction func, VisionFlow item)
|
||||
{
|
||||
var src = func.Src;
|
||||
if (src == null || src.Empty()) { item.Flow.ErrorState = "请先获取图片!"; return false; }
|
||||
if (src == null || src.Empty())
|
||||
{
|
||||
item.Flow.ErrorState = "请先获取图片!"; return false;
|
||||
}
|
||||
|
||||
if (!item.StringParams.TryGetValue("Image", out var imageName) || string.IsNullOrEmpty(imageName))
|
||||
{ item.Flow.ErrorState = "请选择要相减的全局图像!"; return false; }
|
||||
{
|
||||
item.Flow.ErrorState = "请选择要相减的局部图像!";
|
||||
return false;
|
||||
}
|
||||
|
||||
var imageData = func.ImageDatas.FirstOrDefault(i => i.Name == imageName);
|
||||
var imageData = func.LocalImageDatas.FirstOrDefault(i => i.Name == imageName);
|
||||
if (imageData?.Mat == null || imageData.Mat.Empty())
|
||||
{ item.Flow.ErrorState = $"全局图像池中未找到图片:{imageName}"; return false; }
|
||||
{
|
||||
item.Flow.ErrorState = $"局部图像池中未找到图片:{imageName}";
|
||||
return false;
|
||||
}
|
||||
|
||||
using Mat other = imageData.Mat;
|
||||
using Mat other = imageData.Mat.Clone();
|
||||
|
||||
// 尺寸不一致时,取交集区域
|
||||
int w = Math.Min(src.Width, other.Width);
|
||||
@ -31,21 +40,33 @@ namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing
|
||||
using Mat otherRoi = other[new OpenCvSharp.Rect(0, 0, w, h)];
|
||||
|
||||
// 统一为灰度做差值
|
||||
using Mat graySrc = new();
|
||||
using Mat grayOther = new();
|
||||
Cv2.CvtColor(srcRoi, graySrc, ColorConversionCodes.BGR2GRAY);
|
||||
Cv2.CvtColor(otherRoi, grayOther, ColorConversionCodes.BGR2GRAY);
|
||||
Mat graySrc = new();
|
||||
Mat grayOther = new();
|
||||
if (srcRoi.Channels() == 1)
|
||||
{
|
||||
graySrc = srcRoi.Clone();
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv2.CvtColor(srcRoi, graySrc, ColorConversionCodes.BGR2GRAY);
|
||||
}
|
||||
|
||||
if (otherRoi.Channels() == 1)
|
||||
{
|
||||
grayOther = otherRoi.Clone();
|
||||
}
|
||||
else
|
||||
{
|
||||
Cv2.CvtColor(otherRoi, grayOther, ColorConversionCodes.BGR2GRAY);
|
||||
}
|
||||
|
||||
// 绝对差值
|
||||
Cv2.Absdiff(graySrc, grayOther, graySrc);
|
||||
grayOther.Dispose();
|
||||
|
||||
// 写回 func.Src(BGR 格式)
|
||||
var oldSrc = func.Src;
|
||||
func.Src = new Mat();
|
||||
Cv2.CvtColor(graySrc, func.Src, ColorConversionCodes.GRAY2BGR);
|
||||
oldSrc.Dispose();
|
||||
|
||||
item.Flow.Done = true;
|
||||
// 写回 func.Src
|
||||
func.Src.Dispose();
|
||||
func.Src = grayOther;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -354,16 +354,16 @@ namespace PLCSharp.VVMs.Vision
|
||||
|
||||
[VisionFlowType.各通道最小值] = new MinChannelHandler(),
|
||||
[VisionFlowType.各通道最大值] = new MaxChannelHandler(),
|
||||
[VisionFlowType.显示图像到主页] = new ShowImageHandler(),
|
||||
[VisionFlowType.显示图像到主页] = new ImageToHomePageHandler(),
|
||||
|
||||
[VisionFlowType.从文件获取图片] = new GetFromFileHandler(),
|
||||
[VisionFlowType.从文件获取图片] = new ImageFromFileHandler(),
|
||||
|
||||
[VisionFlowType.存到文件] = new SaveImageToFileHandler(),
|
||||
[VisionFlowType.从全局图像获取图片] = new GetFromGlobalImageHandler(),
|
||||
[VisionFlowType.存到全局图像] = new SaveImageToGlobalHandler(),
|
||||
[VisionFlowType.从局部图像获取图片] = new GetImageFromProcessHandler(),
|
||||
[VisionFlowType.存到局部图像] = new SaveImageToProcessHandler(),
|
||||
[VisionFlowType.拍照] = new GetFromCameraHandler(),
|
||||
[VisionFlowType.存到文件] = new ImageToFileHandler(),
|
||||
[VisionFlowType.从全局图像获取图片] = new ImageFromGlobalHandler(),
|
||||
[VisionFlowType.存到全局图像] = new ImageToGlobalHandler(),
|
||||
[VisionFlowType.从局部图像获取图片] = new ImageFromLocalHandler(),
|
||||
[VisionFlowType.存到局部图像] = new ImageToLocalHandler(),
|
||||
[VisionFlowType.拍照] = new ImageFromCameraHandler(),
|
||||
[VisionFlowType.卡尺寻边] = new CaliperFindEdgeHandler(),
|
||||
[VisionFlowType.ORB匹配] = new ORBMatchHandler(),
|
||||
[VisionFlowType.灰度模板匹配] = new GrayTemplateMatchHandler(),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user