Halcon中模板匹配的总结
基于相关性的模板匹配
该方法使用一种基于行向量的归一化相关匹配法,在检测图像种匹配模板匹配。与基于灰度值的匹配相比,该方法速度比较快,并且能够适应线光照变化。
read_image (Image1, 'E:/YZW/image/1.bmp')
get_image_size (Image1, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width/4, Height/4, 'black', WindowHandle)
dev_display (Image1)
*选择ROI区域
gen_rectangle1 (ROI_0, 1322.32, 449.966, 1438.32, 3877.97)
area_center (ROI_0, Area, Row1, Column1)
reduce_domain (Image1, ROI_0, ImageReduced)
*创建基于相关性的匹配模板,输入模板图像和模型参数
create_ncc_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 'use_polarity', ModelID)
*设置显示图像
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image1)
dev_display (ROI_0)
stop ()
*读取图像
read_image (Image3, 'E:/YZW/image/3.bmp')
find_ncc_model (Image3, ModelID, -0.39, 0.79, 0.8, 1, 0.5, 'true', 0, Row, Column,Angle, Score)
*dev_display_shape_matching_results (ModelID, 'red', Row, Column, Angle, 1, 1, 0)
vector_angle_to_rigid (Row1, Column1, 0, Row, Column, 0, HomMat2D)
affine_trans_region (ROI_0, RegionAffineTrans, HomMat2D, 'nearest_neighbor')
dev_display (Image3)
dev_display (RegionAffineTrans)