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