How to extract only the date from a food label image?

2 views (last 30 days)
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.

Accepted Answer

Cris LaPierre
Cris LaPierre on 31 Dec 2018
Is the label an image? I'd suggest looking at this example on optical character recognition.
Code up what you can, and then come back with specific questions about any parts you are getting stuck on.
  7 Comments
Cris LaPierre
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.
  1. Use 'ismember' to determine which word is the month
  2. Use the bounding box y-position to find the other words on the same line
  3. Put the words together to recreate the date
  4. 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))
Stevie
Stevie on 1 Jan 2019
Many thanks for all of your help! you've been a great help.

Sign in to comment.

More Answers (0)

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!