Matlab-vision包学习-Object Detection and Recognition-ocr函数字符识别

这一篇介绍利用

函数/Functions

函数名称:ocr

功能:利用光学性质识别文字

语法:txt = ocr(I); 

            txt = ocr(I,roi); 

            [_] = ocr(_,Name,Value); 

其中,I为图像;roi为感兴趣的区域;Name为用一对单引号包含的字符串,Value为对应Name的值。

Name&Value参数
NameValue
'TextLayout'默认值为‘Auto',表示设置输出文字的排版,还有更多的取值见下表
’Language'默认值为‘English',表示识别文字的字符集,可以通过路径添加字符集,举例如下:
txt = ocr(img,'Language',{'path\...\eng.traineddata','path\...\chinese.traineddata'}),注意每个<language>.traineddata的路径必须相同,否则无效。
’CharacterSet'默认值为 all characters,也可以是字符串,例如只识别数字时,可以取值为'0 1 2 3 4 5 6 7 8 9'(包含空格)
TextLayout及其含义
‘TextLayout'取值含义
’Auto'按照图像中的文本排版显示
‘Block'将图像中的文本当作块显示
’Line'将图像中的文本作为一行进行显示
‘Word'将图像中的文本按照单词进行显示

举例:

close all; 
clear all; 
clc; 

businessCard = imread('businessCard.png'); 
ocrResults = ocr(businessCard); 
recognizedText = ocrResults.Text; 
figure; 
imshow(businessCard); 
text(600,150,recognizedText,'BackgroundColor',[1,1,1]); 
title('识别英语和数字'); 

businessCard = imread('businessCard.png'); 
ocrResults = ocr(businessCard,'CharacterSet','0 1 2 3 4 5 6 7 8 9'); 
recognizedText = ocrResults.Text; 
figure; 
imshow(businessCard); 
text(600,150,recognizedText,'BackgroundColor',[1,1,1]); 
title('识别数字'); 

businessCard = imread('C:\Users\heshiwen\Desktop\digital.png'); 
ocrResults = ocr(businessCard,'CharacterSet','0 1 2 3 4 5 6 7 8 9'); 
recognizedText = ocrResults.Text; 
figure; 
imshow(businessCard); 
text(600,150,recognizedText,'BackgroundColor',[1,1,1]); 
title('识别数字'); 



  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值