Halcon算子应用和技巧9

提示:若没有查找的算子,可以评论区留言,会尽快更新


前言

提示:可以使用搜索小工具搜索对应算子名称:

本篇博文主要用于记录学习Halcon中算子的应用场景,及其使用代码和图像展示。只讲通俗易懂使用方法,不讲原理,不讲原理,不讲原理,重要的事情说三遍。


提示:以下是本篇文章正文内容,下面案例可供参考,注意参数坐标的使用,能帮助你理解算子

一、Halcon应用?

Halcon 是一个强大的图像处理工具,该工具是为了解决机器视觉项目任务而创建的。

二、算子汇总

每一博文仅展示10个算子,点击此链接进行查询所有算子,并点击对应算子跳转相应博文。'
跳转链接

三、应用算子

81. binary_threshold ()

先上代码:

read_image (Image, 'D:/HALCON_learn/理论/81-90/zhizhang.png')
rgb1_to_gray (Image, GrayImage)
binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)
stop ()

解析
自动阈值分割,适用于背景和目标有明显差异的,也就是灰度直方图是双峰的。
PS:根据设定参数选择亮的区域或者暗的区域
在这里插入图片描述


82. smooth_contours_xld ()

先上代码:

read_image (Image, 'D:/HALCON_learn/理论/81-90/zhizhang.png')
rgb1_to_gray (Image, GrayImage)
binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)
dilation_circle (Region, RegionDilation, 3.5)
reduce_domain (GrayImage, RegionDilation, ImageReduced)
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
smooth_contours_xld (Edges, SmoothedContours, 9)
stop ()

解析
平滑亚像素边缘,左图原边缘,右图平滑后的边缘
PS:参数只能是奇数,参数越大,平滑越厉害,反之;一般用于产品磨边。
在这里插入图片描述


83. shape_trans_xld ()

先上代码:

read_image (Image, 'D:/HALCON_learn/理论/81-90/zhizhang2.png')
rgb1_to_gray (Image, GrayImage)
binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)
dilation_circle (Region, RegionDilation, 3.5)
reduce_domain (GrayImage, RegionDilation, ImageReduced)
edges_sub_pix (ImageReduced, Edges, 'canny', 1, 20, 40)
select_contours_xld (Edges, SelectedContours, 'contour_length', 500, 1000, -0.5, 0.5)
dev_set_color ('yellow')
shape_trans_xld (SelectedContours, XLDTrans, 'convex')
stop ()

解析
将xld形状改变,本次使用的凸包参数 ‘convex’,红色原始xld,黄色是改变后的xld
PS:你可以设定其他参数进行改变形状自行查看
在这里插入图片描述


84. threshold_sub_pix ()

先上代码:

read_image (Image, 'D:/HALCON_learn/理论/81-90/zhizhang2.png')
rgb1_to_gray (Image, GrayImage)
binary_threshold (GrayImage, Region, 'max_separability', 'light', UsedThreshold)
dilation_circle (Region, RegionDilation, 3.5)
reduce_domain (GrayImage, RegionDilation, ImageReduced)
threshold_sub_pix (ImageReduced, Border, 183)

解析:
根据设定的灰度阈值选择亚像素边缘
PS:该方法比较死板,以183为例, 该方法通过在172-190之间的灰度区域中分段,选择183灰度的区域,因为是亚像素,所以会这样分。
在这里插入图片描述


85. close_contours_xld ()

先上代码

gen_contour_polygon_xld (Contours, [50, 50, 150, 150], [50, 150, 150, 250])
gen_contour_polygon_xld (Contour2, [50, 50, 150, 150, 60], [300, 450, 450, 300, 300])
concat_obj (Contours, Contour2, Contours)
gen_contour_polygon_xld (Contour3, [200, 300, 300], [50, 50, 250])
concat_obj (Contours, Contour3, Contours)
gen_contour_polygon_xld (Contour4, [200, 200, 300, 300, 200], [320, 450, 450, 300, 300])
concat_obj (Contours, Contour4, Contours)
* 
close_contours_xld (Contours, ClosedContours)

