如何使用Tesseract 3.04正确提取图像的方向信息?

时间:2016-03-07 14:55:23

标签: orientation ocr tesseract

我有Tesseract 3.04静态版本,并尝试使用official samples中提供的代码提取方向信息:

 const char* inputfile = "/usr/src/tesseract/testing/eurotext.tif";
  tesseract::Orientation orientation;
  tesseract::WritingDirection direction;
  tesseract::TextlineOrder order;
  float deskew_angle;

  PIX *image = pixRead(inputfile);
  tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
  api->Init("/usr/src/tesseract/", "eng");
  api->SetPageSegMode(tesseract::PSM_AUTO_OSD);
  api->SetImage(image);
  api->Recognize(0);

  tesseract::PageIterator* it =  api->AnalyseLayout();
  it->Orientation(&orientation, &direction, &order, &deskew_angle);
  printf("Orientation: %d;\nWritingDirection: %d\nTextlineOrder: %d\n" \
         "Deskew angle: %.4f\n",
         orientation, direction, order, deskew_angle);

我的应用程序在以下行提取时崩溃:

it->Orientation(&orientation, &direction, &order, &deskew_angle);

此代码出了什么问题?

谢谢!

2 个答案:

答案 0 :(得分:0)

如果您对方向信息感兴趣,可以使用leptonica代替。 IMO应该更快。见example

答案 1 :(得分:0)

我通过下面的代码在tesserect中找到了方向,它返回0,1(= 90),2(= 180),3(= 270)方向

#include <osdetect.h>
#include <baseapi.h>
#include <allheaders.h>
int main()
{
    TessBaseAPI *tessBaseAPI = new TessBaseAPI();
    tessBaseAPI ->Init("/tessdataPath/", "eng")) 
    Pix *image = pixRead(imagePath);
    tessBaseAPI->SetImage(image);
    //orientation
    OSResults os_results;
    tessBaseAPI->DetectOS(&os_results);
    int orientationType=os_results.best_result.orientation_id
    pixDestroy(&image);
    return 0;
}