plcsharp/PLCSharpWpf/VVMs/Vision/VisionFlowHandler/Processing/ImageFlipHandler.cs

31 lines
969 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}
}