模板匹配三
阿新 • • 發佈:2022-03-17
模板建立與匹配引數的選擇
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 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] >= 1100) 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
可以得到結果分別如下: