检测任务
点胶检查检测以下缺陷:
1.缺少粘合胶的部分(断胶)
2.粘合剂过多或过少的部分(溢胶、缺胶)
3.粘合胶离其预定位置太远(点胶偏移)
halcon对应示例程序:
apply_bead_inspection_model.hdev
效果图示:
检测思路
示例程序的图像处理思路:
1.使用halcon的可变形模板匹配,将检测物品转正,方便检测
这里我们用的较少,因为我们平时在做点胶检测的时候,用普通的模板匹配,还有普通的2D仿射变换就可以保证图像的一致性。
2.定义粘合胶条的参考路径,以及胶条的宽度,还有误差容忍值
注意,这里halcon的官方例程是给了一个轨迹的点集,我们在实际的检测中,可以使用CAD图纸导入或者手绘路径,完成此步骤。关于CAD图纸导入halcon我会出一期教学博客,写完了把链接贴上来。
3. 利用算子create_bead_inspection_model 创建点胶轨迹模型
创建点胶轨迹的模型,相当于我们使用模板匹配时候用到的穿件模板算子,也不难的。到第三步,我们已经完成了创建模板与点胶轨迹模型的步骤,准备工作都进行完毕,接下来就要进行检测了。
4.校正胎圈的位置,并生成四条平行轮廓,进行显示
显示一下前面准备工作的结果,包括胶轨迹的样子,可容许胶轨迹范围等。
5.读入待检测图像,并进行校正,最后利用算子apply_bead_inspection_model进行点胶轨迹检测
从这一步开始,就使用前面几部的模板,进行点胶轨迹的检测了。首先我们先把图片进行一个仿射变换,转正图片,让我们处理的点胶区域每次都保持一致。这样极大地减小了处理难度。再调用apply_bead_inspection_model进行点胶轨迹检测,就检测完成啦。是不是并不难。
6.根据不同的检测类型在窗口上进行相关显示
最后搞个交互界面显示一下结果就OK了啦。
点胶质量检测代码及解析
在本例中,图片矫正使用平面可变形匹配。
首先使用仿射变换将图片转正,之后创建平面可变形模模板
这一步就是为了让每次处理的图片一致性好。
求取检测区域的最小矩形,这样的好处是只对需要进行图像处理的区域进行处理,使算法速度增加。
定义点胶轨迹的参考路径
//这里使用轨迹点集创建点胶轨迹,也可以通过在参考图像上绘制该路径来生成,例如使用算子draw_nurbs.
定义点胶轨迹模板创建变量
创建点胶轨迹模板
//参数说明:参考轮廓(ContourRef);胶轨迹标准宽度(TargetWidth);胶轨迹宽度误差大小(WidthTolerance);胶轨迹宽所在的区域范围(PositionTolerance);胶轨迹颜色(Polarity);进行处理的sigma与阈值([], []);创建出的模板(BeadInspectionModel)
读入图片进行显示点胶轨迹、描述信息等
矫正图像,使图像与之前的图像保持较好的一致性
创建两个平行轮廓,用于显示正确点胶轨迹的宽度,并将两个轮廓合并到一个变量中
创建两个平行轮廓,用于显示正确点胶轨迹容许范围,并将两个轮廓合并到一个变量中
halcon显示操作相关操作
显示描述文本
开始读入图片进行检测
矫正图片
使用之前生成的点胶轨迹模板,进行点胶轨迹检测
//参数说明:进行检测的图像(ImageAligned);胶轨迹左轮廓(LeftContour);胶轨迹右轮廓(RightContour);胶轨迹宽缺陷所在位置(ErrorSegment);使用的模板(BeadInspectionModel);缺陷种类(ErrorType)
显示点胶轨迹,检测结果等相关信息
释放所有模板句柄
图示处理思路
1、使用符合要求图像,创建模板
2、读入新图像,矫正图像(图像仿射变换)
矫正前图像:
矫正后图像:
3、使用创建的模板检测点胶轨迹,得到结果
————————————————
本文仅做学术分享,如有侵权,请联系删文。