Halcon 可形变模板匹配

本文详细介绍了可形变模板匹配技术,包括创建模板和模板匹配的两个核心算子,以及关键参数说明。该技术适用于未经校正的透视匹配场景,通过调整旋转角度、缩放比例等参数实现精准匹配。

可形变模板匹配主要用到两个算子

1.创建模板

Description

The operator create_planar_uncalib_deformable_model prepares a template, which is passed in the image Template, as a deformable model used for uncalibrated perspective matching. The ROI of the model is passed as the domain of Template.

2.模板匹配

Description

The operator find_planar_uncalib_deformable_model finds the best NumMatches instances of the perspectively distorted deformable model ModelID in the input image Image. The model must have been created previously by calling create_planar_uncalib_deformable_model or read_deformable_model.

3.模板匹配主要参数说明

Image (input_object)  (multichannel-)image → object (byte / uint2)

Input image in which the model should be found.

ModelID (input_control)  deformable_model → (integer)

Handle of the model.

AngleStart (input_control)  angle.rad → (real)

Smallest rotation of the model.

Default value: -0.39

Suggested values: -3.14, -1.57, -0.79, -0.39, -0.20, 0.0

AngleExtent (input_control)  angle.rad → (real)

Extent of the rotation angles.

Default value: 0.78

Suggested values: 6.29, 3.14, 1.57, 0.79, 0.39, 0.0

Restriction: AngleExtent >= 0

ScaleRMin (input_control)  number → (real)

Minimum scale of the model in row direction.

Default value: 1.0

Suggested values: 0.5, 0.6, 0.7, 0.8, 0.9, 1.0

Restriction: ScaleRMin > 0

ScaleRMax (input_control)  number → (real)

Maximum scale of the model in row direction.

Default value: 1.0

Suggested values: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5

Restriction: ScaleRMax >= ScaleRMin

ScaleCMin (input_control)  number → (real)

Minimum scale of the model in column direction.

Default value: 1.0

Suggested values: 0.5, 0.6, 0.7, 0.8, 0.9, 1.0

Restriction: ScaleCMin > 0

ScaleCMax (input_control)  number → (real)

Maximum scale of the model in column direction.

Default value: 1.0

Suggested values: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5

Restriction: ScaleCMax >= ScaleCMin

MinScore (input_control)  real → (real)

Minimum score of the instances of the model to be found.

Default value: 0.5

Suggested values: 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0

Typical range of values: 0 ≤ MinScore ≤ 1

Minimum increment: 0.01

Recommended increment: 0.05

NumMatches (input_control)  integer → (integer)

Number of instances of the model to be found (or 0 for all matches).

Default value: 1

Suggested values: 0, 1, 2, 3, 4, 5, 10, 20

MaxOverlap (input_control)  real → (real)

Maximum overlap of the instances of the model to be found.

Default value: 1.0

Suggested values: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0

Typical range of values: 0 ≤ MaxOverlap ≤ 1

Minimum increment: 0.01

Recommended increment: 0.05

NumLevels (input_control)  integer(-array) → (integer)

Number of pyramid levels used in the matching (and lowest pyramid level to use if |NumLevels| = 2).

Default value: 0

List of values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

Greediness (input_control)  real → (real)

“Greediness” of the search heuristic (0: safe but slow; 1: fast but matches may be missed).

Default value: 0.9

Suggested values: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0

Typical range of values: 0 ≤ Greediness ≤ 1

Minimum increment: 0.01

Recommended increment: 0.05

GenParamName (input_control)  string-array → (string)

The general parameter names.

Default value: []

List of values: [], 'angle_change_restriction', 'angle_step', 'aniso_scale_change_restriction', 'scale_c_step', 'scale_r_step', 'subpixel'

GenParamValue (input_control)  integer-array → (integer / real / string)

Values of the general parameters.

Default value: []

List of values: [], 'least_squares', 'least_squares_high', 'least_squares_very_high', 'none'

HomMat2D (output_control)  hom_mat2d(-array) → (real)

Homographies between model and found instances.

Score (output_control)  real-array → (real)

Score of the found instances of the model.

 

4.模板匹配相关算子

read_image 读取图像

gen_cam_par_area_scan_division 设置相机参数模型

create_planar_uncalib_deformable_model 创建模板

set_deformable_model_origin 设置模板坐标原点

get_deformable_model_contours 获取模板轮廓

find_planar_uncalib_deformable_model 模板匹配

projective_trans_contour_xld 轮廓投影变换

projective_trans_pixel 投影坐标原点

vector_to_pose 计算出世界坐标和图像坐标之间的点对应的绝对位姿

