【问题标题】:Azure Form Recognizer boundingBox result convert to XY coordinationAzure 表单识别器边界框结果转换为 XY 坐标
【发布时间】:2019-05-19 15:35:18
【问题描述】:

我想将表单识别器“boundingBox”的结果转换为图像坐标,以可视化叠加图像和识别的数据。 但是,boundingBox 结果看起来不像此图像这样的 XY 坐标位置。 https://i.stack.imgur.com/DOEi5.png

我需要每个boundingBox的左上(X1,Y1)右下(X2,Y2)计算规则。

我也用认知服务 OCR 和文本识别做了一些计算规则,但没有关于表单识别器的信息。 我试图通过减号或除法找到 XY 坐标规则,但没有找到规则。

这是我通过表单识别器的示例图像获得的结果 json 数据。但无法从中找到 boundingBox 规则。

Responsebody: {
  'status': 'success',
  'pages': [
    {
      'number': 1,
      'height': 792,
      'width': 612,
      'clusterId': 0,
      'keyValuePairs': [
        {
          'key': [
            {
              'text': 'Address:',
              'boundingBox': [
                57.3,
                683.0,
                100.5,
                683.0,
                100.5,
                673.7,
                57.3,
                673.7
              ]
            }
          ],
          'value': [
            {
              'text': '1020 Enterpirse Way.',
              'boundingBox': [
                57.3,
                672.2,
                153.1,
                672.2,
                153.1,
                658.8,
                57.3,
                658.8
              ],
              'confidence': 0.53
            },

我需要每个boundingBox的左上(X1,Y1)和右下(X2,Y2)计算规则。

感谢团队。

【问题讨论】:

  • 也许我误解了你的问题,但不是你正在寻找的 boundingBox 属性吗?这八个数字代表文本框所有四个角的 X 和 Y。

标签: azure preview opencv-python form-recognizer


【解决方案1】:

这 8 个数字代表 4 对边界框角的 (x,y) 坐标,顺序如下:左上、右上、右下、左下。坐标系的原点是页面的左下角。对于示例中的键“地址:”,左上角 (X1, Y1) = (57.3, 683.0) 和右下角 (X2, Y2) = (100.5, 673.7)。

【讨论】:

    【解决方案2】:

    我在使用表单识别器时也遇到过这种困惑。它的原点位于页面的左下角。

    // Azure Bounding box is like this                      0---->1
    //                                                      |     |
    //                                         Y            |     |
    //                                         ↑            3<----2
    //                                  Origin . → X
    
    
    
    // Expected Bounding Box            Origin . → X
    //                                         ↓            0---->1
    //                                         Y            |     |
    //                                                      |     ↓
    //                                                      3<----2
    

    这八个值是 4 个点的 X、Y 值。您可以选择左上角的第 0、第 1 和右下角的第 4、第 5。 如果您想标准化坐标以保持值在 0 和 1 之间,则必须将每个像素值除以相应页面的宽度和高度。

    【讨论】:

      【解决方案3】:

      在示例中:

      'boundingBox': [
                  57.3,
                  683.0,
                  100.5,
                  683.0,
                  100.5,
                  673.7,
                  57.3,
                  673.7
                ]
      

      表示边界框的顶点。

      // Azure Bounding box:           (57.3,683.0) X1,Y1---->x2,y2(100.5,683.0)
                                                        |     |
                                                        |     |
                                       (57.3,673.7) X4,Y4<----x3,y3(100.5,673.7)
      

      从上面的例子中,选择(X1,y1)和(x3,y3)来绘制一个边界框。边界框在 Azure 中是非常连续的,它从 x1、y1、x2、y2、x3、y3、x4、y4 开始。列表中的前两个值是 x1,y1,第 5,6 个是 x3,y3。

      【讨论】:

        【解决方案4】:

        仅提供一个具体示例,请考虑以下输入图像:https://imgur.com/a/zUeqe0L

        Azure 表单识别器返回以下边界框,您可以使用以下代码 sn-p 和opencv-python 绘制边界框:

        import cv2
        import numpy as np
        import matplotlib.pylab as plt
        image = cv2.imread('adhar2.jpg')
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        boundingBox = [42.0, 84.0, 227.0, 0.0, 246.0, 41.0, 61.0, 126.0]
        pts = np.array(boundingBox, np.int32).reshape((-1,1,2))
        image = cv2.polylines(image, [pts], True, (0, 255, 0), 2)
        plt.figure(figsize=(20,40))
        plt.imshow(image)
        plt.axis('off')
        plt.show()
        

        使用以下输出图像:

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-08-01
          • 1970-01-01
          • 2022-12-28
          • 1970-01-01
          • 2021-09-03
          • 1970-01-01
          • 1970-01-01
          • 2019-06-18
          相关资源
          最近更新 更多