OCR (optical character recognition) misreading simple numbers even when image is pre-processed. What's the issue?

24 次查看(过去 30 天)
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!

采纳的回答

Birju Patel
Birju Patel 2024-9-12
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.
  1 个评论
Elinor Austin
Elinor Austin 2024-9-15
It worked for me! Specifically, setting LayoutAnalysis to "word" fixed it--for some reason just updating to 2024b was not enough on its own. Thanks so much.

请先登录,再进行评论。

更多回答(1 个)

Gayathri
Gayathri 2024-9-4
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.

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by