解析
将未闭合的xld进行闭合, 左边原图, 右边闭合结果图
PS:多边形构成也是点组成,该算子就是将首尾坐标一致, 添加了一个尾坐标和首坐标一样, 所以能将xld闭合.
在这里插入图片描述


86. sort_contours_xld ()

先上代码:

read_image (Image, 'letters')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width / 2, Height / 2 + 100, 'black', WindowHandle)
dev_set_part (-100, 0, Height - 1, Width - 1)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
set_line_style (WindowHandle, [])
dev_set_color ('red')
threshold_sub_pix (Image, Edges, 128)
select_contours_xld (Edges, SelectedContours, 'contour_length', 10, 200, -0.5, 0.5)
* Sort the unsorted output:
* First sort the contours by row coordinates. The position of a
* contour is given by the upper left corner of its surrounding rectangle.
count_obj (SelectedContours, Number)
dev_set_line_width (3)
sort_contours_xld (SelectedContours, SortedContours1, 'character', 'true', 'column')
dev_display (Image)
disp_message (WindowHandle, 'XLD contours sorted by column', 'window', 12, 12, 'black', 'true')
for I := 1 to Number by 1
    select_obj (SortedContours1, ObjectSelected, I)
    dev_display (ObjectSelected)
    wait_seconds (0.01)
endfor

解析
对混乱的xld边缘进行排序,排序方式以character为例, 以xld轮廓包围矩形左上顶点进行排序, 然后for循环方便选择xld
PS: 逐步从a选择到g, 还与’column’参数有关
在这里插入图片描述


87. clip_contours_xld ()

先上代码:

read_image (Angio, 'angio-part')
get_image_size (Angio, Width, Height)
dev_open_window (0, 0, 3 * Width / 2, 3 * Height / 2, 'black', WindowID)
lines_gauss (Angio, Lines, 2.3, 0.0, 0.7, 'dark', 'true', 'parabolic', 'true')
dev_display (Angio)
dev_set_color ('yellow')
dev_display (Lines)
stop ()
Top := 200
Left := 100
Bottom := 300
Right := 200
gen_rectangle1 (Rectangle, Top, Left, Bottom, Right)
reduce_domain (Angio, Rectangle, AngioReduced)
clip_contours_xld (Lines, LinesClipped, Top, Left, Bottom, Right)

解析
裁剪出对应矩形区域内的线(xld),右图为裁剪后的结果,中间是检测的线,左图为需要的矩形区域
在这里插入图片描述


88. clip_end_points_contours_xld ()

先上代码:

dev_close_window ()
dev_open_window (0, 0, 500, 500, 'black', WindowHandle)
dev_set_part (0, 0, 499, 499)
dev_set_line_width (3)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
* Create an ellipse with a contour point distance much larger than 1.
gen_ellipse_contour_xld (EllipseContour, 250, 250, 0, 200, 100, 0, rad(180), 'positive', 3)
* Clip off contour points for a total length of 20 pixels at both ends.
clip_end_points_contours_xld (EllipseContour, ClippedContoursLength, 'length', 20)
* Clip off 20 contour points at both ends.
clip_end_points_contours_xld (EllipseContour, ClippedContoursNumPoints, 'num_points', 20)

解析
从xld两端按照指定模式将两端的xld裁剪掉,左图原图,中间裁剪length,右图裁剪point
PS: point 比 length 长一点,这是因为点与点之间有长度在
在这里插入图片描述


89. clip_region_rel ()

先上代码:

read_image (Image, 'double_circle')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
* Segment a region containing the edges
fast_threshold (Image, Region, 0, 120, 7)
boundary (Region, RegionBorder, 'inner')
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)

解析
将图像整体看作一个矩形,从该矩形的上下左右裁剪掉指定参数量的像素数,左图原region,中图为区域边界,右图为裁剪后结果
PS:适用于裁剪图像四周不需要的xld
在这里插入图片描述


90. segment_contours_xld ()

