1. 程式人生 > >bottle.hdev例程——訓練字符

bottle.hdev例程——訓練字符

angle append style ons bottle 填充 line rate segment


* 第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例程——訓練字符