How to extract only the date from a food label image?
2 views (last 30 days)
Show older comments
I am looking to create a program that reads only the date from a product label such as:
I have currently tried using OCR and bounding boxes to see which part I'm isolating but I have had no luck just isolating the date which can be used on multiple images.
Any idea's about how best to go about this would be helpful.
Many thanks.
0 Comments
Accepted Answer
Cris LaPierre
on 31 Dec 2018
Code up what you can, and then come back with specific questions about any parts you are getting stuck on.
7 Comments
Cris LaPierre
on 31 Dec 2018
Edited: Cris LaPierre
on 31 Dec 2018
Again, it's going to depend on the format of your labels. Based on the 2 you've shown, here's what I'm thinking.
- Use 'ismember' to determine which word is the month
- Use the bounding box y-position to find the other words on the same line
- Put the words together to recreate the date
- Convert the string to a datetime
This works on the 2 images you've uploaded
% Create list of months
months = {'JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'};
% Find word that is a month (only expecting 1)
idx = ismember(word,months);
% Extract Y position of month
y = results.WordBoundingBoxes(idx,2);
% Find other words that are on the same line (+/- 0.1*height of month
sameY = abs(results.WordBoundingBoxes(:,2)-y)<results.WordBoundingBoxes(idx,2)/10;
% Convert to datetime
date = horzcat(word{sameY})
date = datetime(datevec(date))
More Answers (0)
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!