玻璃瓶口缺陷检测

在网上看到有几张个瓶口缺陷的图片拿来练练手,先上原图





这几张应该是都有缺陷的,特别是第一张缺口不明显只有口边有黑色区域

下面是我的检测程序:

dev_close_window ()
* read_image (Image, 'C:/Users/liuhang/Desktop/瓶口缺陷检测/爆口.bmp')
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('C:/Users/liuhang/Desktop/瓶口缺陷检测', ['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])
    * Image Acquisition 01: Do something
    get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width/2.5, Height/2.5, 'black', WindowHandle)
dev_display (Image)
* threshold_sub_pix (Image, Border, 128)
edges_sub_pix (Image, Edges, 'canny', 0.5, 20, 40)
segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
select_shape_xld (ContoursSplit, SelectedXLD, 'contlength', 'and', 100, 5000)
union_cocircular_contours_xld (SelectedXLD, UnionContours, 0.25, 0, 0.2, 50, 20, 20, 'true', 2)
select_shape_xld (UnionContours, SelectedXLD1, 'circularity', 'and', 0.9, 1)
dev_clear_window ()
dev_display (Image)
dev_display (SelectedXLD1)
fit_circle_contour_xld (SelectedXLD1, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
sort_contours_xld (ContCircle, SortedContours, 'upper_left', 'true', 'row')
* select_shape_xld (SelectedXLD1, SelectedXLD2, 'contlength', 'and', 1200, 99999)
* select_contours_xld (Edges, SelectedContours, 'contour_length', 20, 500, 0, 0
* Number:=|Row|
select_obj (SortedContours, ObjectSelected, 1)
gen_region_contour_xld (ObjectSelected, Region, 'filled')  
reduce_domain (Image, Region, ImageReduced)
scale_image (ImageReduced, ImageScaled, 0.2, 2)
threshold (ImageScaled, Region1, 40, 80)
connection (Region1, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 15500, 40000)
select_shape (SelectedRegions, SelectedRegions1, 'max_diameter', 'and', 500, 700)
dev_clear_window ()
dev_set_color ('green')
dev_display (Image)
dev_display (SelectedRegions1)
stop ()
endfor

运行效果如下:



        开始我是打算找黑色的缺陷区域作为判断条件,后面发现干扰比较多不好提,转而找白色区域,如结果图。但是发现精准度不好,面积判断条件不好把控,如原图1中就是有缺陷的,口边有黑色区域但是白色部分跟正常的瓶口区别不大, 而且小的缺陷也不好剔除。各位有什么好的方法,指导一下吧,谢谢大家!!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沐细雨如春风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值