Before the advent of RCNN, the traditional method was OCR extraction. Characters extracted from OCR were normalized, and then CNN or SVM was used to identify them. The following is a simple operation section built, and the process is button part:
Step 1: Select the image
Select the specified image to be displayed in the left coordinate area, and later OCR operations are also done in the left AXES1.
global I; [filename, filepath]=uigetfile('*.bmp; *.jpg; *.png'); % select image file I=imread([filepath filename]); Axes (handles. Axes1); % specify the image position to display imshow(I); % displays the image matrixCopy the code
Step 2: Perform OCR
The image can be grayscale before OCR operation, in order to save space in the following image recognition steps, and avoid grayscale for all five characters during normalization. In the OCR operation, imcrop function is used to complete it. For details, you can refer to the introduction of MathWork. Since the nameplate has five characters, only five coordinate areas need to be posted
global I;
global X1;
global X2;
global X3;
global X4;
global X5;
if size(I,3) ~= 1
I = rgb2gray(I);
end
X1 = imcrop(I);
X2 = imcrop(I);
X3 = imcrop(I);
X4 = imcrop(I);
X5 = imcrop(I);
axes(handles.axes2)
imshow(X1)
axes(handles.axes3)
imshow(X2)
axes(handles.axes4)
imshow(X3)
axes(handles.axes6)
imshow(X4)
axes(handles.axes5)
imshow(X5)
Copy the code
Step 3: Normalization
Since the image needs to be normalized to the same size before CNN recognition, the gray-scale operation has been completed when OCR is performed, and the images at this time are all gray-scale images. At this time, the function imresize is used instead of noise reduction filtering enhancement, which is lazy. You can add it by yourself when doing it.
%% global X1; global X2; global X3; global X4; global X5; %% global X1X; global X2X; global X3X; global X4X; global X5X; % % X1X = imresize (X1, [70]). Axes (handles. Axes2) imshow(X1X) %% X2X = imresize(X2,[70,70]); Axes (axes. Axes3) axes(axes. Axes3) axes(axes. Axes3) axes(axes. Axes (axes. Axes4) axes(axes. Axes4) axes(axes. Axes4) axes(axes. Axes (axes5) axes = axes(axes5) axes = axes(axes5) axes(handles.axes6) imshow(X5X)Copy the code
Step 4: Identify characters
Here I use AlexNet network structure, you can refer to myself: juejin.cn/post/707478… The structure of the network is described in detail here, as well as at juejin.cn/post/707478… Why not use a more advanced Network structure: According to the Omka razor principle, you can avoid the over-fitting phenomenon, and it is unnecessary to waste computing power.
load numdata.mat global X1X; global X2X; global X3X; global X4X; global X5X; Y1 = classify(net,X1X); % YPred1=cellstr(Y1); Y2 = classify(net,X2X); % YPred2=cellstr(Y2); Y3 = classify(net,X3X); % YPred3=cellstr(Y3); Y4 = classify(net,X4X); % YPred4=cellstr(Y4); Y5 = classify(net,X5X); % YPred5=cellstr(Y5); set(handles.edit1,'string',YPred1); set(handles.edit2,'string',YPred2); set(handles.edit3,'string',YPred3); set(handles.edit4,'string',YPred4); set(handles.edit5,'string',YPred5);Copy the code
Initialize the
I’m not going to go into this step.
clc
axes(handles.axes1);
cla reset
axes(handles.axes2);
cla reset
axes(handles.axes3);
cla reset
axes(handles.axes4);
cla reset
axes(handles.axes5);
cla reset
axes(handles.axes6);
cla reset
A = " ";
set(handles.edit1,'string',A)
set(handles.edit2,'string',A)
set(handles.edit3,'string',A)
set(handles.edit4,'string',A)
set(handles.edit5,'string',A)
Copy the code
Operation screenshot:
Step 1: Select the image
Step 2: Execute OCR
Step 3: Pretreatment
Step 4: Identify characters