I have to count the characters that is printed in a beverage tin[1]. So far i have done till removing noise and unwanted pixels and now my text is clear to read 2 but is there any way to count them properly. Ocr fails to detect this text. Or should i join these dots using some algorithm and continue with ocr function?
Here is the code which gave me the above picture.
clear all; close all;
a=imread('coke.jpg');
gray=rgb2gray(a);
thres=150;
lbw=double(gray>thres);
imwrite(lbw,'--\OCR\output.png');
a=imread('output.png');
c=imresize(a,.5);
b = im2bw(c, .9);
b=imcomplement(b);
imwrite(b,'compli.png');
You should definitely join the dots. The first thing I would try is the imclose
function, which does morphological closing (dilation followed by erosion).
For example, you could try this:
im = imread('dotMatrix.png');
im2 = imclose(im, strel('line', 5, 90));
im3 = imclose(im2, strel('line', 5, 45));