Reading seven segment display with OCR command

10 次查看(过去 30 天)
I am trying to read the digits off of Images of a seven segment display, like the one below.
frame1.jpg
b = imread('frame1.jpg'); %image above
imshow(b)
BW1 = imbinarize(rgb2gray(b),0.2);
BW2 = imcomplement(BW1);
figure; imshow(BW2); roi = round(getPosition(imrect));
imshowpair(BW1,BW2,'montage')
ocrResults = ocr(BW2,roi,'CharacterSet','.0123456789','TextLayout','word');
recognizedText = ocrResults.Text;
text(600, 150, recognizedText, 'BackgroundColor', [1 1 1]);
However the ocr command cannot read the digits correclty, as can be seen in the textbox on the processed image below.
Capture.JPG
Are there any pre-processing steps I should additionaly take?
Do I need to use the ocr command in a different way?
Thanks in advance for any suggestions
  1 个评论
Brett Shoelson
Brett Shoelson 2021-3-3
Attempts to do this using image morphology are almost certain to fail under certain conditions. Better: download and install a (freely available) 7-segment font, then use the OCR Trainer App to train the character recognition on samples of those digits. You'll get better results!
Brett

请先登录,再进行评论。

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-7-3
编辑:KALYAN ACHARJYA 2019-7-3
One Suggestion: connect the disconneted pixels, then apply the OCR
You can do that in multiple ways, imdilate , choose proper structuring element.
Let me know the result, is it working?
  1 个评论
Kevin Ammann
Kevin Ammann 2019-7-3
Thank you! Connecting the digits internaly did the trick.
I used imerode in the following way.
...
BW2 = imcomplement(BW1);
SE1 = strel('line',4.5,0);
SE2 = strel('line',4.5,90);
BW2 = imerode(BW2,SE1);
BW2 = imerode(BW2,SE2);
figure; imshow(BW2); roi = round(getPosition(imrect));
...
This solves the problem as stated in my question. However the code is not entirely robust. The initial image above is a frame of a video.
When I apply it to other frames, wrong recognitions still occur. For example with the following initial image.
frame16.jpg
The adjusted code reads the following.
Capture2.JPG
Do you have any suggestions on how to make the code more robust?

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by