disp_3d_coord_system 显示模板原点坐标系

5.模板匹配测试

设置ROI,制作模板

测试图像

 

<think>嗯,用户这次的问题很明确,就是询问Halcon中可变形模板匹配的具体使用方法和常见错误解决。从引用的材料来看,用户应该已经有一定的Halcon基础,之前可能做过基于形状的模板匹配,现在想进阶到可变形匹配这种更复杂的技术。用户提供的三份参考资料里恰好包含了关键信息:引用3直接说明了可变形匹配的分数计算机制,引用1提到了变形参数的鲁棒性特点,引用2则证实了多种匹配方法的编程实现可行性。看来用户自己已经做过功课了,只是需要系统化的操作指导。注意到用户在提问时特别强调“不是需求参考”,说明ta可能遇到过教程材料碎片化的问题。作为回复,应该把碎片信息整合成完整的工作流:从模板创建、参数配置到结果分析的全链条。尤其是引用3里提到的亚像素提取参数和变形量的关系,这个细节很多教程会忽略,但实际调试时特别重要。用户没有说具体的错误现象,所以需要准备两类内容:一是标准操作流程,二是典型报错场景。比如“模型点对应失败”这种报错,新手很容易卡住,但引用3里提到的亚像素模式切换就是解决方案之一。另外准备流程图会比较直观。</think> 以下是根据参考资料整理的**Halcon可变形模板匹配**使用教程及常见问题解决方案,结合关键参数说明和实践步骤: --- ### **一、可变形模板匹配核心原理** 通过调整模板的**局部形变**(旋转、缩放、扭曲)适应目标物体在图像中的非线性变化,适用于橡胶零件、纺织品等易变形物体定位[^1]。 ⚠️ **核心机制**: 1. **形变模型生成**:提取模板轮廓或灰度特征,建立形变向量场描述局部位移。 2. **相似度计算**:采用**最小二乘法**(如`least_squares_very_high`)匹配变形后的模型点与图像点[^3]。 --- ### **二、操作流程详解** #### **Step 1: 创建可变形模板** ```halcon * 读取参考图像并创建模板 read_image(Image, 'template.png') * 定义ROI区域(可手动绘制) gen_rectangle1(ROI, 100, 100, 300, 300) * 关键参数:'deformable'表示启用形变 create_deformable_model(Image, ROI, 'auto', 'auto', 'auto', 'deformable', 'auto', 'auto', 'auto', 'max_deformation', ModelID) ``` #### **Step 2: 配置形变参数** | 参数名 | 作用 | 建议值 | |---------------------|-------------------------------------|-------------| | `'max_deformation'` | 最大允许形变幅度(像素) | 10-30 | | `'subpixel'` | 亚像素精度模式 | `'least_squares_very_high'`[^3] | | `'min_score'` | 匹配分数阈值(过滤低质量结果) | 0.7 | #### **Step 3: 执行匹配与结果提取** ```halcon * 在目标图像中搜索模板 find_deformable_model(TargetImage, ModelID, 'auto', 'auto', 0.7, 1, 0.1, 'interpolation', 'false', Pose, Score) * 获取变形向量场(用于缺陷检测) get_deformable_model_contours(ModelContours, ModelID) ``` --- ### **三、常见问题及解决方案** #### ❗ **问题1:匹配分数异常降低** - **原因**:形变幅度过大导致模型点失去对应关系[^3]。 - **解决**: 1. 调低`'max_deformation'`(例如从30降至15) 2. 检查亚像素模式是否为`'least_squares_very_high'`(提升抗噪能力) #### ❗ **问题2:形变结果不稳定** - **原因**:光照变化或背景干扰影响特征提取。 - **解决**: 1. 预处理图像:使用`emphasize`增强边缘对比度 2. 增加模板角度范围:设置`'rotation'`(如-30°至30°) #### ❗ **问题3:程序报错"Model point not found"** - **原因**:模板ROI区域包含不稳定特征(如反光点)。 - **解决**: 1. 重新选择ROI(避开干扰区域) 2. 改用多模板策略:分别创建不同形变状态的模板[^2] --- ### **四、优化技巧** - **加速技巧**:在`find_deformable_model`中设置`'pyramid_level'=4`(多级金字塔提速) - **精度提升**:结合灰度相关性与形状匹配(`'combined'`模式)[^1] --- ### **核心参考总结** > 可变形匹配的精度依赖于亚像素模式与形变上限的平衡:**高亚像素精度可容忍更大形变,但计算成本增加**;低精度模式(如`'none'`)在变形时匹配分数可能失真[^3]。 --- ###
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值