read_image (Image, 'double_circle')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
fast_threshold (Image, Region, 0, 120, 7)
boundary (Region, RegionBorder, 'inner')
clip_region_rel (RegionBorder, RegionClipped, 5, 5, 5, 5)
dilation_circle (RegionClipped, RegionDilation, 2.5)
reduce_domain (Image, RegionDilation, ImageReduced)
edges_sub_pix (ImageReduced, Edges, 'canny', 2, 20, 60)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 3)
count_obj (ContoursSplit, Number)

解析
将一根xld分割成多段,比如**‘lines_circles’**,将分割出可能的线和圆弧,左图为reduce_domain,从右图可见变为多段xld,obj从数量1变为6
PS:有时测量工件(齿轮的齿)的圆形度如何,需要该方法
在这里插入图片描述


以上内容陆续更新。。。

内容如有错误之处,望不吝指出,谢谢

以上内容陆续更新。。。

### 回答1: Halcon算子中文手册CHM是Halcon系统提供的一种在线帮助文档格式。CHM是“Compiled HTML Help”的缩写,即编译的HTML帮助文档。 Halcon算子中文手册CHM是为了方便中文用户学习和使用Halcon算子而特别准备的。它包含了Halcon算子的详细说明、用法示例以及相关函数的参数说明。通过查阅CHM手册,用户可以了解各种算子的作用、输入输出参数的含义,以及如何在Halcon中使用它们。这对于Halcon初学者来说是一个很好的学习工具。 CHM手册的使用非常简单方便,用户只需要在Halcon界面中点击相关算子的帮助按钮,就可以快速打开相应的CHM手册页面。在CHM手册页面中,用户可以通过目录、索引、搜索等方式浏览和查找需要的信息。CHM手册的页面包含了算子的详细解释和代码示例,帮助用户更好地理解和应用算子Halcon算子中文手册CHM的提供,为中文用户提供了一种方便、快捷的学习和查阅资源。它不仅节省了用户在网上搜索资料的时间,还提供了更专业、系统、全面的算子说明,从而帮助用户更加高效地使用Halcon进行图像处理和分析。无论是新手还是有一定经验的用户,都能通过CHM手册快速查找所需的信息,提升开发和应用的效率。 ### 回答2: Halcon算子中文手册CHM是一个用于参考和学习Halcon算子的详细文件。CHM是Halcon提供的一种帮助文档格式,可以在Windows操作系统上浏览和搜索。 这个中文手册提供了Halcon算子的描述、参数、使用方法以及示例代码等内容。用户可以通过搜索或按照算子分类来查找所需的算子。同时,手册还提供了算子的示例图像,帮助用户理解算子的作用和效果。 使用这个手册,用户可以更加方便地了解和学习Halcon算子。无论是初学者还是有一定经验的用户,都可以通过手册来查找所需的算子,并且了解该算子的具体用法。手册的详细信息和示例代码有助于用户更好地理解算子的功能和使用场景。 总之,Halcon算子中文手册CHM是一个非常有价值的工具,为用户提供了方便快捷的查阅方式,帮助用户学习和运用Halcon算子,提升图像处理的能力。 ### 回答3: Halcon算子中文手册CHM是Halcon软件的一个辅助文档,用于帮助用户快速查询和理解Halcon算子的使用方法和功能。CHM是一种经典的Windows帮助文档格式,可以在Windows系统上直接打开和阅读。 Halcon算子中文手册CHM包含了Halcon软件中各种不同类型的算子的详细说明和示例代码,涵盖了图像处理、机器视觉、测量、工业自动化等众多领域。用户可以根据自己的需求,通过关键字搜索或者按照分类浏览的方式找到所需的算子,并了解其参数设置和使用方法。 使用Halcon算子中文手册CHM可以帮助用户更方便地学习和掌握Halcon算子的使用技巧,从而更高效地完成图像处理和分析任务。用户可以通过手册中的示例代码了解算子的实际应用场景,并根据自己的需求进行修改和优化。 总之,Halcon算子中文手册CHM是一本非常实用的参考资料,对于使用Halcon进行图像处理的用户来说,是不可或缺的帮助工具。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值