halcon bottle上的数字识别实例注释

* 关键掌握数字的分割技术
* bottle2.hdev: Segmenting and reading of numbers on a beer bottle
* Program without visualization: "bottle.hdev"

* Step 0: Preparations
* Specify the name of the font to use for reading the date on the bottle.
* It is easiest to use the pre-trained font Industrial_0-9.  If you have run the
* program bottlet.hdev in this directory, you can activate the second line
* to use the font trained with this program.
FontName := 'Industrial_0-9'
* FontName := 'bottle'

* Step 1: Segmentation
dev_update_window ('off')
read_image (Bottle, 'bottle2')
get_image_size (Bottle, Width, Height)
dev_close_window ()
dev_open_window (0, 0, 2*Width, 2*Height, 'black', WindowID)
set_display_font (WindowID, 20, 'mono', 'true', 'false')
dev_display (Bottle)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*二值化,选取比较暗的部分
threshold (Bottle, RawSegmentation, 0, 95)
*把中间一些小洞洞补起来
fill_up_shape (RawSegmentation, RemovedNoise, 'area', 1, 5)
*开运算,把小杂质图像去掉

opening_circle (RemovedNoise, ThickStructures, 2.5)


dev_display (Bottle)
dev_set_color ('green')
dev_display (ThickStructures)
disp_continue_message (WindowID, 'black', 'true')
stop ()
dev_set_draw ('margin')
dev_set_line_width (3)
dev_display (Bottle)
dev_display (ThickStructures)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*填充区域,里面孔都封起来,处理边缘
fill_up (ThickStructures, Solid)
dev_display (Bottle)
dev_clear_window()
dev_display (Solid)
disp_continue_message (WindowID, 'black', 'true')

stop ()


*矩形开运算,把连通的小区域分开
opening_rectangle1 (Solid, Cut, 1, 7)
dev_display (Bottle)
dev_display (Cut)
disp_continue_message (WindowID, 'black', 'true')

stop ()


*计算连通区域
connection (Cut, ConnectedPatterns)
*交集
dev_clear_window()
dev_display(ConnectedPatterns)
dev_clear_window()
dev_display(ThickStructures)
intersection (ConnectedPatterns, ThickStructures, NumberCandidates)
dev_clear_window()
dev_display(NumberCandidates)


dev_set_colored (12)
dev_display (Bottle)
dev_display (NumberCandidates)
disp_continue_message (WindowID, 'black', 'true')

stop ()

*选择区域

select_shape (NumberCandidates, Numbers, 'area', 'and', 300, 9999)

*排队排队

sort_region (Numbers, FinalNumbers, 'first_point', 'true', 'column')
dev_set_color ('red')
dev_display (Bottle)
dev_display (Numbers)
dev_set_shape ('rectangle1')
dev_set_color ('green')
dev_display (FinalNumbers)
dev_set_shape ('original')
dev_set_line_width (1)
dev_set_draw ('fill')

* Step2: Reading
* 读取训练好的分类器.这应该是神经网络之类的东东.
read_ocr_class_mlp (FontName, OCRHandle)
*识别
do_ocr_multi_class_mlp (FinalNumbers, Bottle, OCRHandle, RecNum, Confidence)
*计算中心点
area_center (FinalNumbers, Area, Row, ColNum)
set_display_font (WindowID, 27, 'mono', 'true', 'false')
for i := 0 to |RecNum|-1 by 1
    disp_message (WindowID, RecNum[i], 'image', 80, ColNum[i]-3, 'green', 'false')
endfor

*显示效果


clear_ocr_class_mlp (OCRHandle)
dev_update_window ('on')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值