XLD模板匹配实例
解读对于这个图片,会出现重复查找,后续解决!
dev_update_off() dev_close_window() read_image(Image, 'E:/学习/Halcon/模板匹配/XLD/modules_01.png') get_image_size(Image, Width, Height) dev_open_window(0, 0, Width, Height, 'black', WindowHandle) dev_display(Image) *获取灰度图 rgb1_to_gray(Image, GrayImage) *获取感兴趣的区域 draw_rectangle2(WindowHandle, Row, Column, Phi, Length1, Length2) gen_rectangle2(Rectangle1, Row, Column, Phi, Length1, Length2) *创建模板 reduce_domain(GrayImage, Rectangle1, ImageReduced) edges_sub_pix(ImageReduced, Edges, 'canny', 1, 20, 40) *create_shape_model(ImageReduced, 'auto', rad(0), rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID) create_shape_model_xld(Edges, 'auto', rad(0), rad(360), 'auto', 'auto', 'ignore_local_polarity', 50, ModelID) get_shape_model_contours(ModelContours, ModelID, 1) find_shape_model(GrayImage, ModelID, rad(0), rad(360), 0.9, 1, 0.9, 'least_squares', 0, 0.9, Row1, Column1, Angle1, Score1) vector_angle_to_rigid(0, 0, 0,Row1, Column1, 0, HomMat2D) affine_trans_contour_xld(ModelContours, ContoursAffinTrans, HomMat2D) dev_clear_window() dev_display(Image) dev_display(ContoursAffinTrans) find_shape_models(GrayImage, ModelID, rad(0), rad(360), 0.86, 0, 0.9, 'least_squares', 0, 0.9, Row4, Column4, Angle4, Score4, Model) dev_clear_window() dev_display(Image) for I:=0 to |Score4|-1 by 1 hom_mat2d_identity(HomMat2DIdentity) hom_mat2d_translate(HomMat2DIdentity, Row4[I],Column4[I], HomMat2DTranslate) hom_mat2d_rotate(HomMat2DTranslate, Angle4[I], Row4[I],Column4[I], HomMat2DRotate) affine_trans_contour_xld(ModelContours, ContoursAffinTrans1, HomMat2DRotate) dev_display(ContoursAffinTrans1) endfor
查了几次。
解决上述问题:
采用了这种方式实现ROI获取XLD:
1 *获取感兴趣的区域 2 draw_rectangle2(WindowHandle, Row, Column, Phi, Length1, Length2) 3 gen_rectangle2(Rectangle1, Row, Column, Phi, Length1, Length2) 4 smallest_rectangle2(Rectangle1, Row3, Column3, Phi2, Length12, Length22) 5 gen_rectangle2_contour_xld(Rectangle, Row3, Column3, Phi2, Length12, Length22)
可以解决上述问题,但不知道第一种方式出现这种问题的根源在哪里。