1.运行结果
2.代码
*读取参考图像
read_image(Image, 'F:/Halcon_workstation/data/m3')
*根据要匹配的目标,围绕目标创建一个矩形,获取ROI区域
gen_rectangle1 (Rectangle, 34, 250, 200, 400)
*对ROI区域进行裁剪,得到模板图像
reduce_domain (Image, Rectangle, ImageReduced)
*测试金字塔的层级参数
inspect_shape_model (ImageReduced, ModelImages, ModelRegions, 4, 30)
*设置显示图像、绘制线条的线宽等窗口参数
dev_set_draw ('margin')
dev_set_line_width(3)
dev_display(Image)
dev_display(Rectangle)
*根据剪裁的模板图像创建基于形状的模板,返回模板句柄ShapeModelID
*create_shape_model (ImageReduced, 5, rad(-10), rad(20), 'auto', 'none', 'use_polarity', *20, 1, ShapeModelID)
*edges_image (ImageReduced, ImaAmp, ImaDir, 'canny', 1, 'nms', 20, 40)
edges_sub_pix (ImageReduced, Edges, 'canny', 1.7, 40, 120)
create_shape_model_xld(Edges, 'auto', rad(0), rad(360), 'auto', 'auto', 'ignore_local_polarity', 5, ModelID)
stop()
*读取用于测试的图像
read_image(SearchImage, 'F:/Halcon_workstation/data/m5')
*dev_open_window_fit_image(SearchImage, 0, 0, -1, -1, WindowHandle)
get_image_size(Image, Width, Height)
*打开指定窗口的大小
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
*使用匹配算子进行形状模板匹配
find_scaled_shape_models (SearchImage, ModelID, rad(-180), rad(180), 0.9, 1.1, 0.50, 6, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Scale, Score1, Model)
gen_cross_contour_xld (Cross, Row, Column, 15, Angle)
disp_cross (WindowHandle, Row, Column, 15, 0)
*disp_rectangle1 (WindowHandle, 0, 0, 100, 100)
*gen_rectangle1 (Rectangle1, Row, Column, Row, Column)
dev_display (SearchImage)
clear_shape_model (ModelID)