필터 지우기
필터 지우기

ocr not recognizing some numbers

조회 수: 23 (최근 30일)
Simon Chan
Simon Chan 2023년 4월 30일
댓글: Simon Chan 2023년 5월 1일
Trying to use function ocr to extract some numbers from the attached image.
Expected to have 9 numbers and the results have 8 numbers only.
On the other hand, some of the numbers are not correctly detected.
Any recommendation or suggestion to improve the detection? Or any additional pre-processing on the image needs to be done before using function ocr?
I = imread('Sample.png');
imshow(I,[]);
txt = ocr(I, 'CharacterSet', '0123456789.');
data = str2double(txt.Words);
data(~isnan(data))
ans = 8×1
971.5000 459.2000 7.0000 174.0000 416.0000 174.0000 417.0000 416.0000

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 30일
You can use trainOCR to train on sample images, and pass the trained model to ocr
You might want to use ocrTrainingData to help create the data to train on.
Your current model is failing completely on 8's, and is weak on 7's.
  댓글 수: 2
Image Analyst
Image Analyst 2023년 4월 30일
Cool. THat might help. I didn't know about that one. It was introduced just last month in R2023a.
Simon Chan
Simon Chan 2023년 5월 1일
Great, will definitely train a new model.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

albara
albara 2023년 4월 30일
편집: albara 2023년 4월 30일
There are several possible ways to improve the detection, which may include image pre-processing techniques, adjusting OCR parameters, or using other image processing tools.
Here are some recommendations:
  1. Convert to grayscale and apply a threshold: If the image is in color, you might want to convert it to grayscale to simplify the analysis. You can also apply a binary threshold to make the text stand out more clearly.
I_gray = rgb2gray(I);
I_binary = imbinarize(I_gray);
imshow(I_binary);
2- Noise reduction: Removing noise from the image can help to improve OCR accuracy. You can use the 'medfilt2' function to apply a median filter for noise reduction.
I_denoised = medfilt2(I_binary);
imshow(I_denoised);
3- Morphological operations: You can use morphological operations like dilation or erosion to improve the text's visibility.
se = strel('square', 2); % Structuring element
I_dilated = imdilate(I_denoised, se);
imshow(I_dilated);
4-Adjust OCR parameters: You can experiment with the 'TextLayout' and 'AnalysisLevels' parameters to improve the OCR results.
txt = ocr(I_dilated, 'CharacterSet', '0123456789.', 'TextLayout', 'Block', 'AnalysisLevels', 2);
5- If the numbers are expected to be arranged in a specific pattern or grid, you can use image segmentation techniques to isolate each number and then apply OCR on individual segments.
After applying the above recommendations, update the code with the processed image and try again. Remember to experiment with different combinations of the above suggestions for optimal results. Keep in mind that OCR accuracy might not be perfect, and some manual validation or correction might still be necessary.
Waiting for your feedback
Important: There may be some mistakes in this answer Experts can tell if there are any mistakes

Image Analyst
Image Analyst 2023년 4월 30일
편집: Image Analyst 2023년 4월 30일
ocr needs the image of the letters or numbers to be at least 20 pixels high. I don't think yours are.
If your digits are always the same size (image magnification does not change) then you might have a template of numbers and try normalized cross correlation. See attached demo.

카테고리

Help CenterFile Exchange에서 Computer Vision Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by