MATLAB Answers

How do I import a table containing numbers in a picture with OCR?

13 views (last 30 days)
I have a picture of a table with numeric data in it. Like this:
How do I import the values with ocr? Is there a better method?
I tried to use ocr, but it's not working properly.
Thank you


Mohammad Sami
Mohammad Sami on 30 Jan 2020
If images is all you have, ocr would be the easy way.
try to restrict the characters to between 0 to 9 and - , .
Mattia Tosi
Mattia Tosi on 30 Jan 2020
I will try, but sometimes it's a mix of characters and numbers. How can I capture both? It looks like ocr is not really effective...
Mohammad Sami
Mohammad Sami on 30 Jan 2020
Another option, that might improve the ocr accuracy sometimes is to imresize the input image.

Sign in to comment.

Accepted Answer

Mohammad Sami
Mohammad Sami on 30 Jan 2020
Try resizing the image. It would hopefully improve the accuracy.
a = imread('image.jpeg');
a = imresize(a,2);
txt = ocr(a,'CharacterSet','0123456789.');
Iocr = insertObjectAnnotation(a, 'rectangle', ...
txt.WordBoundingBoxes, ...
for i = 1:length(txt.Words)
Iocr = insertText(Iocr,txt.WordBoundingBoxes(i,1:2),txt.Words{i},'AnchorPoint','Center');
figure; imshow(Iocr);


Show 1 older comment
Mohammad Sami
Mohammad Sami on 30 Jan 2020
If you are really having a lot of issue, you can train your own ocr model using the included ocr trainer app.
However you will need to manually label the training set in the ocr trainer app. The app would label the data initially, you can review and correct the mistakes. Then train the model using the newly labelled data.
You can also try the various matlab image enhancements, to see if any of those help.
Mattia Tosi
Mattia Tosi on 4 Feb 2020
It doesn't work direcly with the table I have, but playing with all the parameters you mentioned the result is improving.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!