文章目录
- 简单的阈值处理
- 发现颜色不统一,把‘游’字选出来
- 膨胀处理
- 把字扣下来进行阈值处理
- 训练模型
简单的阈值处理
dev_close_window()
**基于自定义中文识别库识别名称
read_image(Image,'C:/Users/Augustine/Desktop/西游记.png')
get_image_size(Image,Width,Height)
dev_open_window(0,0,Width, Height, 'black', WindowHandle)
dev_display(Image)**选取ROI 区域
draw_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)
gen_rectangle1(Rectangle,Row1,Column1,Row2,Column2)**显示需要识别的区域
reduce_domain(Image, Rectangle, ImageReduced)**分割出需要识别的区域
rgb1_to_gray(ImageReduced,GrayImage)** 阈值处理
binary_threshold(GrayImage, Region, 'max_separability', 'dark', UsedThreshold)
connection(Region, ConnectedRegions)
发现颜色不统一,把‘游’字选出来
膨胀处理
*选取特征区域
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [80,190], [170,280])* 膨胀,尽量的将单个字体连接起来
dilation_circle (SelectedRegions, RegionDilation, 2)
* 将各个区域求并集
union1 (RegionDilation, RegionUnion)
把字扣下来进行阈值处理
*抠图
reduce_domain(Image, RegionUnion, ImageReduced1)
* 阈值选择
threshold (ImageReduced1, Regions, 0, 228)
训练模型
*抠图
reduce_domain(Image, RegionUnion, ImageReduced1)
* 阈值选择
threshold (ImageReduced1, Regions1, 0, 228)* 创建一个trf文件,将‘游’字存放进去
write_ocr_trainf (Regions1, Image, '游', 'D:/游.trf')
* 加载我们创建的trf文件
read_ocr_trainf_names ('D:/游.trf', CharacterNames, CharacterCount)
* 创建模型
create_ocr_class_mlp (8, 10, 'constant', 'default', CharacterNames,\80, 'none', 10, 42, OCRHandle)
* 训练模型
trainf_ocr_class_mlp (OCRHandle, 'D:/游.trf', 200, 1, 0.01, Error1, ErrorLog1)
* 识别
do_ocr_multi_class_mlp (Regions1, Image, OCRHandle, Class, Confidence)* 显示
disp_message (WindowHandle, Class, 'window', 0, 0, 'red', 'true')
其他字以此类推
dev_close_window()
**基于自定义中文识别库识别名称
read_image(Image,'C:/Users/Augustine/Desktop/西游记.png')
get_image_size(Image,Width,Height)
dev_open_window(0,0,Width, Height, 'black', WindowHandle)
dev_display(Image)**选取ROI 区域
draw_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)
gen_rectangle1(Rectangle,Row1,Column1,Row2,Column2)**抠图显示需要识别的区域
reduce_domain(Image, Rectangle, ImageReduced)**分割出需要识别的区域
rgb1_to_gray(ImageReduced,GrayImage)** 阈值处理
binary_threshold(GrayImage, Region, 'max_separability', 'dark', UsedThreshold)
connection(Region, ConnectedRegions)***********************************************************************************************************
*选取特征区域 "识别 游 字"
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [80,190], [170,280])* 膨胀,尽量的将单个字体连接起来
dilation_circle (SelectedRegions, RegionDilation, 2)
* 将各个区域求并集
union1 (RegionDilation, RegionUnion)*抠图
reduce_domain(Image, RegionUnion, ImageReduced1)
* 阈值选择
threshold (ImageReduced1, Regions1, 0, 228)* 创建一个trf文件,将‘游’字存放进去
write_ocr_trainf (Regions1, Image, '游', 'D:/游.trf')
* 加载我们创建的trf文件
read_ocr_trainf_names ('D:/游.trf', CharacterNames, CharacterCount)
* 创建模型
create_ocr_class_mlp (8, 10, 'constant', 'default', CharacterNames,\80, 'none', 10, 42, OCRHandle)
* 训练模型
trainf_ocr_class_mlp (OCRHandle, 'D:/游.trf', 200, 1, 0.01, Error1, ErrorLog1)
* 识别
do_ocr_multi_class_mlp (Regions1, Image, OCRHandle, Class, Confidence)* 显示
disp_message (WindowHandle, Class, 'window', 0, 0, 'red', 'true')************************************************************************************************************
*选取特征区域 "识别 记 字"
select_shape (ConnectedRegions, SelectedRegions1, ['row','column'], 'and', [80,280], [170,360])* 膨胀,尽量的将单个字体连接起来
dilation_circle (SelectedRegions1, RegionDilation1, 4.5)
* 将各个区域求并集
union1 (RegionDilation1, RegionUnion1)*抠图
reduce_domain(Image, RegionUnion1, ImageReduced2)
* 阈值选择
threshold (ImageReduced2, Regions1, 0, 228)* 创建一个trf文件,将‘记’字存放进去
write_ocr_trainf (Regions1, Image, '记', 'D:/记.trf')
* 加载我们创建的trf文件
read_ocr_trainf_names ('D:/记.trf', CharacterNames, CharacterCount)
* 创建模型
create_ocr_class_mlp (8, 10, 'constant', 'default', CharacterNames,\80, 'none', 10, 42, OCRHandle)
* 训练模型
trainf_ocr_class_mlp (OCRHandle, 'D:/记.trf', 200, 1, 0.01, Error1, ErrorLog1)
* 识别
do_ocr_multi_class_mlp (Regions1, Image, OCRHandle, Class, Confidence)* 显示
disp_message (WindowHandle, Class, 'window', 0, 0, 'red', 'true')
参考
https://blog.csdn.net/qq_41440913/article/details/110868580