繁体   English   中英

通过Boost将图像从Python发送到C ++

[英]Send image from Python to C++ through Boost

我正在尝试使用Boost在Python上优化我的程序,并用C ++函数替换一些Python代码。

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);`

所以,我需要做两件事:

  1. 使用Boost.Python将图像从Python发送到C ++。
  2. 将图像数组发送到C ++(我想通过在C ++中使用多线程来提高性能)。

您可以尝试使用包含tesseract的C ++ API的tesserocr

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一次并使用它来处理多个图像。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM