67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
// ============================================================================
|
|
// Copyright © 2026 Hexagon Technology Center GmbH. All Rights Reserved.
|
|
// 文件名: MirrorProcessor.cs
|
|
// 描述: 镜像算子,用于图像翻转
|
|
// 功能:
|
|
// - 水平镜像(左右翻转)
|
|
// - 垂直镜像(上下翻转)
|
|
// - 对角镜像(水平+垂直翻转,等效180°旋转)
|
|
// 算法: 像素坐标映射
|
|
// 作者: 李伟 wei.lw.li@hexagon.com
|
|
// ============================================================================
|
|
|
|
using Emgu.CV;
|
|
using Emgu.CV.CvEnum;
|
|
using Emgu.CV.Structure;
|
|
using XP.ImageProcessing.Core;
|
|
using Serilog;
|
|
|
|
namespace XP.ImageProcessing.Processors;
|
|
|
|
/// <summary>
|
|
/// 镜像算子
|
|
/// </summary>
|
|
public class MirrorProcessor : ImageProcessorBase
|
|
{
|
|
private static readonly ILogger _logger = Log.ForContext<MirrorProcessor>();
|
|
|
|
public MirrorProcessor()
|
|
{
|
|
Name = LocalizationHelper.GetString("MirrorProcessor_Name");
|
|
Description = LocalizationHelper.GetString("MirrorProcessor_Description");
|
|
}
|
|
|
|
protected override void InitializeParameters()
|
|
{
|
|
Parameters.Add("Direction", new ProcessorParameter(
|
|
"Direction",
|
|
LocalizationHelper.GetString("MirrorProcessor_Direction"),
|
|
typeof(string),
|
|
"Horizontal",
|
|
null,
|
|
null,
|
|
LocalizationHelper.GetString("MirrorProcessor_Direction_Desc"),
|
|
new string[] { "Horizontal", "Vertical", "Both" }));
|
|
|
|
_logger.Debug("InitializeParameters");
|
|
}
|
|
|
|
public override Image<Gray, byte> Process(Image<Gray, byte> inputImage)
|
|
{
|
|
string direction = GetParameter<string>("Direction");
|
|
|
|
var result = inputImage.Clone();
|
|
|
|
FlipType flipType = direction switch
|
|
{
|
|
"Vertical" => FlipType.Vertical,
|
|
"Both" => FlipType.Both,
|
|
_ => FlipType.Horizontal
|
|
};
|
|
|
|
CvInvoke.Flip(inputImage, result, flipType);
|
|
|
|
_logger.Debug("Process: Direction = {Direction}", direction);
|
|
return result;
|
|
}
|
|
} |