halcon字符检测
2023-12-25 14:05:14
创建模板:
* 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)
文章来源:https://blog.csdn.net/weixin_38241876/article/details/135196891
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!