OCR toolkit for use in a C++ program

Asked By 260 points N/A Posted on -
qa-featured

Hi,

I want to make a software that scans an Image (admission form) and identifies the Text within its fields. And puts them in some File. I am doing this in C++. I have some little experience with opencV but not as much as is required to do the OCR thing. So I realized a solution. Call an external Command Line tool which converts an image to text. Then my program just needs to fetch the required data from the text file. Its  kind of funny I believe, I don't actually know if I have any other options in hand. So my question is:

"Is there any API sort of thing that can be called from my program to convert an image to text?"

SHARE
Best Answer by shababhsiddique
Best Answer
Best Answer
Answered By 0 points N/A #91562

OCR toolkit for use in a C++ program

qa-featured

If your question was for the API. Then I don't know of any which is free  and yes, if u want to do the same thing in some other way (calling external program which does the OCR thing) as you mentioned then, there is a tool named "Tesseract".  It is as far as I know the simplest to start with and the accuracy is also notable. You can download it from Google code:

Download Tesseract

After installing, just issue this in the cmd: Tesseract testimage.tif outputtext

Here testimage.tif is the image file that contains the form and output text is the text file which shall be used to write the extracted data.

Answered By 260 points N/A #91563

OCR toolkit for use in a C++ program

qa-featured

Thanks for the reply. It is useful but how do I convert my scanned image (in jpeg) to tif? And one more thing, tesseract doesn't seem to be saving alignment. A multi lined document just gets messy. Am I doing something wrong?

Answered By 0 points N/A #91564

OCR toolkit for use in a C++ program

qa-featured

As far as I know tesseract doesn't support multi lined OCR. This may be the cause. If you want to convert the admission form to text then, use your OpenCV skills to slice the form to each fields( e. g. name, address number). Save each slice as a different .tif file. This will also solve your conversion problem and then call tesseract to each of this sliced pieces of image to generate text for each field.

Answered By 260 points N/A #91565

OCR toolkit for use in a C++ program

qa-featured

I am trying to do as you said, but a little problem.

    cvSetImageROI(img, cvRect(645,1468,565,75));

    cvSaveImage("firstName.tif",img);
    system("tesseract firstName.tif temp");
    fio.open("temp.txt");
    getline(fio,s1.firstname);
    fio.close();

    cvSetImageROI(img, cvRect(390,290,280,60));
    cvSaveImage("formNumber.tif",img);

   system("tesseract firstName.tif temp");

The program crashes for some reason stating, "CV_image buffer overloaded".

Answered By 0 points N/A #91566

OCR toolkit for use in a C++ program

qa-featured

It crashes because you haven't reset the ROI after each crop. Use something like this:

    cvSetImageROI(img, cvRect(645,1468,565,75));
    cvSaveImage("firstName.tif",img);
    cvResetImageROI(img); // After saving is done reset the image ROI to original size

    system("tesseract firstName.tif temp");

    fio.open("temp.txt");
    getline(fio,s1.firstname);
    fio.close();

    cvSetImageROI(img, cvRect(390,290,280,60)); //now new roi works as the first one
    cvSaveImage("formNumber.tif",img);
    cvResetImageROI(img);                      

    system("tesseract formNumber.tif temp");

Related Questions