模板匹配

dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)

read_image (Image00228, 'D:/TestImg/图像00228.BMP')

dev_set_draw ('margin')

 

*第一种方法:用一个半径为18的圆去匹配图像

*此处创建了一个半径为18的轮廓圆
gen_circle_contour_xld (ROI_0, 0, 0, 18, 0, 6.28318, 'positive', 1)

*根据xld创建模板
create_shape_model_xld (ROI_0, 'auto',rad(-180), rad(360), 'auto', 'auto', 'ignore_local_polarity', 5, ModelID)


*获取模板轮廓
get_shape_model_contours (ModelContours, ModelID, 1)

*模板匹配
find_shape_model (Image00228, ModelID,rad(-180), rad(360), 0.5, 30, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)

if( |Row|>0 )

dev_display (Image00228)
disp_message (WindowHandle, '零件个数=' + |Row|, 'window', 50, 50, 'black', 'true')
dev_display_shape_matching_results (ModelID, 'red', Row, Column, Angle, 1, 1, 0)

else
disp_message (WindowHandle, '一个都没有找到!', 'window', 50, 50, 'black', 'true')
endif


disp_continue_message (WindowHandle, 'black', 'true')
stop()

 

*第二种方法:用图像轮廓去匹配图像

dev_clear_window ()
dev_display (Image00228)
gen_circle (ROI_0, 232.275, 480.52, 35.9315)
reduce_domain (Image00228, ROI_0, ImageReduced)
create_shape_model (ImageReduced, 'auto', rad(-180), rad(360), 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID1)
get_shape_model_contours (ModelContours1, ModelID1, 1)
find_shape_model (Image00228, ModelID1, rad(-180), rad(360), 0.5, 30, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle1, Score1)
if( |Row1| > 0 )
dev_display_shape_matching_results (ModelID1, 'red', Row1, Column1, Angle1, 1, 1, 0)
endif

posted on 2016-06-29 14:51  LongHuaiYu  阅读(355)  评论(0编辑  收藏  举报