www.gusucode.com > IPCV_Eval_Kit_R2019a_0ce6858工具箱matlab程序源码 > IPCV_Eval_Kit_R2019a_0ce6858/code/demo_files/I5_03_1_myOCR_sign40.m

    clear;clc;close all;imtool close all

%% 夋憸偺撉崬傒丒昞帵
I = imread('I5_03_1_ocr\IMG_2521_sign40.JPG');
figure;imshow(I);

%% 愒偄椞堟傪拪弌
HSV = rgb2hsv(I);
areaRed = ((HSV(:,:,1) >= 0.9 ) | (HSV(:,:,1) <= 0.05 )) & ...
          (HSV(:,:,2) >= 0.8 );
figure;imshow(areaRed);

%% 彫偝側僑儈傪彍嫀
areaRed1 = bwareaopen(areaRed,500);
figure;imshow(areaRed1);

%% 愒偵埻傑傟偰偄傞晹暘傪拪弌
areaRedFilled = imfill(areaRed1,'holes');   %愒偱埻傑傟偰偄傞晹暘傪杽傔傞
G = rgb2gray(I);
G(~areaRedFilled)=255;     %愒偱埻傑傟偰偄傞晹暘傪拪弌
figure;imshow(G); 

%% 愒偄晹暘傕彍嫀
areaRed2 = imdilate(areaRed1,ones(11));   % 愒偄晹暘傪彮偟偩偗朿挘
G(areaRed2)=255;                          % 愒怓晹暘傪彍嫀
figure;imshow(G); 

%% 暥帤擣幆
results = ocr(G)

%% 暥帤偺昞帵
Ir = insertObjectAnnotation(I, 'rectangle', results.WordBoundingBoxes, results.Words, 'FontSize',50);
imtool(Ir);

%% 暥復嶌惉
sentense = ['惂尷懍搙偼丄' results.Words{1} '僉儘偱偡丅']    % 擔杮岅撉忋偘偺暥復
%sentense = ['Speed limit is ' results.Words{1}]             % 塸岅撉忋偘偺暥復

%% 撉傒忋偘 (擔杮岅壒惡崌惉僄儞僕儞偼暿搑擖庤梫)
NET.addAssembly('System.Speech');   %.NET傾僙儞僽儕偺撉崬傒
speak = System.Speech.Synthesis.SpeechSynthesizer; speak.Volume = 100;
speak.SelectVoice('偗偄偙');
speak.Speak(sentense);

%% 撉傒忋偘 (塸岅壒惡崌惉僄儞僕儞偼Windows偵晅懏)
NET.addAssembly('System.Speech');   %.NET傾僙儞僽儕偺撉崬傒
speak = System.Speech.Synthesis.SpeechSynthesizer; speak.Volume = 100;
speak.SelectVoice('Microsoft Anna')
speak.Speak(sentense);


%% 廔椆









%% 擔杮岅偺撉傒忋偘偵偼丄暿搑擔杮岅壒惡崌惉僄儞僕儞偑昁梫
%  塸岅偵娭偟偰偼Windows偵撪憻

%% 奺専弌椞堟偺妋搙傪昞帵偡傞応崌
%Ic = insertObjectAnnotation(G, 'rectangle', results.WordBoundingBoxes, results.WordConfidences, 'FontSize', 30);
%imtool(Ic);

%% ocr幚峴慜偵丄娭悢撪晹偱Otu朄偵傛傝2抣壔偝傟偰偄傑偡
%G = rgb2gray(I);imtool(im2bw(G,graythresh(G)))

% Copyright 2014 The MathWorks, Inc.