【问题标题】:Train tesseract for Hindi language为印地语训练 tesseract
【发布时间】:2014-12-20 13:09:33
【问题描述】:

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

【问题讨论】:

    标签: ocr tesseract


    【解决方案1】:

    我一直想自己训练几个字符集,并首先收集信息。也许这些信息对你也有用。

    您是否阅读过此文档:

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

    如果没有一个字符被识别,恐怕你将不得不训练所有字符。但重要的步骤似乎是:

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

    • 注意 tesseract 的版本。我的印象是训练过程在上一个版本中发生了变化。

    【讨论】:

      【解决方案2】:

      从图像中识别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;
      
      }
      

      【讨论】:

      • 如果你想要比这更高的精度,那么你可以在 pixeRead() 中传递 OTSU 阈值图像。我现在在 pixRead() 中传递正常图像。通过 OTSU 阈值图像。我为此开发了算法。 .如果有人想要,请告诉我。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-04
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2012-11-05
      相关资源
      最近更新 更多