视觉检测之焊点检测(八):固定ROI焊点检测的方法


这种方式比较简单,条件是你的焊点位置比较固定。

这时候我们可以按焊点数量做几个固定的ROI区域,在reduce_domain。剩下的不用说大家也知道怎么玩了。

如果有深度学习就好了,否则也不会出此下策,这实在不是什么好办法。

此种方式让勇哥联想到当年用printf("    *    ")打印金字塔图形的那种办法。


为什么焊点会出现色阶分布不均匀的效果呢?

这是因为打焊点的时候,由于两个焊片贴合得不平整,或者是激光能量不稳定造成的。

image.png


Row1:=928.934
Column1:=1280.83
Row2:=982.723
Column2:=1453.5
*read_image(Image, 'C:/Users/hackpig/Desktop/图片/图片/上焊点OK图片/DAB43671DB5_16_39_36.jpg')  
*draw_rectangle1(200000, Row1, Column1, Row2, Column2)
list_files ('C:/Users/hackpig/Desktop/图片/图片/上焊点OK图片', ['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 (Image, ImageFiles[Index])
    index:=0  //不为1则为上焊点,否则为下焊点

    roix1:= Row1 
    roix2:=Row2 
    roiy1:= Column1
    roiy2:=Column2 
    widthSpan:=  60
    circleradius:=  24
    
    bottomThreHold:=240
    
    width1:=roiy2-roiy1
    widthSpan:=width1/3
    
    gen_empty_obj(roi)
    
    for i:=0 to 3 by 1
        gen_circle(Circle, roix1, roiy1+i*widthSpan,circleradius)
        union2(roi, Circle, roi)
    endfor
    for i:=0 to 3 by 1
        gen_circle(temp, roix2, roiy1+i*widthSpan,circleradius)
        union2(roi, temp, roi)
    endfor
    
  
    //如果阴影区域面积大于一定值,就认为有折痕
    rugateMinArea:=9000
    rugateNG:=true
    gen_rectangle1(Rectangle, Row1-10, Column1-10, Row2+10, Column2+10)
    reduce_domain(Image, Rectangle, roiRugate)
    threshold(roiRugate, Region, 0, bottomThreHold)
    connection(Region, ConnectedRegions)
    union1(ConnectedRegions, RegionUnion)
    area_center(RegionUnion, Area, Row, Column)
    if (Area[0]>rugateMinArea)
        rugateMinArea:=true
    else
        rugateMinArea:=false
    endif
    
 
     //如果小于一定阈值,则认为黑色区域偏多,可能出现双TOC
    doubleTcoNg:=false
    maxAvgeGray:=215
    visionUpThreshold:=205
    visionBottomThreshold:=240
    selectShapeMin:=1
    selectShapeMax:=10000
    gen_rectangle1(Rectangle1, Row1-50, Column1-50, Row2+50, Column2+50)
    reduce_domain(Image, Rectangle1, ImageReduced)
    intensity(ImageReduced, Image, Mean, Deviation)
    if(Deviation[0]<maxAvgeGray)
        doubleTcoNg:=true
    else
        doubleTcoNg:=false
    endif
    
     dev_set_draw('fill')
    get_image_size(Image, Width, Height)
    reduce_domain(Image, roi, ImageReduced1)
    bin_threshold(ImageReduced1, Region1)
    
    if(index#1)
        threshold(ImageReduced1, Region2, 0, visionUpThreshold)
    else
        threshold(ImageReduced1, Region2, 0, visionBottomThreshold)
    endif
    closing_circle(Region2, RegionClosing, 4)
    fill_up(RegionClosing, RegionFillUp)
    connection(RegionFillUp, ConnectedRegions1)
    count_obj(ConnectedRegions1, Number)
    erosion_circle(ConnectedRegions1, RegionErosion, 1.5)
    select_shape(RegionErosion, SelectedRegions, 'area', 'and',50, 99999)
    count_obj(SelectedRegions, Number1)
    area_center(SelectedRegions, Area1, Row3, Column3)
    smallest_circle(SelectedRegions, Row4, Column4, Radius)
    if(|Radius|>0)
       dev_set_draw('fill')
        dev_set_line_width(1)
        dev_set_color('green')
*         if(rugateNG=true or doubleTcoNg=true)
*             dev_set_color('red')
*             write_string(200000, '怀疑极片褶皱')
*         endif
        dev_disp_text(Number1, 'window', 214, 238, 'black', 'box', 22)
        dev_set_color('green')
        disp_obj(ConnectedRegions1,200000)
        dev_set_draw('margin')
        dev_set_color('blue')
        dilation_circle(SelectedRegions,RegionDilation, 12)
        disp_obj(RegionDilation, 200000)
    endif
    stop()
endfor

--------------------- 

作者:hackpig
来源:
www.skcircle.com
版权声明:本文为博主原创文章,转载请附上博文链接!


本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年4月    »
1234567
891011121314
15161718192021
22232425262728
2930
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864