图片中的芯片会发送位置变换,需要检测芯片的针脚数量是否缺少,芯片的每一根针脚宽度是否达到要求。图像如下:
- * 读取文件夹中的图像,模拟相机采集
- list_files ('D:/File/c# code/ce liang/bin/Debug/图像', ['files','follow_links'], ImageFiles)
- tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
- for Index := 0 to |ImageFiles| - 1 by 1
- read_image (ImageCheck, ImageFiles[Index])
- get_image_size (ImageCheck, Width, Height)
- *进行模板匹配
- find_shape_model (ImageCheck, ModelID, rad(0), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9,RowCheck, ColumnCheck, AngleCheck, Score)
- *仿射变换,匹配成功才进行
- if (|Score| > 0)
- *匹配
- hom_mat2d_identity (HomMat2DIdentity)
- hom_mat2d_translate (HomMat2DIdentity, RowCheck, ColumnCheck, HomMat2DTranslate)
- hom_mat2d_rotate (HomMat2DTranslate, AngleCheck, RowCheck, ColumnCheck, HomMat2DRotate)
- *变换模板轮廓
- affine_trans_contour_xld (ModelContours, ShapeModelTrans, HomMat2DRotate)
- dev_display (ShapeModelTrans)
- *转换绘制的两个矩形的点
- affine_trans_pixel (HomMat2DRotate, rectRow2, rectColumn2, Rect1RowCheck, Rect1ColCheck)
- affine_trans_pixel (HomMat2DRotate, rectRow3, rectColumn3, Rect2RowCheck, Rect2ColCheck)
- *根据转换后位置生成两个测量矩形
- gen_rectangle2 (Rectangle1Check, Rect1RowCheck, Rect1ColCheck, AngleCheck, rect1Width, rect1Height)
- gen_rectangle2 (Rectangle2Check, Rect2RowCheck, Rect2ColCheck, AngleCheck, rect2Width, rect2Height)
- dev_set_color ('blue')
- dev_set_draw ('margin')
- dev_set_line_width (3)
- dev_display (Rectangle1Check)
- dev_display (Rectangle2Check)
- count_seconds (S1)
- gen_measure_rectangle2 (Rect1RowCheck, Rect1ColCheck, AngleCheck, rect1Width, rect1Height, Width, Height, 'bilinear', MeasureHandle1)
- gen_measure_rectangle2 (Rect2RowCheck, Rect2ColCheck, AngleCheck, rect2Width, rect2Height, Width, Height, 'bilinear', MeasureHandle2)
- *测量,使用测量队模式,将一组边缘作为一对
- measure_pairs (ImageCheck, MeasureHandle1, 3, 99, 'positive', 'all', RowEdgeFirst1, ColumnEdgeFirst1, AmplitudeFirst1, RowEdgeSecond1, ColumnEdgeSecond1, AmplitudeSecond1, IntraDistance1, InterDistance1)
- measure_pairs (ImageCheck, MeasureHandle2, 3, 99, 'positive', 'all', RowEdgeFirst2, ColumnEdgeFirst2, AmplitudeFirst2, RowEdgeSecond2, ColumnEdgeSecond2, AmplitudeSecond2, IntraDistance2, InterDistance2)
- close_measure (MeasureHandle1)
- close_measure (MeasureHandle2)
- count_seconds (S2)
- dev_set_color ('red')
- *画线对,把测量到的边缘绘制显示
- disp_line (WindowHandle, RowEdgeFirst1 - rect1Height * cos(AngleCheck), ColumnEdgeFirst1 - rect1Height * sin(AngleCheck), RowEdgeFirst1 + rect1Height * cos(AngleCheck), ColumnEdgeFirst1 + rect1Height * sin(AngleCheck))
- disp_line (WindowHandle, RowEdgeSecond1 - rect1Height * cos(AngleCheck), ColumnEdgeSecond1 - rect1Height * sin(AngleCheck), RowEdgeSecond1 + rect1Height * cos(AngleCheck), ColumnEdgeSecond1 + rect1Height * sin(AngleCheck))
- disp_line (WindowHandle, RowEdgeFirst2 - rect2Height * cos(AngleCheck), ColumnEdgeFirst2 - rect2Height * sin(AngleCheck), RowEdgeFirst2 + rect2Height * cos(AngleCheck), ColumnEdgeFirst2 + rect2Height * sin(AngleCheck))
- disp_line (WindowHandle, RowEdgeSecond2 - rect2Height * cos(AngleCheck), ColumnEdgeSecond2 - rect2Height * sin(AngleCheck), RowEdgeSecond2 + rect2Height * cos(AngleCheck), ColumnEdgeSecond2 + rect2Height * sin(AngleCheck))
- dev_set_line_width (1)
- *测量时间
- time:=S2-S1
- *针脚大小判断
- distance_threshold:=10.5
- wrongdistance:=[]
- wrongRow:=[]
- wrongCol:=[]
- *从第一个测量矩形判断,判断每一个针脚的宽度是否符合要求,将不符合要求的针脚边缘中心的坐标保存
- for Index1 := 0 to |IntraDistance1|-1 by 1
- if(IntraDistance1[Index1]
- wrongRow:=[wrongRow,RowEdgeFirst1[Index1]]
- wrongCol:=[wrongCol,ColumnEdgeFirst1[Index1]]
- *将缺陷距离保存
- wrongdistance:=[wrongdistance,IntraDistance1[Index1]]
- endif
- endfor
- *判断第二个测量矩形的结果
- for Index2 := 0 to |IntraDistance2|-1 by 1
- if(IntraDistance2[Index2]
- wrongRow:=[wrongRow,RowEdgeFirst2[Index2]]
- wrongCol:=[wrongCol,ColumnEdgeFirst2[Index2]]
- *将缺陷距离保存
- wrongdistance:=[wrongdistance,IntraDistance2[Index2]]
- endif
- endfor
- *针脚总数计算
- set_display_font (WindowHandle, 10, 'mono', 'true', 'false')
- NumLeads := |IntraDistance1| + |IntraDistance2|
- *显示结果模块
- if (NumLeads<28)
- disp_message (WindowHandle, '缺少针脚', 'window', 20, 20, 'red', 'false')
- elseif (|wrongRow|>0)
- dev_set_draw ('margin')
- dev_set_color ('red')
- dev_clear_window ()
- dev_display (ImageCheck)
- *显示不合格的针脚
- for Index3 := 0 to |wrongRow|-1 by 1
- disp_circle (WindowHandle, wrongRow[Index3], wrongCol[Index3], 6.0)
- disp_message (WindowHandle, wrongdistance[Index3]$'.2f', 'window', wrongRow[Index3]-30, wrongCol[Index3]-50, 'black', 'true')
- endfor
- disp_message (WindowHandle, '针脚有缺陷', 'window', 20, 20, 'red', 'false')
- else
- dev_set_color ('green')
- disp_message (WindowHandle, '图像OK,针脚数:'+NumLeads, 'window', 20, 20,'green', 'true')
- endif
- stop()
- * Image Acquisition 01: Do something
- endif
- endfor
三,检测示意图
最后的检测效果如下,左上角显示检测结果。
结语
在本专栏下一篇文章中,将实现halocn代码的导出,和c#软件界面的搭建。
这里是图像文件和halcon的源码
链接:https://pan.baidu.com/s/1MhI64rQA2GAIIjdMZ7R8iw
提取码:wtu2
链接:https://pan.baidu.com/s/119fA7JdX_Hgh-GyMIvBC5w
提取码:7f2q
-
相关阅读:
frida打印byte数组
05※、Map集合介绍、HashMap、Hashtable、LinkedHashMap、Properties和Collections
【快手小玩法-弹幕游戏】开发者功能测试报告提交模板
Educational Codeforces Round 115 (Rated for Div. 2)
动态规划求解最大子段和 (两种写法+还原最优解)
AndroidStudio 新建工程的基本修改及事件添加
从指定 URL 读取图像并以 OpenCV 格式返回的函数(从指定 URL 读取图像并使其可由 OpenCV 处理。)
SpringMVC 程序开发
WorldPop2000年至2020年的全中国的人口统计数据
零售业:别让数据安全成为业务的绊脚石!(附文件下载)
-
原文地址:https://blog.csdn.net/uiopmn1/article/details/126051493