模板匹配三
模板创建与匹配参数的选择
inspect_shape_model
inspect_shape_model创建形状模型的表示。运算符对于确定参数NumLevels和Contrast尤其有用,它们可以快速,方便地用于create_shape_model,create_scaled_shape_model或create_aniso_shape_model中。模型的表示是在多个图像金字塔级别上创建的,其中级别的数量由NumLevels确定。在其典型用法中,使用NumLevels和Contrast的不同参数多次调用inspect_shape_model,直到获得满意的模型为止。
1 dev_update_window ('off') 2 read_image(Image, 'E:/学习/Halcon/模板匹配/2.bmp') 3 threshold (Image, Regions, 201, 255) 4 5 connection(Regions, ConnectedRegions) 6 7 draw_rectangle1(3600, Row1, Column1, Row2, Column2) 8 gen_rectangle1(Rectangle1, Row1, Column1, Row2, Column2) 9 reduce_domain(Image, Rectangle1, ImageReduced) 10 *determine_shape_model_params 11 inspect_shape_model(ImageReduced, ModelImages, ModelRegions, 2, 50) 12
*NumLevels表面金字塔层数,建议最高层的金字塔至少有10-15个像素 13 * area_center(ModelRegions, Area, Row, Column) 14 * count_obj(ModelImages, Number) 15 * for i := 1 to Number by 1 16 * if(Area[i-1] >= 10) 17 * NumLevels := i 18 * endif 19 * endfor 20 21 create_shape_model(ImageReduced, 2, -0.39, 0.79, 'auto', 'auto', 'use_polarity', 60, 10, ModelID) 22 23 24 get_shape_model_contours(ModelContours, ModelID, 2) 25 26 get_shape_model_origin(ModelID, RowOrigin, ColumnOrigin) 27 28 find_shape_model(Image, ModelID, -0.39, 0.78, 0.5, 1, 0.5, 'least_squares', 2, 0.9, Row3, Column3, Angle, Score) 29 vector_angle_to_rigid(RowOrigin, ColumnOrigin, 0, Row3, Column3, Angle, HomMat2D) 30 affine_trans_contour_xld(ModelContours, ContoursAffinTrans, HomMat2D) 31 dev_clear_window() 32 dev_display(Image) 33 dev_display(ContoursAffinTrans)
修改层数NumLevels的值:1,2,3,
可以得到结果分别如下:
修改对比度Contrast :20,30,40,60
可以得到结果分别如下: