halcon 创建模板
1、先用摄像头读取一张图片
2、在图片上画出模板
3、连续读取图片,进行模板匹配
dev_close_window ()
* Image Acquisition 01: Code generated by Image Acquisition 01
open_framegrabber ('GigEVision2', 0, 0, 0, 0, 0, 0, 'progressive', -1, 'default', -1, 'false', 'default', 'b0b35368a72b_GEV_MVCS00410GM', 0, -1, AcqHandle)
grab_image_start (AcqHandle, -1)
*读取图像并获取其宽高
grab_image_async (Image, AcqHandle, -1)
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
* median_image (Image, ImageMedian, 'circle', 6, 'mirrored')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle1)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Image)
draw_rectangle1 (WindowHandle1, Row11, Column11, Row2, Column2)
gen_rectangle1 (Rectangle, Row11, Column11, Row2, Column2)
* gen_rectangle1 (Rectangle, 30, 20, 100, 200)
dev_display(Rectangle)
reduce_domain (Image, Rectangle, ImageReduced)
dev_open_window (0, 800, 512, 512, 'black', WindowHandle)
dev_set_color ('yellow')
dev_display (ImageReduced)
*创建模板
inspect_shape_model (ImageReduced, ModelImages, ModelRegions, 4, 30)
dev_display (ModelImages)
area_center (ModelRegions, Area, Row, Column)
count_obj (ModelImages, Number)
for i:=1 to Number by 1
if(Area[i-1]>=15)
Number:=i
endif
endfor
* create_shape_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 'auto', 'ignore_global_polarity', 'auto', 'auto', ModelID)
* create_shape_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
create_ncc_model (ImageReduced, 'auto', -0.39, 0.79, 'auto', 'use_polarity', ModelID)
* get_shape_model_contours (ModelContours, ModelID, 1)
dev_open_window (0, 800, 512, 512, 'black', WindowHandle)
while (true)
grab_image_async (Image, AcqHandle, -1)
dev_display (Image)
* find_shape_model (Image, ModelID, -0.39, 0.79, 0.5, 1, 0.5, 'least_squares', 0, 0.5, Row3, Column3, Angle, Score)
find_ncc_model (Image, ModelID, -0.39, 0.79, 0.8, 1, 0.5, 'true', 0, Row3, Column3, Angle, Score)
if(Score>0)
set_tposition (WindowHandle, Row3, Column3)
set_font (WindowHandle, '微软雅黑'+'-Normal-34')
write_string (WindowHandle, Score)
endif
if(Score>0.5)
vector_angle_to_rigid (Row3, Column3, Angle, Row3, Column3, Angle, HomMat2D)
* affine_trans_contour_xld (ModelContours, ContoursAffineTrans, HomMat2D)
gen_rectangle2 (Rectangle1, Row3, Column3, Angle, 100, 20)
dev_set_draw ('margin')
* dev_display (ContoursAffineTrans)
dev_set_color ('red')
dev_display (Rectangle1)
endif
endwhile
close_framegrabber (AcqHandle)
clear_shape_model (ModelID)