2016-10-22 55 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