1874c4a5bb
统一补齐对齐核心工具类、RoiAlignment 算子、模板匹配对齐扩展和多语言资源,便于在检测前稳定完成示教 ROI 到运行图的变换。 Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using XP.ImageProcessing.Core.Alignment;
|
|
|
|
namespace XP.ImageProcessing.Processors;
|
|
|
|
/// <summary>
|
|
/// 将 TemplateMatchLib 匹配结果转换为对齐工具使用的 <see cref="Pose2D"/>。
|
|
/// </summary>
|
|
public static class TemplateMatchAlignmentExtensions
|
|
{
|
|
public static Pose2D ToPose2D(this TM_Result result)
|
|
=> new(result.CenterX, result.CenterY, result.Angle);
|
|
|
|
/// <summary>四角质心是否与 Center 一致(容差默认 1 像素)。</summary>
|
|
public static bool IsCenterConsistentWithCorners(this TM_Result result, double tolerancePixels = 1.0)
|
|
=> RoiAlignment.IsMatchCenterConsistentWithCorners(
|
|
result.CenterX,
|
|
result.CenterY,
|
|
result.LtX,
|
|
result.LtY,
|
|
result.RtX,
|
|
result.RtY,
|
|
result.RbX,
|
|
result.RbY,
|
|
result.LbX,
|
|
result.LbY,
|
|
tolerancePixels);
|
|
|
|
/// <summary>从 RotatedTemplateMatching 的 OutputData 读取测量位姿。</summary>
|
|
public static bool TryReadMeasuredPose(
|
|
IReadOnlyDictionary<string, object>? outputData,
|
|
out Pose2D measuredPose,
|
|
out string? errorMessage,
|
|
int matchIndex = 0)
|
|
=> TemplateMatchOutputReader.TryReadMeasuredPose(outputData, out measuredPose, out errorMessage, matchIndex);
|
|
|
|
/// <summary>用匹配结果 + 示教配方一步得到对齐后的 ROI。</summary>
|
|
public static RoiAlignmentResult AlignRecipe(
|
|
AlignmentRecipe recipe,
|
|
IReadOnlyDictionary<string, object>? templateMatchOutput,
|
|
int matchIndex = 0)
|
|
=> RoiAlignmentApplier.ApplyFromTemplateMatchOutput(recipe, templateMatchOutput, matchIndex);
|
|
}
|