Tuesday, January 22, 2013

Simple OCR in Visual Basic 6


Do you want to make an application that has OCR ability within vb6?  Well, I did and I almost gave up because I could not find an OCR ActiveX.  Then I found Tesseract.
Although it is not an ActiveX and seems only usable for Visual Basic 2008 or higher, but we can actually make use of its capability.

Download tesseract from here and install. Then insert this line in your VB code:

Shell "tesseract <image files> <output file>"

for example:

Shell "tesseract c:\cap.bmp c:\output", vbHide

Tesseract will convert the image ("cap.bmp") into text and save it into a TXT file ("output.txt").  Then, all you have to do is read the output file.

Here is a short demo video:


The VB6 Project can be downloaded here.

UPDATE
Shelling tesseract in Windows7 doesn't work.  The quick solution is to create *.bat file, and shell it.

You can create *.bat file in notepad with following line:

tesseract c:\cap.bmp c:\output

For example, if you create "ocr.bat", the shell command in vb6 will look like:

Shell "c:\ocr.bat", vbHide