一、建立OCR库
dev_close_window()
read_image(Image,'OCR')
get_image_size(Image,Width,Hight)
dev_open_window(0,0,Width,Hight,'black',Window)
dev_display(Image)*字符处理
rgb1_to_gray(Image,ImageGray)
*鼠标画你要找的roi区域
draw_rectangle1(Window,Row1,Column1,Row2,Column2)
*显示roi区域
gen_rectangle1(Rectangle1, Row1, Column1, Row2, Column2)
*减少其他区域,显示你画的roi区域
reduce_domain(ImageGray,Rectangle1,ImageReduced)
threshold (ImageReduced, Regions, 0, 169)
connection(Regions,RegioncCnnection)
*排序
sort_region(RegioncCnnection,SortedRegions,'character', 'true', 'row')
count_obj(SortedRegions,Number)
for Index := 1 to Number by 1*dev_clear_window ()select_obj (SortedRegions, ObjectSelected, Index)dev_display (ObjectSelected)stop ()
endfor
*字符标识
word:= ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
*创建训练文件
File:='OCR.rtf'
*将图像区域与字符标识关联,保存到训练文件
write_ocr_trainf (SortedRegions, Image, word, File)
*创建OMC文件
FontFlie:='OCR.omc'
*读取训练文件
read_ocr_trainf_names(File,CharacterNames,CharacterCount)
*创建神经网络分类器mlp
create_ocr_class_mlp (8, 10, 'constant', 'default', CharacterNames, 80, 'none', 10, 42, OCRHandle)
*训练
trainf_ocr_class_mlp (OCRHandle, File, 200, 1, 0.01, Error, ErrorLog)
*保存训练结果
write_ocr_class_mlp (OCRHandle, FontFlie)
clear_ocr_class_mlp (OCRHandle)
stop()******************
二、识别
dev_close_window()
read_image(Image,'OCR')
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', Window)
dev_display (Image)
*字符处理
rgb1_to_gray(Image,ImageGray)
*鼠标画你要找的roi区域
draw_rectangle1(Window,Row1,Column1,Row2,Column2)
*显示roi区域
gen_rectangle1(Rectangle1, Row1, Column1, Row2, Column2)
*减少其他区域,显示你画的roi区域
reduce_domain(ImageGray,Rectangle1,ImageReduced)
*text_line_orientation
threshold (ImageReduced, Regions, 0, 169)
connection(Regions,RegioncCnnection)
select_shape (RegioncCnnection, SelectedRegions, 'height', 'and', 0, 500)
sort_region(SelectedRegions,SortedRegions,'character', 'true', 'row')
count_obj(SortedRegions,Number)*识别
read_ocr_class_mlp ('OCR/1.omc', OCRHandle1)
do_ocr_multi_class_mlp (SortedRegions, ImageGray, OCRHandle1, Class, Confidence)
dev_display (Image)
for j := 1 to Number by 1select_obj (SortedRegions, ObjectSelected1, j)area_center (ObjectSelected1, Area, Row, Column)disp_message (Window, Class[j-1], 'window', Row+20, Column, 'black', 'true')endfor
****************