フィルターのクリア

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 Center および File ExchangeComputer Vision Toolbox についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by