31.8、几何定位---实例三(多模板不支持缩放)
目标:定位出以下三种工件(计算出每个工件的中心坐标以及旋转角度)
read_image (Image1, 'C:/1.BMP')
*创建模板1
draw_rectangle2 (3600, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle1, Row, Column, Phi, Length1, Length2)
reduce_domain (Image1, Rectangle1, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(-180), rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID1)
get_shape_model_contours (ModelContours, ModelID1, 1)
*创建模板2
draw_rectangle2 (3600, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle2, Row, Column, Phi, Length1, Length2)
reduce_domain (Image1, Rectangle2, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(-180), rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID2)
get_shape_model_contours (ModelContours, ModelID2, 1)
*创建模板3
draw_rectangle2 (3600, Row, Column, Phi, Length1, Length2)
gen_rectangle2 (Rectangle3, Row, Column, Phi, Length1, Length2)
reduce_domain (Image1, Rectangle3, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(-180), rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID3)
get_shape_model_contours (ModelContours, ModelID3, 1)
*输入模板数组
find_shape_models (Image1, [ModelID1,ModelID2,ModelID3], rad(-180), rad(360), 0.5, 30, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle, Score, Model)
*显示结果
dev_display_shape_matching_results ([ModelID1,ModelID2,ModelID3], ['red','green','blue'], Row1, Column1, Angle, 1, 1, Model)