【问题标题】:Char's bounding box order of verticesChar的边界框顶点顺序
【发布时间】:2017-06-19 16:06:25
【问题描述】:

Google Vision API 文档指出检测到的字符的顶点将始终保持相同的顺序:

// The bounding box for the symbol.
// The vertices are in the order of top-left, top-right, bottom-right,
// bottom-left. When a rotation of the bounding box is detected the rotation
// is represented as around the top-left corner as defined when the text is
// read in the 'natural' orientation.
// For example:
//   * when the text is horizontal it might look like:
//      0----1
//      |    |
//      3----2
//   * when it's rotated 180 degrees around the top-left corner it becomes:
//      2----3
//      |    |
//      1----0
//   and the vertice order will still be (0, 1, 2, 3).

但有时我可以看到不同的顶点顺序。以下是来自同一图像的两个字符的示例,它们具有相同的方向:

[x:778 y:316  x:793 y:316  x:793 y:323  x:778 y:323 ]
0----1
|    |
3----2

[x:857 y:295  x:857 y:287  x:874 y:287  x:874 y:295 ]
1----2
|    |
0----3

为什么顶点的顺序不一样?而不是在文档中?

【问题讨论】:

    标签: google-cloud-platform ocr google-cloud-vision


    【解决方案1】:

    这似乎是 Vision API 中的一个错误。 解决方案是检测图像方向,然后以正确的顺序重新排列顶点。

    不幸的是,Vision API 在其输出中不提供图像方向,所以我不得不编写代码来检测它。

    可以通过比较字符的高度和宽度来检测水平/垂直方向。高度通常大于宽度。

    下一步是检测文本的方向。例如,在垂直图像方向的情况下,文本可能从上到下或从下到上。

    输出中的大多数字符似乎都以自然的方式出现。因此,通过查看统计数据,我们可以检测文本方向。例如: 第 1 行的 Y 坐标为 1000 第 2 行的 Y 坐标为 900 第 3 行的 Y 坐标为 950 第 4 行的 Y 坐标为 800 我们可以看到图像是倒置的。

    【讨论】:

    • 之前也遇到过同样的问题。使用字符宽度和高度似乎是个好主意。 (Y)
    • 从我的结果中可以看出,顶点总是正确的,但 OCR 本身并没有找到单词的正确方向。在我的例子中,我有带有简单文本文档的图像。但是图像被逆时针旋转了 90 度。大多数单词都被正确检测到,并且顶点符合预期。对于某些单词,顶点旋转了 180 度,而 OCR 真正“读取”了颠倒的单词(并且得到了错误的读数)。
    【解决方案2】:

    You must to reorder vertices of four poins(clockwise inverted from A to D):
    A-B-C-D that:
    A: min X, min Y
    B: max X, min Y
    C: max X, max Y
    D: min X, max Y
    
    And save to your rectangle object.

    更新:对于上面的 A-B-C-D 顺序,您可以按距 O(0,0) 的距离对顶点进行排序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2021-08-26
      • 1970-01-01
      • 2011-10-23
      • 2020-06-04
      • 2019-04-14
      • 1970-01-01
      相关资源
      最近更新 更多