Halocn OCR识别入门学习

一、建立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()

******************
OCR

 

二、识别

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 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
****************

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值