Prasad Bhosale
Prasad Bhosale

Reputation: 722

Train tesseract for Hindi language

I want to train my tesseract for hindi language . I have many 'hindi' written text images with specific font and I would like to train tesseract ocr for that images . Several times I tried train tesseract using this link https://code.google.com/p/tesseract-ocr/wiki/TrainingTesseract3 . when I run makebox command it extracts box file but it recognises like english character. I dont understand why this happen. Please help me to train tesseract ocr for Hindi language. You can check sample image on following link. sample file

Upvotes: 1

Views: 5260

Answers (3)

Aifos Si Prahs
Aifos Si Prahs

Reputation: 363

Currently the Tesseract API provides pre-trained language models for most of the popular languages:

https://tesseract-ocr.github.io/tessdoc/Data-Files-in-different-versions.html

Upvotes: 0

pratik solanki
pratik solanki

Reputation: 41

Sample program of the recognize the Hindi char from the image and store the respective bounding box values and respective Hindi char store into the one file.

/*
 * Char_OCR.cpp
 *
 *  Created on: Jun 23, 2016
 *      Author: pratik
 */

#include <opencv2/opencv.hpp>
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include <iostream>
#include <fstream>

using namespace std;
using namespace cv;

void dumpIntoFile(const char *ocrResult , ofstream &myfile1 ,int x1, int y1,
        int x2, int y2, int &);

int main(int argc ,char **argv)
{

    Pix *image = pixRead(argv[1]);

    if (image == 0) {
        cout << "Cannot load input file!\n";
    }

    tesseract::TessBaseAPI tess;


    if (tess.Init("/usr/share/tesseract/tessdata", "hin")) {
            fprintf(stderr, "Could not initialize tesseract.\n");
            exit(1);
        }

    tess.SetImage(image);
    tess.Recognize(0);

    tesseract::ResultIterator *ri = tess.GetIterator();
    tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;

    cout << ri << endl;

    ofstream myfile1("Word.txt");

    myfile1 << "ID" << '\t' << "CORD_X" << '\t' << "CORD_Y" << '\t' <<
            "CORD_W" << '\t' << "CORD_H" << '\t' << "STRING" << endl;

    int i=1;

    if(ri!=0)
    {
        do {
            const char *word = ri->GetUTF8Text(level);
//          cout << word << endl;

            //float conf = ri->Confidence(level);
            int x1, y1, x2, y2;
            ri->BoundingBox(level, &x1, &y1, &x2, &y2);

            dumpIntoFile(word, myfile1, x1, y1, x2, y2, i);

            delete []word;

        } while (ri->Next(level));

        delete []ri;
    }

}

void dumpIntoFile(const char *ocrResult , ofstream &myfile1 ,int x1, int y1,
        int x2, int y2,int &i)
{

            int length = strlen(ocrResult);

                myfile1 << i++ << '\t' << x1 << '\t' << y1 << '\t' <<
                        x2 << '\t' << y2 << '\t' ;

                //cout << "in the string (" << length << ") ::";
                for(int  j = 0; j < length && ocrResult[j] != '\n'; j++)
                {
                    myfile1 << ocrResult[j];
                }

                myfile1 << endl;

}

Upvotes: 0

jcoppens
jcoppens

Reputation: 5440

I have been wanting to train a few character sets myself, and have been gathering information first. Maybe this info is of use to you too.

Did you read this document:

http://blog.cedric.ws/how-to-train-tesseract-301

If none of the characters are recognized you will have to train all of the characters, I'm afraid. But important steps seem to be:

  • include the indication of the language ('eng') in the makebox command line (this would probably be 'hin' in your case.

  • be aware of the version of tesseract. I have the impression that the training procedure has been changing in the last versions.

Upvotes: 0

Related Questions