简单算法识别胶水不足的情况.
dev_set_draw (‘margin’)
dev_set_line_width (3)
dev_set_color (‘green’)
dev_get_window (WindowHandle)
set_system (‘filename_encoding’, ‘utf8’)
list_files (‘胶水污染残缺’, [‘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])
decompose3 (Image, R, G, B)
sub_image (R, B, ImageSub, 1, 128)
//提取底板有效区域
median_image (B, ImageMedian, ‘circle’, 3, ‘mirrored’)
fast_threshold (ImageMedian, Region2, 128, 255, 20)
fill_up (Region2, RegionFillUp2)
opening_circle (RegionFillUp2, RegionOpening2, 3.5)
connection (RegionOpening2, ConnectedRegions3)
select_shape_std (ConnectedRegions3, SelectedRegions2, ‘max_area’, 70)
shape_trans (SelectedRegions2, RegionTrans, ‘rectangle1’)
erosion_rectangle1 (RegionTrans, RegionErosion, 51, 101)
//提取底板有效区域
fast_threshold (ImageMedian, Region, 0, 180, 2)
opening_circle (Region, RegionOpening, 3.5)
// fill_up (RegionOpening, RegionFillUp)
connection (RegionOpening, ConnectedRegions)
intersection (ConnectedRegions, RegionErosion, RegionIntersection)
connection (RegionIntersection, ConnectedRegions4)
fill_up (ConnectedRegions4, RegionFillUp3)
opening_circle (RegionFillUp3, RegionOpening3, 3.5)
connection (RegionOpening3, ConnectedRegions5)
select_shape (ConnectedRegions5, SelectedRegions, ['orientation','width','contlength','roundness'], 'and', [-1.9487,90,1000,0.05677], [2.9087,1034,4339.59,0.58])sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'row')
count_obj (SortedRegions, Number)
胶水提取
emphasize (ImageSub, ImageEmphasize, 15, 15, 1)
fast_threshold (ImageEmphasize, Region1, 140, 255, 5)
connection (Region1, ConnectedRegions1)
opening_circle (ConnectedRegions1, RegionOpening1, 3.5)
closing_circle (RegionOpening1, RegionClosing, 8.5)
fill_up (RegionClosing, RegionFillUp1)
connection (RegionFillUp1, ConnectedRegions2)
inner_circle (ConnectedRegions2, Row, Column, Radius)
gen_circle (Circle, Row, Column, Radius)
select_shape (Circle, SelectedRegions1, 'max_diameter', 'and', 280, 752)
sort_region (SelectedRegions1, SortedRegions1, 'character', 'true', 'row')
count_obj (SortedRegions1, Number1)dev_set_color ('green')for k:=0 to Number-1 by 1select_obj(SortedRegions,obj1,k+1)area_center (obj1, Area1, Row1, Column1)if(k+1<Number1)select_obj(SortedRegions1,ojb2,(k+1))endifintersection ( obj1,ojb2, RegionIntersection1)area_center (RegionIntersection1, Area, Row1, Column1)if(Area>1)dev_set_color ('green')elsedev_set_color ('green')dev_set_draw ('margin')dev_display (Image)dev_display (SortedRegions1)dev_set_color ('red')dev_set_line_width (10)shape_trans (obj1, RegionTrans1, 'rectangle1')area_center (RegionTrans1, Area2, Row2, Column2)disp_message (WindowHandle, 'find area glue is small or nothing ,NG', 'image', Row2, Column2-800, 'red', 'true')endifendforstop()
endfor
这个一类的算法都有一个通用性.图像的预处理,分割,筛选,得到满足条件的区域或xld
方法都是大同小异.