为印地语训练tesseract

时间:2014-12-20 13:09:33

标签: ocr tesseract

我想训练我的印地语语言。我有很多印地语'带有特定字体的书面文字图像,我想为这些图像训练tesseract ocr。    有几次我尝试使用此链接https://code.google.com/p/tesseract-ocr/wiki/TrainingTesseract3训练tesseract。当我运行makebox命令时,它会提取框文件,但它会识别出英文字符。我不明白为什么会这样。请帮我训练tesseract ocr for Hindi语言。     您可以在以下链接上查看示例图像。     sample file

2 个答案:

答案 0 :(得分:0)

我一直想自己训练一些角色,并且一直在收集信息。也许这些信息也对你有用。

您是否阅读了此文件:

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

如果没有识别出任何一个角色,你将不得不训练所有角色,我很害怕。但重要的步骤似乎是:

  • 在makebox命令行中包含语言指示(' eng')(在您的情况下,这可能是' hin'

  • 了解tesseract的版本。我的印象是培训程序在最新版本中发生了变化。

答案 1 :(得分:0)

从图像中识别Hindi字符的示例程序,并将相应的边界框值和相应的印地文字符存储区存储到一个文件中。

/*
 * 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;

}
相关问题