模版匹配

 

1   通过Halcon  自动生成代码

 

 

 

 

2   通过自己手动写代码

read_image (Image, '1')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (Image)
**draw_rectangle1 (WindowHandle, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, 196, 222, 236, 370)
reduce_domain (Image, Rectangle, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(0), rad(360),\
'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
area_center (Rectangle, Area, Row, Column)
vector_angle_to_rigid (0, 0, 0, Row, Column, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2D)
read_image (Image2, '2')
find_shape_model (Image2, ModelID, rad(0), rad(360), 0.5, 0, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle, Score)

for i := 0 to |Score|-1 by 1

*** 方法1 刚性仿射变化 推荐
* vector_angle_to_rigid (Row, Column, 0,Row1[i], Column1[i], Angle[i], HomMat2D1)
* affine_trans_contour_xld (ContoursAffineTrans, ContoursAffineTrans1, HomMat2D1)

** 方法2 仿射变化
hom_mat2d_identity (HomMat2DIdentity)
*** Row1[i]-Row 要移动的X左边
*** Column1[i]-Column 要移动的Y坐标
hom_mat2d_translate (HomMat2DIdentity, Row1[i]-Row,Column1[i]-Column, HomMat2DTranslate)
hom_mat2d_rotate (HomMat2DTranslate, Angle[i], Row1[i],Column1[i], HomMat2DRotate)
affine_trans_contour_xld (ContoursAffineTrans, ContoursAffineTrans1, HomMat2DRotate)

endfor

 

posted @ 2024-07-09 11:18  陌念  阅读(21)  评论(0)    收藏  举报