Вы находитесь на странице: 1из 2

function [LPImageGray,LPImageBW,BW2,BW3,stats,LPImageTH,EdgeImage,imrefdata,ids

,im] = AnprEngine( LPImage,thresh)


%ANPRENGINE Summary of this function goes here
% Process image input analytics and output licence plate alphanumeric string
% Based on static image
tic
%%
% Variables Initialization
% EligibleBands = zeros(3,2);
% Pointer = 1;
% Sensing = 0;
% MinimalHeight = 15;
srcData = load('AnprSysData.mat');
imrefdata = srcData.AlphaNumRef;
im = [];
C = zeros(109);
% toc
%%
% Pre-process LPImage
LPImageGray = rgb2gray(LPImage);
LPImageTH = imtophat(LPImageGray,strel('ball',12,7));%Close ball 18 7/ Far ball
12 4
imadjust(LPImageTH,[0;0.1],[0;1]);
%[EdgeImage, thr, gv, gh] = edge(LPImageGray,'sobel','nothinning');
[EdgeImage, ~, ~] = edge(LPImageGray,'sobel');
LPImageBW = ~im2bw(LPImageTH,thresh);
%LPImageVH = edge(LPImageGray, 'sobel',0.11,'vertical');
%sz = size(LPImage);
toc
%%
% Skew detection Spacial Transformation correction
%%
% Process Image ROI candidates, Heuristic and Bands Elimamination
toc
ProjectionVH = sum(LPImageVH,2);%Compute sum of Horizontal Projection of vertica
l lines
maxIndexValue = find(ProjectionVH == max(ProjectionVH), 1,'last');%Find Max Inde
x Value of ProjectionVH 1*m Matrix
% Locate most significative eligible bands.
sensor = mean(ProjectionVH);% Define standard deviation of ProjectionVH to find
eligible bands
for idx = 1:sz(1,1)
if(ProjectionVH(idx) > sensor && Sensing == 0)
Sensing = 1;
EligibleBands(Pointer, 1) = idx;
end
if(ProjectionVH(idx) < sensor && Sensing == 1)
Sensing = 0;
EligibleBands(Pointer, 2) = idx;
if((EligibleBands(Pointer, 2)-EligibleBands(Pointer, 1))>MinimalHeight)
Pointer = Pointer + 1;
end
end
end
for i = 1:sz(1,1)
if(i < EligibleBands(1,1) || i > EligibleBands(1,2))
LPImageBW(i,:) = 0;
end
end

%%
% Locate Licence Plate Bands
%%
% Blobs Analysis
CC = bwconncomp(LPImageBW);
stats = regionprops(CC, 'Area','BoundingBox','Image');
ids = find([stats.Area] > 8 & [stats.Area] < 250);
BW2 = ismember(labelmatrix(CC),ids);
toc
%%
% Blobs Analysis
CC2 = bwconncomp(~LPImageBW);
stats2 = regionprops(CC2,'Area','BoundingBox','Eccentricity');
ids2 = find([stats2.Area] > 20 & [stats2.Eccentricity] > 0.95);
BW3 = ismember(labelmatrix(CC2),ids2);
%BW3 = [];% ismember(labelmatrix(CC2),ids2);
toc
%%
% Pre-OCR
for k=1:length(ids)
imOriginal = stats(ids(k)).Image;
BB = stats(ids(k)).BoundingBox;
NormIm{1,1} = resizem(imOriginal,[60,30]);
NormIm{2,1} = BB(4)/BB(3);
[NormIm{3,1} NormIm{4,1}, NormIm{5,1}] = getMaxCorrelationRate(NormIm{1,1},i
mrefdata);
if(BB(4)/BB(3)>=1.4 && BB(4)/BB(3)<=2 || BB(4)/BB(3)>=3 && BB(4)/BB(3)<=10)
im = [im NormIm];
%imshow(cell2mat(PD(1,:))) %to display all column in first row on NormIm
%output
%imshow(cell2mat(E2(2)))
end
end
toc
%%
% OCR Function
function [Rate,id, Letter] = getMaxCorrelationRate(imOriginal,imrefdata)
for n=1:length(imrefdata)
Rates(n) = corr2(imOriginal,cell2mat(imrefdata(1,n)));
end
[Rate,id] = max(Rates);
if(Rate>0.48)
Letter = imrefdata{2,id};
else
Letter ='';
end;
end
%%
% OCR AlphaNumerical resolution
%%
% LPNumber = 'Hello Plate';
%% Output
end
% It uses correlation instead of ANN.
% All is in AnprSysData.mat file Chars are indexed from 1 to 109

Вам также может понравиться