ocr not recognizing some numbers
조회 수: 31 (최근 30일)
이전 댓글 표시
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))
댓글 수: 0
채택된 답변
Walter Roberson
2023년 4월 30일
Your current model is failing completely on 8's, and is weak on 7's.
댓글 수: 2
Image Analyst
2023년 4월 30일
Cool. THat might help. I didn't know about that one. It was introduced just last month in R2023a.
추가 답변 (2개)
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:
- 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
댓글 수: 0
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.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!