Files
XplorePlane/XP.ImageProcessing.Core/Alignment/AlignmentRecipe.cs
T
李伟 1874c4a5bb 新增 ROI 对齐基础能力并打通到算子与 UI。
统一补齐对齐核心工具类、RoiAlignment 算子、模板匹配对齐扩展和多语言资源,便于在检测前稳定完成示教 ROI 到运行图的变换。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 17:04:32 +08:00

35 lines
1.4 KiB
C#

namespace XP.ImageProcessing.Core.Alignment;
/// <summary>
/// 示教阶段保存的对齐配方:基准位姿 + 示教图像素坐标下的检测 ROI。
/// </summary>
public sealed class AlignmentRecipe
{
/// <summary>示教图上的基准位姿(建议示教图自匹配得到,或与模板 ROI 中心 + 角度 0 一致)。</summary>
public Pose2D ReferencePose { get; set; }
/// <summary>示教图上的 ROI 多边形顶点(至少 3 点)。</summary>
public List<Point2D> RoiPoints { get; set; } = new();
/// <summary>将示教 ROI 变换到运行图坐标。</summary>
public Point2D[] TransformRoi(Pose2D measuredPose)
=> RoiAlignment.TransformPolygon(RoiPoints, ReferencePose, measuredPose);
/// <summary>变换为整型顶点,供检测算子注入。</summary>
public (int X, int Y)[] TransformRoiToInt(Pose2D measuredPose)
=> RoiAlignment.TransformPolygonToInt(RoiPoints, ReferencePose, measuredPose);
/// <summary>从算子参数字典读取示教多边形并填充 <see cref="RoiPoints"/>。</summary>
public static AlignmentRecipe FromTeachParameters(
Pose2D referencePose,
IReadOnlyDictionary<string, object> parameters)
{
var points = RoiAlignmentApplier.ReadTeachPolygon(parameters);
return new AlignmentRecipe
{
ReferencePose = referencePose,
RoiPoints = points.ToList()
};
}
}