示例程序的图像处理思路

检测任务
点胶检查检测以下缺陷:
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了啦。
点胶质量检测代码及解析
在本例中,图片矫正使用平面可变形匹配。
dev_update_off ()
首先使用仿射变换将图片转正,之后创建平面可变形模模板
这一步就是为了让每次处理的图片一致性好。
prepare_alignment (regionpart, rowt, columnt, modelid)
求取检测区域的最小矩形,这样的好处是只对需要进行图像处理的区域进行处理,使算法速度增加。
smallest_rectangle1 (regionpart, partrow1, partcolumn1, partrow2, partcolumn2)
定义点胶轨迹的参考路径
//这里使用轨迹点集创建点胶轨迹,也可以通过在参考图像上绘制该路径来生成,例如使用算子draw_nurbs.
gen_contour_nurbs_xld (contourref, [701.767,626.953,538.867,443.54,390.447,360.28,354.247,363.9,400.1,458.02,509.907,588.34,659.533,696.94], [319.24,336.133,367.507,431.46,489.38,546.093,646.247,722.267,776.567,826.04,869.48,912.92,934.64,929.813], ‘auto’, [15,15,15,15,15,15,15,15,15,15,15,15,15,15], 3, 1, 5)
定义点胶轨迹模板创建变量
targetwidth := 14
widthtolerance := 7
positiontolerance := 30
polarity := ‘dark’
创建点胶轨迹模板
//参数说明:参考轮廓(contourref);胶轨迹标准宽度(targetwidth);胶轨迹宽度误差大小(widthtolerance);胶轨迹宽所在的区域范围(positiontolerance);胶轨迹颜色(polarity);进行处理的sigma与阈值([], []);创建出的模板(beadinspectionmodel)
create_bead_inspection_model (contourref, targetwidth, widthtolerance, positiontolerance, polarity, [], [], beadinspectionmodel)
读入图片进行显示点胶轨迹、描述信息等
read_image (image, ‘bead/adhesive_bead_01’)
矫正图像,使图像与之前的图像保持较好的一致性
align_bead (image, imagealigned, modelid, rowt, columnt) //校正
创建两个平行轮廓,用于显示正确点胶轨迹的宽度,并将两个轮廓合并到一个变量中
gen_parallel_contour_xld (contourref, modelside1, ‘regression_normal’, targetwidth * 0.5)
gen_parallel_contour_xld (contourref, modelside2, ‘regression_normal’, -targetwidth * 0.5)
concat_obj (modelside1, modelside2, modelsides)
创建两个平行轮廓,用于显示正确点胶轨迹容许范围,并将两个轮廓合并到一个变量中
gen_parallel_contour_xld (contourref, positiontoleranceside1, ‘regression_normal’, positiontolerance)
gen_parallel_contour_xld (contourref, positiontoleranceside2, ‘regression_normal’, -positiontolerance)
concat_obj (positiontoleranceside1, positiontoleranceside2, positiontolerancesides)
halcon显示操作相关操作
dev_close_window ()
dev_open_window_fit_size (0, 0, partcolumn2 - partcolumn1 + 1, partrow2 - partrow1 + 41, -1, -1, windowhandle)
set_display_font (windowhandle, 16, ‘mono’, ‘true’, ‘false’)
dev_set_part (partrow1 - 20, partcolumn1, partrow2 + 20, partcolumn2)
dev_display (imagealigned)
dev_set_line_width (2)
dev_set_color (‘green’)
dev_display (contourref) //粘合胶条的参考路径
dev_set_line_width (1)
dev_display (modelsides) //胶条的宽度
dev_set_color (‘yellow’)
dev_display (positiontolerancesides) //容许点胶范围
显示描述文本
message := ‘correct adhesive bead and the reference contour. the’
message[1] := ‘yellow contours indicate the range of position tolerance.’
disp_message (windowhandle, message, ‘window’, 12, 12, ‘black’, ‘true’)
disp_continue_message (windowhandle, ‘black’, ‘true’)
stop ()
*
开始读入图片进行检测
textoffset := 20 //偏移值
numimages := 7
for index := 1 to numimages by 1
read_image (image, ‘bead/adhesive_bead_’ + index$‘02’)
矫正图片
align_bead (image, imagealigned, modelid, rowt, columnt)
使用之前生成的点胶轨迹模板,进行点胶轨迹检测
//参数说明:进行检测的图像(imagealigned);胶轨迹左轮廓(leftcontour);胶轨迹右轮廓(rightcontour);胶轨迹宽缺陷所在位置(errorsegment);使用的模板(beadinspectionmodel);缺陷种类(errortype)
apply_bead_inspection_model (imagealigned, leftcontour, rightcontour, errorsegment, beadinspectionmodel, errortype)
显示点胶轨迹,检测结果等相关信息
dev_display (imagealigned)
dev_set_line_width (1)
dev_set_color (‘white’)
dev_display (contourref)
dev_display (modelsides)
dev_display (positiontolerancesides)
dev_set_line_width (2)
dev_set_color (‘green’)
dev_display (leftcontour) //检测出的内部xld
dev_display (rightcontour) //检测出的外部xld
dev_set_color (‘red’)
dev_display (errorsegment) //错误部分区域
if (|errortype| == 0)
没有错误信息,显示ok
message := ‘adhesive bead is ok’
disp_message (windowhandle, message, ‘window’, 12, 12, ‘white’, ‘forest green’)
disp_continue_message (windowhandle, ‘black’, ‘true’)
stop ()
else
有错误信息,显示not ok,并且显示缺陷种类,标识缺陷位置
message[0] := ‘adhesive bead is not ok:’
errorclasses := [‘no bead’,‘too thin’,‘too thick’,‘incorrect position’]
for classindex := 0 to |errorclasses| - 1 by 1
class := errorclasses[classindex]
errorindices := find(errortype,class)
if (errorindices != -1)
select_obj (errorsegment, selectedsegments, errorindices + 1)
dev_set_color (‘red’)
dev_set_line_width (3)
if (class != ‘no bead’)
gen_display_segments (selectedsegments, leftcontour, rightcontour, errorparts)
dev_display (errorparts)
else
dev_display (selectedsegments)
endif
area_center_points_xld (selectedsegments, area, row, column)
for e := 0 to |errorindices| - 1 by 1
disp_message (windowhandle, errorindices[e] + 1, ‘image’, row[e], column[e] - textoffset, ‘white’, ‘red’)
textoffset := 20 - textoffset
endfor
endif
endfor
disp_message (windowhandle, message, ‘window’, 12, 12, ‘white’, ‘red’)
disp_message (windowhandle, [1:|errortype|] + ': ’ + errortype, ‘image’, 500, 500, ‘red’, ‘false’)
if (index < numimages)
disp_continue_message (windowhandle, ‘black’, ‘true’)
stop ()
endif
endif
endfor
释放所有模板句柄
clear_bead_inspection_model (beadinspectionmodel)
clear_deformable_model (modelid)
图示处理思路
1、使用符合要求图像,创建模板
2、读入新图像,矫正图像(图像仿射变换)
矫正前图像:
矫正后图像:
3、使用创建的模板检测点胶轨迹,得到结果


衰减网络的计算
世强电讯启动NEC电子Minicube2让利风潮
光电效应的基本原理是什么 光电效应的发展历程
电子计数式频率计原理 看门狗端口中断实现计数电路功能
ARM I2C 总线接口的寄存器设置
示例程序的图像处理思路
全球GPU呈现“一超一强”竞争格局
Apollo 3.0开发者技术沙龙干货要点
东山精密拟出售显示及触控面板业务
如何利用物联网技术帮助拯救濒危动物
数据压缩算法计算步骤及过程
虹科新品 | 虹科eCap性能传感器帮您优化生产线效率与性能
温度补偿功能的新型实时时钟电路
德索讲解fakra连接器特点以及应用
E6500电能质量分析仪和红外热像仪的应用及不足之处分析
Genesys和谷歌团队结合驱动人工智能体验
电容滤波的解析与EMC整改建议
PCB设计中常见的8大误区
华为Mate50系列实现卫星双向通信,向上捅破天的技术独领风骚
食品重金属快速检测仪器的功能特点说明