OCR (optical character recognition) misreading simple numbers even when image is pre-processed. What's the issue?
24 views (last 30 days)
Show older comments
Elinor Austin
on 3 Sep 2024
Commented: Elinor Austin
on 15 Sep 2024
I followed the advice in this ( https://www.mathworks.com/matlabcentral/answers/1955379-ocr-not-recognizing-some-numbers ) forum to pre-process a series of images but my code is still outputting terribly inaccurate results. I make sure to draw the ROI just around the "0.12" and it does not help. Here's my code and one image:
clc; clear all
I = imread('test.jpg');
I_gray = rgb2gray(I);
I_gray_binary = imbinarize(I_gray);
I_f = medfilt2(I_gray_binary);
[J,roi] = imcrop(I_f);
ocrResults = ocr(I_f,roi,Language='seven-segment');
ocrResults.Text
Thanks to anyone who can offer any advice!
0 Comments
Accepted Answer
Birju Patel
on 12 Sep 2024
When giving an ROI around a word, setting the LayoutAnalysis to word can help. Here are the results I get in R2024b:
>> txt = ocr(I_f,roi,Model="seven-segment",LayoutAnalysis="word");
>> txt.Text
ans =
'0.12
'
If you are using a release before 23b, I would consider updating to get access to the latest OCR function.
More Answers (1)
Gayathri
on 4 Sep 2024
To resolve issues with “ocr” on certain images, you can improve accuracy by training a model using “trainocr” function. Certain fonts and sizes may be difficult for OCR to recognize, so using training data tailored to your font can be beneficial. “trainocr” function was introduced in MATLAB R2023a. Please upgrade to MATLAB R2023a or later versions to access this function. For more information about “trainocr” refer to the below link.
Additionally, if the input image appears skewed, you can correct this by using the “imrotate” function to adjust the orientation. For more information on “imrotate”, please refer to the below link.
I hope you find this information helpful.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!