翻转
This commit is contained in:
parent
4ada605d65
commit
f923a286f3
@ -346,6 +346,9 @@ namespace PLCSharp.VVMs.Vision
|
||||
newFlow.DoubleParams["ImageY"] = 0;
|
||||
newFlow.StringParams["TransformMat"] = "";
|
||||
break;
|
||||
case VisionFlowType.图像翻转:
|
||||
newFlow.IntParams["FlipDirection"] = 0;
|
||||
break;
|
||||
case VisionFlowType.ROI解码:
|
||||
newFlow.IntParams["DecodeType"] = 0;
|
||||
newFlow.BoolParams["EnableMirror"] = false;
|
||||
@ -580,6 +583,9 @@ namespace PLCSharp.VVMs.Vision
|
||||
case VisionFlowType.坐标转换:
|
||||
ContentRegion = new CoordTransform();
|
||||
break;
|
||||
case VisionFlowType.图像翻转:
|
||||
ContentRegion = new ImageFlip();
|
||||
break;
|
||||
case VisionFlowType.ROI解码:
|
||||
ContentRegion = new BarcodeDecode();
|
||||
break;
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<UserControl x:Class="PLCSharp.VVMs.Vision.VisionFlowHandler.Processing.ImageFlip"
|
||||
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"
|
||||
xmlns:local="clr-namespace:PLCSharp.VVMs.Vision.VisionFlowHandler"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:vision="clr-namespace:PLCSharp.VVMs.Vision"
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance Type=vision:VisionConfigViewModel}"
|
||||
d:DesignHeight="200" d:DesignWidth="300">
|
||||
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel>
|
||||
<GroupBox Header="翻转方向">
|
||||
<Grid Margin="5">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80" />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="方向" VerticalAlignment="Center" />
|
||||
<ComboBox Grid.Column="1" SelectedIndex="{Binding SelectVisionFlow.IntParams[FlipDirection], Mode=TwoWay}">
|
||||
<ComboBoxItem Content="水平翻转(左右)" />
|
||||
<ComboBoxItem Content="垂直翻转(上下)" />
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</GroupBox>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing
|
||||
{
|
||||
/// <summary>
|
||||
/// ImageFlip.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ImageFlip : UserControl
|
||||
{
|
||||
public ImageFlip()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
using OpenCvSharp;
|
||||
|
||||
namespace PLCSharp.VVMs.Vision.VisionFlowHandler.Processing
|
||||
{
|
||||
/// <summary>
|
||||
/// 图像翻转Handler — 对图像进行水平或垂直翻转
|
||||
/// </summary>
|
||||
public class ImageFlipHandler : IVisionFlowHandler
|
||||
{
|
||||
public VisionFlowType Type => VisionFlowType.图像翻转;
|
||||
|
||||
public bool Execute(VisionFunction func, VisionFlow item)
|
||||
{
|
||||
var src = func.Src ?? throw new Exception("请先获取图片!");
|
||||
|
||||
// 读取翻转方向:0=水平(左右),1=垂直(上下)
|
||||
int direction = item.IntParams.TryGetValue("FlipDirection", out int dir) ? dir : 0;
|
||||
|
||||
FlipMode flipMode = direction switch
|
||||
{
|
||||
0 => FlipMode.Y, // 水平翻转(左右)
|
||||
1 => FlipMode.X, // 垂直翻转(上下)
|
||||
_ => FlipMode.Y,
|
||||
};
|
||||
|
||||
Cv2.Flip(src, src, flipMode);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -337,6 +337,7 @@ namespace PLCSharp.VVMs.Vision
|
||||
[VisionFlowType.微信解码] = new WeChatDecodeHandler(),
|
||||
[VisionFlowType.颜色面积] = new ColorAreaHandler(),
|
||||
[VisionFlowType.灰度面积] = new GrayAreaHandler(),
|
||||
[VisionFlowType.图像翻转] = new ImageFlipHandler(),
|
||||
|
||||
};
|
||||
[NotMapped]
|
||||
|
||||
@ -46,6 +46,8 @@
|
||||
各通道最大值 = 16,
|
||||
[FlowCategory("图像处理")]
|
||||
阈值 = 17,
|
||||
[FlowCategory("图像处理")]
|
||||
图像翻转 = 19,
|
||||
|
||||
[FlowCategory("图像处理")]
|
||||
坐标转换 = 18,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user