

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# 문서 페이지의 항목 위치
<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`object는 탐지된 항목에 대한 두 가지 유형의 위치 및 형상 정보를 포함합니다.
+ 축 정렬[BoundingBox](API_BoundingBox.md)왼쪽 위 좌표와 항목의 너비와 높이가 포함된 객체입니다.
+ 항목의 아웃라인을 설명하는 폴리곤 객체로, 배열로 지정됩니다.[Point](API_Point.md)다음을 포함하는 객체`X`(가로 축) 및`Y`(세로 축) 각 점의 페이지 좌표를 문서화합니다.

a를 위한 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 Textract를 사용하여 문서 텍스트 감지](detecting-document-text.md). 예제 출력은 다음과 비슷합니다.

![\[alt text not found\]](http://docs.aws.amazon.com/ko_kr/textract/latest/dg/images/janedoe.png)


## Bounding Box
<a name="bounding-box"></a>

경계 상자 (`BoundingBox`) 에는 다음과 같은 속성이 있습니다.
+ 높이 — 전체 문서 페이지 높이에 대한 비율로서 경계 상자의 높이입니다.
+ Left — 전체 문서 페이지 너비에 대한 비율로서 경계 상자의 상단 좌측 포인트에 대한 X 좌표입니다.
+ Top — 전체 문서 페이지 높이에 대한 비율로서 경계 상자의 상단 지점에 대한 Y 좌표입니다.
+ 너비 — 전체 문서 페이지 너비에 대한 비율로서 경계 상자의 너비입니다.

각 BoundingBox 속성은 0\$11 사이의 값을 가집니다. 값은 전체 이미지 너비에 대한 비율입니다.`Left`과`Width`) 또는 높이 (적용`Height`과`Top`). 예를 들어 입력 이미지가 700x200픽셀이고 경계 상자의 상단 좌측 좌표가 (350,50) 픽셀일 경우 API는`Left`값 0.5 (350/700) 및`Top`값은 0.25 (50/200) 입니다.

다음 다이어그램은 각 BoundingBox 속성이 다루는 문서 페이지의 범위를 보여 줍니다.

![\[Diagram showing bounding box properties: Top, Left, Width, and Height within an image.\]](http://docs.aws.amazon.com/ko_kr/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 ]

이 파이썬 예제는`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)
```

------

## 다각형
<a name="polygon"></a>

에 의해 반환된 폴리곤`AnalyzeDocument`는 다음과 같은 배열입니다.[Point](API_Point.md)객체입니다. Each`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));

    }
```