汉字识别之膨胀连接

read_image (Image, 'C:/Users/Administrator/Desktop/汉字.jpg')    *读取图片 见附图
rgb1_to_gray (Image, GrayImage)                                                        *转灰度图片
scale_image (GrayImage, ImageScaled, 1.82143, 0)                            *图像预处理,灰度值缩放,增加对比度
threshold (ImageScaled, Regions, 0, 67)                                                *二值化,提取汉字区域
connection (Regions, ConnectedRegions)                                              *求连接区域,将不同连接区域分开
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [64.98,944.55], [407.01,1113])  *形状选择
union1 (SelectedRegions, RegionUnion)                                                 *将选择区域联合,形成一个连通域
shape_trans (RegionUnion, RegionTrans, 'rectangle2')                           *求最小外接矩形
reduce_domain (Image, RegionTrans, ImageReduced)                           *提取感兴趣区域
threshold (ImageReduced, Regions1, 0, 19)                                              *区域二值化
closing_rectangle1 (Regions1, RegionClosing, 10, 10)                             *区域膨胀,将汉字断开区域连接
connection (RegionClosing, ConnectedRegions1)                                    *求连接区域,将不同连接区域分开
*求两个区域的交集
intersection (ConnectedRegions1, Regions1, RegionIntersection)          *求两个区域交集
sort_region (RegionIntersection, SortedRegions, 'character', 'true', 'column')     *区域排序
count_obj (SortedRegions, Number)                                                            *计算区域个数
for i:= 1 to Number by 1
    select_obj (SortedRegions, ObjectSelected, i)
endfor
word:=['晚','秋','拾','叶']
TrainFile:='D://word.trf'
for i:= 1 to Number by 1
    select_obj (SortedRegions, ObjectSelected, i)
    append_ocr_trainf (ObjectSelected, ImageReduced, word[i-1], TrainFile)    *将汉字和区域关联
    
 *   write_ocr_trainf (ObjectSelected, ImageReduced, TrainFile, 'train_ocr')  *一次性写训练文件
    endfor
FontFile:='D://word.omc'
read_ocr_trainf_names (TrainFile, CharacterNames, CharacterCount)   *读训练文件
NumHidden:=20
create_ocr_class_mlp (8, 10, 'constant', 'default',CharacterNames, 80, 'none', 10, 42, OCRHandle)  *创建基于神经网络*OCR分类器
trainf_ocr_class_mlp (OCRHandle, TrainFile, 200, 1, 0.01, Error, ErrorLog)   *训练分类器
write_ocr_class_mlp (OCRHandle, FontFile)
clear_ocr_class_mlp (OCRHandle)
read_ocr_class_mlp ('D://word.omc', OCRHandle1)
do_ocr_multi_class_mlp (SortedRegions, ImageReduced, OCRHandle1, Class, Confidence)         *OCR识别                                                       
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页