如何將 C++ tesseract-ocr 代碼轉換為 Python? (how to convert C++ tesseract-ocr code to Python?)


問題描述

如何將 C++ tesseract‑ocr 代碼轉換為 Python? (how to convert C++ tesseract‑ocr code to Python?)

我想在tesseract‑ocr doc中轉換C++版本Result iterator example到 Python。

  Pix *image = pixRead("/usr/src/tesseract/testing/phototest.tif");
  tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
  api‑>Init(NULL, "eng");
  api‑>SetImage(image);
  api‑>Recognize(0);
  tesseract::ResultIterator* ri = api‑>GetIterator();
  tesseract::PageIteratorLevel level = tesseract::RIL_WORD;
  if (ri != 0) {
    do {
      const char* word = ri‑>GetUTF8Text(level);
      float conf = ri‑>Confidence(level);
      int x1, y1, x2, y2;
      ri‑>BoundingBox(level, &x1, &y1, &x2, &y2);
      printf("word: '%s';  \tconf: %.2f; BoundingBox: %d,%d,%d,%d;\n",
               word, conf, x1, y1, x2, y2);
      delete[] word;
    } while (ri‑>Next(level));
  }

到目前為止我能做的如下:

import ctypes
liblept = ctypes.cdll.LoadLibrary('liblept‑5.dll')
pix = liblept.pixRead('11.png'.encode()) 
print(pix)

tesseractLib = ctypes.cdll.LoadLibrary(r'C:\Program Files\tesseract‑OCR\libtesseract‑4.dll')

tesseractHandle = tesseractLib.TessBaseAPICreate()

tesseractLib.TessBaseAPIInit3(tesseractHandle, '.', 'eng')

tesseractLib.TessBaseAPISetImage2(tesseractHandle, pix)
#tesseractLib.TessBaseAPIRecognize(tesseractHandle, tesseractLib.TessMonitorCreate())

我無法轉換 C++ api‑>Recognize(0)到 Python(我嘗試過的是代碼的最後一行(註釋),但它是錯誤的),我對 C++ 沒有經驗,所以我不能再繼續了,任何人都可以幫助轉換嗎?API:


#tesseract #Python #python-tesseract #C++






相關問題

Android Studio 如何修復無法創建類文件錯誤? (Android Studio How to fix cannot create class-file error?)

Python - 程序收到信號 SIGSEGV,分段錯誤 (Python - Program received signal SIGSEGV, Segmentation fault)

Tesseract OCR 在線程中使用時崩潰 (Tesseract OCR crash when used in thread)

如何將 Leptonica Pix 對象轉換為 Android 的位圖 (How to convert Leptonica Pix Object to Android's Bitmap)

錯誤 2 在 pytesseract 中沒有這樣的文件或目錄 (Error 2 No such file or directory in pytesseract)

OCR:沒有得到想要的結果 (OCR : Not getting desired result)

在 x64 位機器上的 Visual Studio 2013 中鏈接 tesseract 和 opencv (Linking tesseract and opencv in Visual Studio 2013 on x64 bit machine)

如何提高讀取正方體的準確性? (How to improve read tesseract accuracy?)

如何將 C++ tesseract-ocr 代碼轉換為 Python? (how to convert C++ tesseract-ocr code to Python?)

Tesseract Worker.Load 掛在 Vercel 上 (Tesseract Worker.Load hangs on Vercel)

如何在窗口上使用 MinGW 編譯 tesseract baseapi.h? (How to compile tesseract baseapi.h with MinGW on window?)

Pytesseract 或 Keras OCR 從圖像中提取文本 (Pytesseract or Keras OCR to extract text from image)







留言討論