orc识别在很多地方能用到,今天给兄弟们直接来一个简单号入门的例子。
1.建立OCR库
dev_close_window()
read_image(Image,'OCR/1')
get_image_size(Image,Width,Hight)
dev_open_window(0,0,Width*2,Hight*2,'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/1'
*将图像区域与字符标识关联,保存到训练文件
write_ocr_trainf (SortedRegions, Image, word, File)
*创建OMC文件
FontFlie:='OCR/1.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()
******************
原图:
运行结果:
2.识别OCR模板中的文字
dev_close_window()
read_image(Image,'OCR/1')
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 1
select_obj (SortedRegions, ObjectSelected1, j)
area_center (ObjectSelected1, Area, Row, Column)
disp_message (Window, Class[j-1], 'window', Row+20, Column, 'black', 'true')
endfor
运行结果1
运行结果2
只是一个入门程希望对朋友们有点帮助!!!!