首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python-tesseract中的访问信任

python-tesseract中的访问信任
EN

Stack Overflow用户
提问于 2015-06-07 00:23:16
回答 1查看 2.2K关注 0票数 1

我试图为python构建一个OCR扩展,它专门处理具有内部结构的数据表(例如,包含小计和行和列的汇总,允许用户通过强制结构来提高准确性)。

我试图访问信任测试服务分配给多个结果(例如,所有来自无约束运行的结果和所有仅限于[0-9\.]字符的运行结果)。

我看到了一些关于访问python方法的x_wconf属性的信息,但是还没有弄清楚如何从python访问它。如何调用/访问此值?谢谢!

我在OSX10.10.3和Python2.7上使用0.9.1。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-23 20:44:33

编辑

其实我搞错了,我想到的是pytesseract,而不是pytesseract。

如果您查看API源(baseapi_mini.h),您会发现有些函数听起来非常适合您所要做的工作。您感兴趣的部分大约是第500行左右。

代码语言:javascript
复制
  char* GetUTF8Text();

  /**
   * Make a HTML-formatted string with hOCR markup from the internal
   * data structures.
   * page_number is 0-based but will appear in the output as 1-based.
   */
  char* GetHOCRText(int page_number);
  /**
   * The recognized text is returned as a char* which is coded in the same
   * format as a box file used in training. Returned string must be freed with
   * the delete [] operator.
   * Constructs coordinates in the original image - not just the rectangle.
   * page_number is a 0-based page index that will appear in the box file.
   */
  char* GetBoxText(int page_number);
  /**
   * The recognized text is returned as a char* which is coded
   * as UNLV format Latin-1 with specific reject and suspect codes
   * and must be freed with the delete [] operator.
   */
  char* GetUNLVText();
  /** Returns the (average) confidence value between 0 and 100. */
  int MeanTextConf();
  /**
   * Returns all word confidences (between 0 and 100) in an array, terminated
   * by -1.  The calling function must delete [] after use.
   * The number of confidences should correspond to the number of space-
   * delimited words in GetUTF8Text.
   */
  int* AllWordConfidences();

  /**
   * Applies the given word to the adaptive classifier if possible.
   * The word must be SPACE-DELIMITED UTF-8 - l i k e t h i s , so it can
   * tell the boundaries of the graphemes.
   * Assumes that SetImage/SetRectangle have been used to set the image
   * to the given word. The mode arg should be PSM_SINGLE_WORD or
   * PSM_CIRCLE_WORD, as that will be used to control layout analysis.
   * The currently set PageSegMode is preserved.
   * Returns false if adaption was not possible for some reason.
   */

mini.h?at=master

我最初的回答

为了做到这一点,您必须编写自己的包装器。

python很好,因为它可以让您快速地运行,但这不是我所称的复杂。您可以阅读源代码并查看它是如何工作的,但下面是简要说明:

  1. 将输入图像写入临时文件
  2. 调用该文件上的tesseract命令(从命令行)
  3. 返回结果

所以如果你想做什么特别的事情,这根本行不通。

我有一个需要高性能的应用程序,等待文件写入磁盘所花费的时间,等待tesseract启动并加载映像并处理它的时间太长了。

如果我没有记错(我已经不能访问源了),我就使用ctype加载一个tesseract进程,设置图像数据,然后调用GetHOCRText方法。然后,当我需要处理另一个映像时,我不必等待tesseract再次加载,只需设置映像数据并再次调用GetHOCRText。

因此,这并不是解决问题的确切方法,也绝对不是您可以使用的代码片段。但希望它能帮助你朝着你的目标前进。

下面是关于包装外部库的另一个问题:Wrapping a C library in Python: C, Cython or ctypes?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30688840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档