Halcon 曲线宽度检测算法总结 | 您所在的位置:网站首页 › 如何测量弧形的长度和宽度 › Halcon 曲线宽度检测算法总结 |
视觉检测中,直线的宽度很好检测,即两条平行线的垂直距离,而曲线的宽度检测则需要另辟蹊径。 检测图像中曲线边缘的宽度,用以判断边缘是否崩缺,总结如下五种方法: 1.图像匹配判断概述:建立标准图像参考,通过比对检测结果。 核心算子: (1)参考:align_bead; (2)检测:apply_bead_inspection_model; 参考Halcon例程:apply_bead_inspection_model.hdev。 该方法较适用于胶水检测,因为无法方便地获取崩缺的值,因而弃用,但具有参考价值,建议学习。 2.点到轮廓的距离概述:通过二值化提取Border(边缘),提取其中一条边缘的点阵,计算该点阵的所有点到另一条边缘的距离。 核心算子: (1)获取边缘上的点阵:get_contour_xld(Contour : : : Row, Col); (2)计算点阵到边缘的距离:distance_pc(Contour : : Row, Column : DistanceMin, DistanceMax) 参考Halcon例程:distance_pc.hdev。 参考代码: *二值化找Border threshold_sub_pix(ImageReducedM1,Border, 130) count_obj(Border,Number) *创建数组,按长度拍排序Border LengthTuple:=[] for i:=1 to Number by 1 select_obj (Border, ObjectSelected, i) length_xld(ObjectSelected,length) LengthTuple:=[LengthTuple,length] endfor tuple_sort_index(LengthTuple,Indices) *找出两条最长的轮廓 if(|Indices|>1) select_obj(Border,MaxXLD,Indices[|Indices|-1]+1) select_obj(Border,NextXLD,Indices[|Indices|-1-1]+1) else return() endif *获取最长轮廓的点阵 get_contour_xld(MaxXLD, Rows1, Columns1) *计算点阵到另一个轮廓的距离 distance_pc(NextXLD,Rows1, Columns1, DistanceMin, DistanceMax)注意:算子 distance_pc 输出两个数组,分别为最小距离数组,最大距离数组,取值时应取最小距离数组。 3.轮廓与轮廓的距离概述:通过二值化提取一对Contours(轮廓),计算两条轮廓之间的距离。 核心算子: (1)计算轮廓之间的距离:distance_contours_xld(ContourFrom, ContourTo : ContourOut : Mode : ); (2)获取宽度值集合:get_contour_attrib_xld(Contour : : Name : Attrib); (3)提取OK/NG片段:segment_contour_attrib_xld(Contour : ContourPart : Attribute, Operation, Min, Max : ) 参考Halcon例程: (1)inspect_frame_width.hdev; (2)Apply_distance_transform_xld.hdev。 参考代码: *测量两条曲线之间的宽度 distance_contours_xld (MaxXLD, NextXLD, ContourOut, 'point_to_segment') get_contour_attrib_xld (ContourOut, 'distance', Distance) *提取测量宽度集中合规的部分 segment_contour_attrib_xld (ContourOut, ContourPart, 'distance', 'and', 10, 26) display_result (MaxXLD, NextXLD, ContourPart) *取最大值 tuple_max (Distance, WidthMax) tuple_min (Distance, WidthMin) 4.提取骨架测量宽度概述:提取曲线的中心骨架,再通过骨架测量曲线宽度。 核心算子: (1)计算lines_gauss算子所需输入参数:calculate_lines_gauss_parameters( : : MaxLineWidth, Contrast : Sigma, Low, High); (2)检测骨架及其宽度:lines_gauss(Image : Lines : Sigma, Low, High, LightDark, ExtractWidth, LineModel, CompleteJunctions : )。 参考Halcon例程: (1)angio.hdev; (2)lines_gauss.hdev。 5.极坐标展开曲线图像概述:将曲线图像按极坐标展开,检测展开后的图像,再将结果图像恢复直角坐标图像。 核心算子: (1)图像转极坐标:polar_trans_image; (2)图像转直角坐标:polar_trans_region_inv。 参考Halcon例程: (1)ocr_cd_print_polar_trans.hdev; (2)vessel.hdev。 |
CopyRight 2018-2019 实验室设备网 版权所有 |