

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# ドキュメントページ上のアイテムの場所
<a name="text-location"></a>

Amazon Textract オペレーションは、ドキュメントページで見つかったアイテムの場所とジオメトリを返します。[DetectDocumentText](API_DetectDocumentText.md)そして[GetDocumentTextDetection](API_GetDocumentTextDetection.md)ラインと単語の位置とジオメトリを返します。[AnalyzeDocument](API_AnalyzeDocument.md)そして[GetDocumentAnalysis](API_GetDocumentAnalysis.md)キーと値のペア、表、セル、選択要素の位置とジオメトリを返します。

ドキュメントページのアイテムがどこにあるかを確認するには、境界ボックス ([Geometry](API_Geometry.md)) Amazon Textract オペレーションによって返される情報[Block](API_Block.md)オブジェクト。-`Geometry`オブジェクトには、検出されたアイテムに関する 2 種類の位置情報とジオメトリ情報が含まれています。
+ 軸に位置合わせされたもの[BoundingBox](API_BoundingBox.md)アイテムの左上の座標、および幅と高さを含むオブジェクト。
+ アイテムのアウトラインを記述するポリゴンオブジェクト。の配列として指定します。[Point](API_Point.md)を含むオブジェクト`X`(横軸) と`Y`(垂直軸) 各ポイントのドキュメントページ座標。

の JSON`Block`オブジェクトは次のようになります。注意してください`BoundingBox`そして`Polygon`フィールド。

```
{
    "Geometry": {
        "BoundingBox": {
            "Width": 0.053907789289951324, 
            "Top": 0.08913730084896088, 
            "Left": 0.11085548996925354, 
            "Height": 0.013171200640499592
        }, 
        "Polygon": [
            {
                "Y": 0.08985357731580734, 
                "X": 0.11085548996925354
            }, 
            {
                "Y": 0.08913730084896088, 
                "X": 0.16447919607162476
            }, 
            {
                "Y": 0.10159222036600113, 
                "X": 0.16476328670978546
            }, 
            {
                "Y": 0.10230850428342819, 
                "X": 0.11113958805799484
            }
        ]
    }, 
    "Text": "Name:", 
    "TextType": "PRINTED",
    "BlockType": "WORD", 
    "Confidence": 99.56285858154297, 
    "Id": "c734fca6-c4c4-415c-b6c1-30f7510b72ee"
},
```

ジオメトリ情報を使用して、検出されたアイテムの周囲に境界ボックスを描画できます。の例を挙げて`BoundingBox`そして`Polygon`各単語の先頭と末尾の線と垂直線の周りにボックスを描くための情報。[Amazon Textract でドキュメントテキストの検出](detecting-document-text.md)。出力例は、次の例のようになります。

![](http://docs.aws.amazon.com/ja_jp/textract/latest/dg/images/janedoe.png)


## 境界ボックス
<a name="bounding-box"></a>

境界ボックス (`BoundingBox`) には以下のプロパティがあります。
+ Height — ドキュメントページ全体の高さの比率としての境界ボックスの高さ。
+ Left — ドキュメントページ全体の幅の比率としての境界ボックスの左上ポイントの X 座標。
+ Top-ドキュメントページ全体の高さの比率としての境界ボックスの左上のポイントの Y 座標。
+ Width — ドキュメントページ全体の幅の比率としての境界ボックスの幅。

各 BoundingBox プロパティには、0 から 1 の値があります。値は、画像全体の幅の比率です (`Left`そして`Width`) または高さ (に適用)`Height`そして`Top`). たとえば、入力イメージが 700 x 200 ピクセルの場合、境界ボックスの左上の座標は 350,50 ピクセルで、API は`Left`0.5 (350/700) の値と a`Top`0.25 (50/200) の値です。

次の図は、各 BoundingBox プロパティがカバーするドキュメントページの範囲を示しています。

