ocr not recognizing some numbers
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Simon Chan
el 30 de Abr. de 2023
Comentada: Simon Chan
el 1 de Mayo de 2023
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 comentarios
Respuesta aceptada
Walter Roberson
el 30 de Abr. de 2023
Your current model is failing completely on 8's, and is weak on 7's.
2 comentarios
Image Analyst
el 30 de Abr. de 2023
Cool. THat might help. I didn't know about that one. It was introduced just last month in R2023a.
Más respuestas (2)
albara
el 30 de Abr. de 2023
Editada: albara
el 30 de Abr. de 2023
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 comentarios
Image Analyst
el 30 de Abr. de 2023
Editada: Image Analyst
el 30 de Abr. de 2023
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 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!