Read the output line by line

3 visualizaciones (últimos 30 días)
Aqip10
Aqip10 el 12 de Dic. de 2018
Respondida: NIKITHA A S el 25 de Abr. de 2022
How to read the text line by line? i dont know where to put it. Now, it show rubbish output. this is the code.
[file,path]=uigetfile({'*.jpg;*.bmp;*.png;*.tif'},'Choose an image');
s=[path,file];
picture=imread(s);
[~,cc]=size(picture);
picture=imresize(picture,[300 500]);
if size(picture,3)==3
picture=rgb2gray(picture);
figure
imshow(picture)
title ('GRAY')
end
% se=strel('rectangle',[5,5]);
% a=imerode(picture,se);
% figure,imshow(a);
% b=imdilate(a,se);
threshold = graythresh(picture);
picture =~im2bw(picture,threshold);
picture = bwareaopen(picture,30);
imshow(picture)
title ('first')
if cc>2000
picture1=bwareaopen(picture,3500);
else
picture1=bwareaopen(picture,3000);
end
figure,imshow(picture1), title ('show')
picture2=picture-picture1;
figure,imshow(picture2), title ('thresh 1')
picture2=bwareaopen(picture2,200);
figure,imshow(picture2), title ('BoundingBOx')
[L,Ne]=bwlabel(picture2);
propied=regionprops(L,'BoundingBox');
hold on
pause(1)
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
figure
final_output=[];
t=[];
for n=1:Ne
[r,c] = find(L==n);
n1=picture(min(r):max(r),min(c):max(c));
n1=imresize(n1,[42,24]);
imshow(n1)
title ('alphabet found')
pause(0.2)
x=[ ];
totalLetters=size(imgfile,2);
for k=1:totalLetters
y=corr2(imgfile{1,k},n1);
x=[x y];
end
t=[t max(x)];
if max(x)>.45
z=find(x==max(x));
out=cell2mat(imgfile(2,z));
final_output=[final_output out];
end
end
file = fopen('TextDetect.txt', 'wt');
fprintf(file,'%s\n',final_output);
fclose(file);
winopen('TextDetect.txt')
my output are like this : and the 'DO' part cant be read.
TANHNAiyMsyoHEsuEcLMANPYR7EDEo

Respuestas (2)

GT
GT el 12 de Dic. de 2018
Hi,
Not sure if I understand the problem correctly... are you trying to given an image with text get the text into MATLAB?
If yes, there is a simple way: OCR is in the Computer Vision System Toolbox. The example is really useful.
If no, can you further explain what you are looking for:) It also is often useful to share a "dummy" image with the community, so we can use it for helping you.
  1 comentario
Aqip10
Aqip10 el 12 de Dic. de 2018
hi!, thanks for the respond. Actually i want to insert a code that read the output line by line because u can see from the ouput that i get, the word is scramble. I think it read the word (from the image) vertically. And about the OCR, i already use that code but it gives a wrong output, it can only gives the exact output if the image is really clear and no shadow like my picture. This code is best when the image only have one line or two line.

Iniciar sesión para comentar.


NIKITHA A S
NIKITHA A S el 25 de Abr. de 2022
clc
close all;
clear;
load imgfildata;
[file,path]=uigetfile({'*.jpg;*.bmp;*.png;*.tif'},'Choose an image');
s=[path,file];
picture=imread(s);
[~,cc]=size(picture);
picture=imresize(picture,[300 500]);
if size(picture,3)==3
picture=rgb2gray(picture);
end
se=strel('rectangle',[5,5]);
a=imerode(picture,se);
figure,imshow(a);
b=imdilate(a,se);
threshold = graythresh(picture);
picture =~im2bw(picture,threshold);
picture = bwareaopen(picture,30);
imshow(picture)
if cc>2000
picture1=bwareaopen(picture,3500);
else
picture1=bwareaopen(picture,3000);
end
figure,imshow(picture1)
picture2=picture-picture1;
figure,imshow(picture2)
picture2=bwareaopen(picture2,200);
figure,imshow(picture2)
[L,Ne]=bwlabel(picture2);
propied=regionprops(L,'BoundingBox');
hold on
pause(1)
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
end
hold off
figure
final_output=[];
t=[];
for n=1:Ne
[r,c] = find(L==n);
n1=picture(min(r):max(r),min(c):max(c));
n1=imresize(n1,[42,24]);
imshow(n1)
pause(0.2)
x=[ ];
totalLetters=size(imgfile,2);
for k=1:totalLetters
y=corr2(imgfile{1,k},n1);
x=[x y];
end
t=[t max(x)];
if max(x)>.45
z=find(x==max(x));
out=cell2mat(imgfile(2,z));
final_output=[final_output out];
end
end
fileID = fopen('C:\Users\bhuva\Downloads\Vehicle number plate recognition (2)\Vehicle number plate recognition\number_Plate.txt', 'w');
fprintf(fileID,'%s\n',final_output);
fclose(fileID);
winopen('number_Plate.txt')

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by