I am using Microsoft MODI
in VB6
to OCR an image. (I know about other OCR tools like tesseract etc but I find MODI more accurate than other)
The image to be OCRed is like this
and, the text the I get after OCR is like below
Text1
Text2
Text3
Number1
Number2
Number3
The problem here is that corresponding text from opposite column is not maintained. How can I map Number1 with Text1?
I can only think of a solution like this.
MODI provides co-ordinates of all the OCRed words like this
LeftPos = Img.Layout.Words(0).Rects(0).Left
TopPos = Img.Layout.Words(0).Rects(0).Top
So to align words in same line, we can match TopPos of each word and then sort them by LeftPos. We will get the complete line. So I looped through all the words and stored their text as well as left and top in a mysql table. then ran this query
SELECT group_concat(word ORDER BY `left` SEPARATOR ' ')
FROM test_copy
GROUP BY `top`
My problem is, That Top positions are not exact same for each word, Obviously there will be couple of pixel differences.
I tried adding DIV 5
, for merging words that are in 5 pixels range but that doesn't work for some cases. I also tried doing it in node.js by calculating tolerance for each word and then sorting by LeftPos but I still feel this is not the best way to do it.
Update: The js code does the job but except for the case where Number1 has 5 pixel difference and Text2 has no corresponding in that line.
Is there any better idea to do this?