2016-10-22 14 views
1

我想用Boost優化我的Python程序,並用C++函數替換一些Python代碼。通過Boost將圖像從Python發送到C++

Python代碼:

from PIL import Image 
for i in xrange(len(lines)): 
    im = Image.fromarray(lines[i]) 
    line = pytesseract.image_to_string(im, "ukr+ukrb") # working to slow 

和代碼在C++:

Pix *image = pixRead("/home/lucas63/Downloads/test.tif"); # here i need to get image directly from Python 
api->SetImage(image); 
outText = api->GetUTF8Text(); 
printf("OCR output:\n%s", outText);` 

所以,我需要做兩件事情:從Python來

  1. 發送圖像C++使用Boost.Python
  2. 向C++發送圖像數組(我想通過在C++中使用多線程處理來提高性能)。

回答

0

您可以嘗試使用tesserocr圍繞正方體的C++ API包裝:

import tesserocr 

with tesserocr.PyTessBaseAPI(lang='ukr+ukrb') as api: 
    for l in lines: 
     im = Image.fromarray(l) 
     api.SetImage(im) 
     line = api.GetUTF8Text() 

這一次初始化API,並用它來處理多個圖像。

+0

感謝您的回答,我將嘗試用tesserocr替換py-tesseract,並且稍後我會寫關於結果 – lucas63

+0

Ty的幫助,現在它工作得更好 – lucas63