![](http://docs.aws.amazon.com/ja_jp/textract/latest/dg/images/bounding-box.png)


適切な場所に適切なサイズで境界ボックスを表示するには、ピクセル値を取得するには、BoundingBox 値にドキュメントのページの幅または高さ (必要な値に応じて) を掛ける必要があります。境界ボックスを表示するには、ピクセル値を使用します。たとえば、幅608 ピクセル x 高さ 588 ピクセルのドキュメントページと、分析されたテキストに次の境界ボックス値を使用します。

```
BoundingBox.Left: 0.3922065
BoundingBox.Top: 0.15567766
BoundingBox.Width: 0.284666
BoundingBox.Height: 0.2930403
```

テキスト境界ボックスの位置 (ピクセル) は次のように計算されます。

`Left coordinate = BoundingBox.Left (0.3922065) * document page width (608) = 238`

`Top coordinate = BoundingBox.Top (0.15567766) * document page height (588) = 91`

`Bounding box width = BoundingBox.Width (0.284666) * document page width (608) = 173`

`Bounding box height = BoundingBox.Height (0.2930403) * document page height (588) = 172`

これらの値を使用して、解析されたテキストの周囲に境界ボックスを表示します。次の Java および Python の例で、境界ボックスを表示する方法を示しています。

------
#### [ Java ]

```
    public void ShowBoundingBox(int imageHeight, int imageWidth, BoundingBox box, Graphics2D g2d) {

        float left = imageWidth * box.getLeft();
        float top = imageHeight * box.getTop();

        // Display bounding box.
        g2d.setColor(new Color(0, 212, 0));
        g2d.drawRect(Math.round(left / scale), Math.round(top / scale),
                Math.round((imageWidth * box.getWidth()) / scale), Math.round((imageHeight * box.getHeight())) / scale);

    }
```

------
#### [ Python ]

この Python の例では、`response`によって返される[DetectDocumentText](API_DetectDocumentText.md)API オペレーション。

```
def process_text_detection(response):

    # Get the text blocks
    blocks = response['Blocks']
    width, height = image.size
    draw = ImageDraw.Draw(image)
    print('Detected Document Text')

    # Create image showing bounding box/polygon the detected lines/text
    for block in blocks:

        draw = ImageDraw.Draw(image)

        if block['BlockType'] == "LINE":
            box=block['Geometry']['BoundingBox']
            left = width * box['Left']
            top = height * box['Top']
            draw.rectangle([left,top, left + (width * box['Width']), top +(height * box['Height'])],outline='black')

    # Display the image
    image.show()

    return len(blocks)
```

------

## Polygon
<a name="polygon"></a>

によって返されるポリゴン`AnalyzeDocument`の配列です。[Point](API_Point.md)オブジェクト。Eachy`Point`は、ドキュメントページ上の特定の場所の X 座標と Y 座標を持ちます。BoundingBox 座標と同様に、ポリゴン座標はドキュメントの幅と高さに正規化され、0 ～ 1 の間になります。

ポリゴン配列内のポイントを使用して、細粒度の境界ボックスを囲むように表示することができます。`Block`オブジェクト。ドキュメントページ上の各ポリゴンポイントの位置を計算するには、`BoundingBoxes`。X 座標にドキュメントページの幅を掛け、Y 座標にドキュメントページの高さを掛けます。

次の例は、ポリゴンの垂直線を表示する方法を示しています。

```
    public void ShowPolygonVerticals(int imageHeight, int imageWidth, List <Point> points, Graphics2D g2d) {

        g2d.setColor(new Color(0, 212, 0));
        Object[] parry = points.toArray();
        g2d.setStroke(new BasicStroke(2));

        g2d.drawLine(Math.round(((Point) parry[0]).getX() * imageWidth),
                Math.round(((Point) parry[0]).getY() * imageHeight), Math.round(((Point) parry[3]).getX() * imageWidth),
                Math.round(((Point) parry[3]).getY() * imageHeight));

        g2d.setColor(new Color(255, 0, 0));
        g2d.drawLine(Math.round(((Point) parry[1]).getX() * imageWidth),
                Math.round(((Point) parry[1]).getY() * imageHeight), Math.round(((Point) parry[2]).getX() * imageWidth),
                Math.round(((Point) parry[2]).getY() * imageHeight));

    }
```