halcon字符检测

创建模板:

* Saving an OCV tool to file
* 
read_image (Image, 'a01')
threshold (Image, Region, 0, 100)
shape_trans (Region, RegionTrans, 'rectangle1')
dilation_rectangle1 (RegionTrans, RegionDilation, 10, 10)
* Reduce the domain of an image.
reduce_domain (Image, RegionDilation, ImageReduced)
* Create a new OCV tool based on gray value projections
create_ocv_proj ('A', OCVHandle)
traind_ocv_proj (ImageReduced, OCVHandle, 'A', 'single')
write_ocv (OCVHandle, 'test_ocv.ocv')
close_ocv (OCVHandle)
read_ocv ('test_ocv.ocv', OCVHandle)
close_ocv (OCVHandle)

匹配模版:

read_image (Image, 'fonts/arial_a1')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width / 2, Height / 2 + 42, 'black', WindowHandle)
dev_set_part (-84, 0, Height - 1, Width - 1)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
dev_set_draw ('margin')
gen_rectangle1 (Rectangle, 37, 69, 115, 141)
reduce_domain (Image, Rectangle, ImageReduced)
create_ocv_proj ('A', OCVHandle)
traind_ocv_proj (ImageReduced, OCVHandle, 'A', 'single')
dev_set_color ('red')
for I := 1 to 9 by 1
    read_image (Image, 'fonts/arial_a' + I)
    binary_threshold (Image, Region, 'max_separability', 'dark', UsedThreshold)
    connection (Region, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150, 99999)
    sort_region (SelectedRegions, SortedRegions, 'character', 'true', 'row')
    select_obj (SortedRegions, ObjectSelected, 1)
    shape_trans (ObjectSelected, RegionTrans, 'rectangle1')
    dilation_rectangle1 (RegionTrans, RegionDilation, 15, 15)
    reduce_domain (Image, RegionDilation, ImageReduced)
    do_ocv_simple (ImageReduced, OCVHandle, 'A', 'true', 'true', 'true', 'true', 5, Quality)
    * Display quality
    if (Quality > 0.9)
        Color := 'green'
    elseif (Quality > 0.7)
        Color := 'yellow'
    else
        Color := 'red'
    endif
    dev_display (Image)
    dev_set_color (Color)
    dev_set_line_width (2)
    dev_display (RegionDilation)
    disp_message (WindowHandle, 'Check print quality of \'A\' (Image  ' + I + ' of 9)', 'window', 12, 12, 'black', 'true')
    disp_message (WindowHandle, 'Quality = ' + Quality$'.2f', 'image', 120, 12, 'black', Color)
    if (I < 9)
        disp_continue_message (WindowHandle, 'black', 'true')
        stop ()
    endif
endfor
stop ()
close_ocv (OCVHandle)

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值