一、建立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
****************
?