MATLAB: Reading seven segment display with OCR command

image processingMATLABocrseven digit display

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

Best Answer

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?