瓶子个数计数halcon

  • 博主写作不容易,孩子需要您鼓励
  • 万水千山总是情 , 先点个赞行不行

处理要求

查找纸箱内瓶子个数
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

处理方法一

源码

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 1
    read_image (Image, ImageFiles[Index])
    * Image Acquisition 01: Do something
    mean_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 1
    read_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

效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

------------------------------------------------------------------------------------------
                                              分割线
------------------------------------------------------------------------------------------
  • 博主简介:
  • 工业自动化上位机软件工程师、机器视觉算法工程师、运动控制算法工程师。目前从业于智能制造自动化行业。 博主邮箱:2296776525@qq.com
  • 帮忙点个赞吧。哈哈。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值