Matching
HALCON 10.0 II-B
3.1 Gray-Value-Based Matching
基于灰度的匹配是一个非常经典的方法,它仅适用于对象的不模糊,不缺失,灰度值不变化。适用于对象旋转转。注意对
于所有的应用,相关性和基于形状的匹配是要优先考虑的。使用灰度匹配的理由可能是由于匹配的对象和灰度有关系。
The rare cases in which the very slow classical gray-valuebased matching is to be preferred comprise the case that the matching must be illumination-variant. If, e.g. a colored pattern has to be found and the hue value of the object in the search image must not deviate from the hue value of the object in the template image, the illumination-invariant approaches might be less suitable, as they use normalized gray values, i.e., they evaluate the relative differences between the grayvalues instead of the absolute values.
使用灰度值匹配的步骤:
• Create a model with create_template if the object is expected to be only translated but not
• Clear the model from memory with clear_template.
一个例子,扣件匹配。
![](https://images.cnblogs.com/cnblogs_com/xiaomaLV2/201203/201203271034494635.jpg)
dev_close_window()
read_image(Image,'E:/钢轨缺陷/扣件下/227 1.bmp')
get_image_size(Image,Width,Height)
dev_open_window(0,0,Width,Height,'black',WindowHandle)
dev_display(Image)
*draw_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)
*gen_rectangle1(TemplateRegion,Row1,Column1,Row2,Column2)
gen_rectangle1(TemplateRegion,5.0,38.5,84.0,186.5)
*equ_histo_image(Image,Image)
reduce_domain(Image,TemplateRegion,ImageTemplate)
*创建模板
**************************************************
* create_template_rot(Template 用于做模板的图像
* : : NumLevel, 金字塔数
* AngleStart, 最小旋转角度
* AngleExtend,最大旋转角度
* AngleStep,旋转步长
* Optimize, 优化选项 sort /none (sort 创建模板的时间会长点,随之
* 带来的是匹配更准确
* GrayValues : 原始灰度值: original
* normalized
* 梯度:gradient sobel
* TemplateID)
******************************************************
create_template_rot (ImageTemplate, 4, rad(0), rad(360), rad(1), 'sort', 'sobel', TemplateID)
dev_set_draw('margin')
*匹配
for i :=67 to 200 by 1
read_image(ImageDst,'E:/钢轨缺陷/扣件下/'+i+' 1.bmp')
dev_display(ImageDst)
count_seconds(beginTime)
*
*MaxEorr (0~255) 容许的最大匹配偏差
*Error 返回实际匹配到的偏差 。如果是255 则未匹配到 , 此时应该增加MaxEorr
*
best_match_rot_mg (ImageDst, TemplateID, rad(0), rad(360), 100,\
'false', 4, Row, Column, Angle, Error)
count_seconds(endTime)
Time :=round(1000 * (endTime - beginTime))
disp_message(WindowHandle,Time+' ms','image',-1,-1,'black','true')
gen_rectangle2(Rectangle,Row,Column,Angle,75,40)
dev_display(Rectangle)
stop()
endfor
clear_template(TemplateID)
作者: 小马_xiao
出处:http://www.cnblogs.com/xiaomaLV2/>
关于作者:专注halcon\opencv\机器视觉
本文版权归作者,未经作者同意必须保留此段声明,且在文章页面明显位置给出 原文链接