文章目录
- 素材
- 交互选取区域
- 阈值分割
- 特征提取
- 识别字符
- 显示
- 全部代码
素材
dev_get_window(WindowHandle)
**读取图像
read_image(Image,'C:/Users/Augustine/Desktop/1.png')
**把图像转正,镜像方式
mirror_image(Image,ImageMirror,'row')
mirror_image(ImageMirror,ImageMirror1,'column')
交互选取区域
**交互式把需要识别的区域找出来
draw_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)
gen_rectangle1(Rectangle,Row1,Column1,Row2,Column2)
**显示需要识别的区域图像
reduce_domain(ImageMirror1, Rectangle, ImageReduced)
阈值分割
**分割出需要识别的区域
rgb1_to_gray(ImageReduced,GrayImage)
*阈值处理
binary_threshold(GrayImage, Region, 'max_separability', 'dark', UsedThreshold)
connection(Region,ConnectedRegions)
特征提取
通过行和列来获取数字的值
用特征直方图获取特征
**分割出需要识别的区域
rgb1_to_gray(ImageReduced,GrayImage)
*阈值处理
binary_threshold(GrayImage, Region, 'max_separability', 'dark', UsedThreshold)
connection(Region,ConnectedRegions)
** 把需要识别的字符显出出来
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [276,260], [310,310])
识别字符
** 把需要识别的字符显出出来
select_shape (ConnectedRegions, SelectedRegions, ['row','column'], 'and', [276,260], [310,310])
**识别字符,加载识别字符库句柄,使用工业字符
read_ocr_class_mlp('Industrial_0-9_NoRej.omc',OCRHandle)
**执行字符识别
do_ocr_multi_class_mlp(SelectedRegions,GrayImage,OCRHandle,Class,Confidence)
显示
**展示结果
smallest_rectangle1(SelectedRegions,Row11,Column11,Row21,Column21)
for Index:=1 to Number by 1
disp_message(WindowHandle, Class[Index - 1], 'image', Row21[Index -1 ], Column11[Index -1]+20, 'red', 'true')
endfor
全部代码
dev_get_window(WindowHandle)
**读取图像
read_image(Image,'C:/Users/Augustine/Desktop/1.png')
**把图像转正,镜像方式
mirror_image(Image,ImageMirror,'row')
mirror_image(ImageMirror,ImageMirror1,'column')
**交互式把需要识别的区域找出来
draw_rectangle1(WindowHandle,Row1,Column1,Row2,Column2)
gen_rectangle1(Rectangle,Row1,Column1,Row2,Column2)
**显示需要识别的区域图像
reduce_domain(ImageMirror1, 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', [276,260], [310,310])
**获取筛选出来的字符数量
count_obj(SelectedRegions,Number)
**识别字符,加载识别字符库句柄,使用工业字符
read_ocr_class_mlp('Industrial_0-9_NoRej.omc',OCRHandle)
**执行字符识别
do_ocr_multi_class_mlp(SelectedRegions,GrayImage,OCRHandle,Class,Confidence)
**展示结果
smallest_rectangle1(SelectedRegions,Row11,Column11,Row21,Column21)
for Index:=1 to Number by 1
disp_message(WindowHandle, Class[Index - 1], 'image', Row21[Index -1 ], Column11[Index -1]+20, 'red', 'true')
endfor
注意: