*关闭窗口
dev_close_window ()
*读取图像
read_image (Image, 'D:/程序猿/Halcon/Halcon练习/个人练习/图像匹配/board-01.png')
*获取图像大小
get_image_size (Clip, Width, Height)
*打开新窗口
dev_open_window (0, 0, Width / 2, Height / 2, 'black', WindowID)
*在新窗口里显示图像
dev_display (Clip)
*设置窗口字体显示,字体大小,字体样式,粗体,斜体
set_display_font (WindowID, 14, 'mono', 'true', 'false')
*停止程序的执行
stop ()
*显示图像
dev_display (Clip)
*设置输出对象的颜色为绿色
dev_set_color ('green')
*显示过滤后的区域
dev_display (Selected)
*获取过滤后区域的方向
orientation_region (Selected, Phi)
*获取过滤后区域的面积,中心的行坐标,列坐标
area_center (Selected, Area, Row, Column)
*设置输出对象的线宽为3
dev_set_line_width (3)
*设置区域的填充方式
dev_set_draw ('margin')
Length := 80
*设置输出对象的颜色为蓝色
dev_set_color ('blue')
*在窗口上显示十字
disp_arrow (WindowID, Row, Column, Row - Length * sin(Phi), Column + Length * cos(Phi), 4)
*在窗口上显示文字
disp_message (WindowID, '左', 'window', 12, 12, 'red', 'true')
*灰度化
rgb1_to_gray(Image,GrayImage)
*预处理R/GB H/S/V分量
decompose3 (Image, R, G, B)
trans_from_rgb (R, G, B, H, S, V, 'hsv')
*阈值操作
threshold (Saturation, Regions, 182, 255)
*剪切ROI区域的图像
reduce_domain (Image, SelectedRegions, ImageReduced)
*获取区域轮廓
get_shape_model_contours (ModelContours, ModelID, 1)
*获取最大面积区域
select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)
*联通区域
connection (Regions, ConnectedRegions)
*创建一个矩形ROI
gen_rectangle1 (Rectangle, 362, 212, 414, 262)
*填充过滤后区域里的内部间隙
fill_up (SelectedRegions, RegionFillUp)
*将填充区域形状转化为凸形
shape_trans (RegionFillUp, RegionTrans, 'convex')
*获取凸形区域的边界
boundary (RegionTrans, RegionBorder, 'inner')
*对RegionBorder区域进行形态学的膨胀操作,结构元素为2.5
dilation_circle (RegionBorder, RegionDilation, 2.5)
*所有区域合并为一个区域
union1 (RegionDilation, RegionUnion)
*对ImageReduced图像进行边缘提取
edges_sub_pix (ImageReduced, Edges, 'sobel_fast', 0.5, 20, 40)
*连通处理
connection (Region, ConnectedRegions)
*根据面积过滤
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 8000, 9000)
* 用矩形结构元素膨胀
dilation_rectangle1 (SelectedRegions, RegionDilation1, 3, 3)
* 用圆形结构元素膨胀
dilation_circle (SelectedRegions, RegionDilation2, 2.5)
* 用矩形结构元素腐蚀
erosion_rectangle1 (SelectedRegions, RegionErosion1, 3, 3)
* 用圆形结构元素腐蚀
erosion_circle (SelectedRegions, RegionErosion2, 2.5)
* 用矩形结构元素开运算
opening_rectangle1 (SelectedRegions, RegionOpening1, 10, 10)
* 用圆形结构元素开运算
opening_circle (SelectedRegions, RegionOpening2, 2.5)
*用矩形结构元素闭运算
closing_rectangle1 (SelectedRegions, RegionClosing1, 10, 10)
*用圆形结构元素闭运算
closing_circle (SelectedRegions, RegionClosing2, 3.5)
算子:wait_seconds (0.5) *括号内是以秒为单位的时间单位。
*计算两条直线的距离(两个相邻区域的相同像素间的最小距离)
distance_rr_min (HoriLeftLinesMode,HoriRightLinesMode, MinDistance, Row1, Column1, Row2, Column2)