1. 程式人生 > 其它 >模板匹配二

模板匹配二

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)

可以解決上述問題,但不知道第一種方式出現這種問題的根源在哪裡。