文章目录
- 处理要求
- 处理方法一
- 源码
- 效果
- 方法二
- 源码
- 效果
|
处理要求
查找纸箱内瓶子个数
处理方法一
源码
dev_clear_window ()
dev_open_window (0, 0, 640*1.5, 512*1.5, 'black', WindowHandle)
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('F:/HALCON/瓶盖识别/1', ['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 1read_image (Image, ImageFiles[Index])* Image Acquisition 01: Do somethingmean_image (Image, ImageMean, 19, 19)sub_image (ImageMean, Image, ImageSub, 1, 1)mean_image (ImageSub, ImageMean1, 19, 19)dyn_threshold (ImageSub, ImageMean1, RegionDynThresh, 4, 'light')connection (RegionDynThresh, ConnectedRegions)select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 711.57, 20000) select_shape (SelectedRegions, SelectedRegions1, ['width','height'], 'and', [0,0], [200,200])union1 (SelectedRegions1, RegionUnion)closing_circle (RegionUnion, RegionClosing, 20)fill_up (RegionClosing, RegionFillUp)difference (RegionFillUp, RegionClosing, RegionDifference)connection (RegionDifference, ConnectedRegions1) count_obj (ConnectedRegions1, Number)dev_display (Image)dev_display (ConnectedRegions1)set_display_font (WindowHandle, 50, 'mono', 'true', 'false')disp_message (WindowHandle, ['箱内有瓶:']+[Number], 'image', 30, 30, ['blue'], 'false') stop()endfor
效果
方法二
源码
list_files ('F:/HALCON/瓶盖识别/2', ['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 1read_image (Image, ImageFiles[Index])smooth_image(Image, ImageSmooth, 'deriche2', 0.5)edges_color_sub_pix(ImageSmooth, Edges, 'canny', 2, 10, 20)segment_contours_xld(Edges, ContoursSplit, 'lines_circles', 5, 5, 3)union_cocircular_contours_xld(ContoursSplit, UnionContours, 0.5, 0.1, 0.2, 30, 10, 10, 'true', 1)select_shape_xld (UnionContours, SelectedXLD1, ['ra','rect2_len1','circularity'], 'and', [15,30,0.3], [50,65,1])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)select_shape_xld (ContCircle, SelectedXLD, ['ra','area'], 'or', [36,3200], [50,5000])dev_display(Image)dev_display(SelectedXLD)stop()
endfor
效果
------------------------------------------------------------------------------------------分割线
------------------------------------------------------------------------------------------
|
|