why can't my OCR code identify the license plate on the code?

the programming that I made did not experience errors, and for some reason the OCR output did not appear, instead the word "NaN" appeared continuously. please help me to fix it.
I = imread(image1.png);
crop=imcrop(I);
I2 = rgb2gray(crop);
K = im2bw(I2, 0.6);
bw = im2bw(crop);
canny = edge(bw, 'Canny');
figure, imshow(I), title('Original image');
figure,imshow(bw), title ('binerisasi');
figure,imshow(canny), title ('canny');
figure, imshow(crop), title ('cropping');
figure, imshow(I2), title ('grayscale');
figure, imshow(K), title ('thresholding');
ocrOutput = ocr(I, 'TextLayout', 'Line', 'characterSet', '0123456789');
outputNum = str2double(ocrOutput.Text)
ocrImage = insertObjectAnnotation(I, 'rectangle', ocrOutput.WordBoundingBoxes, ...
ocrOutput.WordConfidences);
figure, imshow(ocrImage), title ('OCR');

4 Comments

I = imread(image1.png);
In order for that to work, image1 would have to be a struct with a field named png -- or else image1 would have to be an object with a property or method named png .
Note: it would probably be easier for us to debug if you attached the image.
I have made the file in png format. here is the link i got the picture: https://images.app.goo.gl/nnes5Rm5T3tiWZnA9
but I still get OCR output like this (and it applies to each different image):
outputNum =
NaN
I don't have CVT, but it seems to work just fine, depending on what region is selected.
I = imread('images.jpeg');
% irrelevant code omitted
% pick a region
%ocrOutput = ocr(I,[67 55 169 46],'characterset','0':'9');
ocrOutput = ocr(I,[128 88 43 14],'characterset','0':'9');
outputNum = str2double(ocrOutput.Text)
outputNum = 627
ocrImage = insertObjectAnnotation(I, 'rectangle', ocrOutput.WordBoundingBoxes, ...
ocrOutput.WordConfidences);
figure, imshow(ocrImage), title ('OCR');
I've tried your code and the image was successfully detected, it's just not displayed in the command window. And the letter characters have not been detected either. Why did it happen? and how to solve it?

Sign in to comment.

 Accepted Answer

I = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1471966/images.jpeg');
% if you want to recognize characters other than 0-9
% then don't restrict the character set to 0-9
% you could just let it automatically detect
ocrOutput = ocr(I,[67 55 169 46]);
ocrOutput.Text % this contains non-numeric characters
ans =
'B 505 WLG '
% or you could explicitly give an alphanumeric character set
charset = ['A':'Z' '0':'9' ' -'];
ocrOutput = ocr(I,[67 55 169 46],'characterset',charset);
ocrOutput.Text % this contains non-numeric characters
ans =
'B 505 WLG '
% the other line
ocrOutput = ocr(I,[128 88 43 14],'characterset',charset);
ocrOutput.Text % this contains non-numeric characters
ans =
'06-27 '
% in all of these cases, the output is no longer strictly numeric
outputNum = str2double(ocrOutput.Text) % so it's not a number
outputNum = NaN

2 Comments

it's work! Thank you for patiently helping me. Thank you so much. but what if i want to perform detection to multiple images? because the code [67 55 169 46] prevents OCR from detecting other images and can only detect the input image.
The numbers are the ROI. You need to segment your image somehow to find the ROI and there are a bazillion segmentation algorithms. For some examples, see
16.7.2.9 License Plate Recognition, Extraction, Analysis

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Release

R2015a

Community Treasure Hunt

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

Start Hunting!