码迷,mamicode.com
首页 > 其他好文 > 详细

bottle.hdev例程——训练字符

时间:2017-09-25 09:43:53      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:select   als   注意   分享   for   step   col   anr   pat   


* 第0步,准备
FontName := ‘bottle‘
read_image (Bottle, ‘bottle2‘)

技术分享


* 第1步,分割
*二值化
threshold (Bottle, RawSegmentation, 0, 95)

技术分享.

 

*填充形状
fill_up_shape (RawSegmentation, RemovedNoise, ‘area‘, 1, 5)

opening_circle (RemovedNoise, ThickStructures, 2.5)

技术分享


fill_up (ThickStructures, Solid)

技术分享


opening_rectangle1 (Solid, Cut, 1, 7)

技术分享


connection (Cut, ConnectedPatterns)

技术分享


intersection (ConnectedPatterns, ThickStructures, NumberCandidates)

技术分享


select_shape (NumberCandidates, Numbers, ‘area‘, ‘and‘, 300, 9999) *选择后的区域仅包括6个字符区域

技术分享


sort_region (Numbers, FinalNumbers, ‘first_point‘, ‘true‘, ‘column‘) *排序,注意排序方式有多种
dev_display (Bottle)
dev_set_color (‘green‘)
dev_set_line_width (2)
dev_set_shape (‘rectangle1‘)
dev_set_draw (‘margin‘)
dev_display (FinalNumbers)
*

 

 

技术分享


* 第2步,生成训练文件
TrainingNames := [‘0‘,‘1‘,‘0‘,‘8‘,‘9‘,‘4‘] *训练标签名
TrainingFileName := FontName + ‘.trf‘ *训练文件名
sort_region (FinalNumbers, SortedRegions, ‘first_point‘, ‘true‘, ‘column‘) * 又排序???
shape_trans (SortedRegions, RegionTrans, ‘rectangle1‘) *转换为矩形区域
area_center (RegionTrans, Area, Row, Column) * 获得矩形区域的面积及中心位置
MeanRow := mean(Row) *求行中心值
dev_set_check (‘~give_error‘)
delete_file (TrainingFileName)
dev_set_check (‘give_error‘)
for i := 0 to |TrainingNames| - 1 by 1
select_obj (SortedRegions, CharaterRegions, i + 1)    *依次选择对象并加入训练文件
append_ocr_trainf (CharaterRegions, Bottle, TrainingNames[i], TrainingFileName)
disp_message (WindowID, TrainingNames[i], ‘image‘, MeanRow - 40, Column[i] - 6, ‘yellow‘, ‘false‘)
endfor
*
* Step3: 训练
CharNames := uniq(sort(TrainingNames))
create_ocr_class_mlp (8, 10, ‘constant‘, ‘default‘, CharNames, 5, ‘none‘, 10, 42, OCRHandle)
trainf_ocr_class_mlp (OCRHandle, TrainingFileName, 200, 1, 0.01, Error, ErrorLog)
write_ocr_class_mlp (OCRHandle, FontName)
clear_ocr_class_mlp (OCRHandle)

bottle.hdev例程——训练字符

标签:select   als   注意   分享   for   step   col   anr   pat   

原文地址:http://www.cnblogs.com/opencv2015/p/7590315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!