Returns the bounds for the boxes around the text detected in a document.

## Explore further


For detailed documentation that includes this code sample, see the following:

- [Dense document text detection tutorial](https://docs.cloud.google.com/vision/docs/fulltext-annotations)
- [Detect text in a document: Bounds](https://docs.cloud.google.com/vision/docs/samples/vision-document-text-tutorial-detect-bounds)

## Code sample

### Python


To learn how to install and use the client library for Vision API Product Search, see
[Vision API Product Search client libraries](https://docs.cloud.google.com/vision/product-search/docs/libraries).


For more information, see the
[Vision API Product Search Python API
reference documentation](https://docs.cloud.google.com/python/docs/reference/vision/latest).


To authenticate to Vision API Product Search, set up Application Default Credentials.
For more information, see

[Set up authentication for a local development environment](https://docs.cloud.google.com/docs/authentication/set-up-adc-local-dev-environment).

    def get_document_bounds(image_file, feature):
        """Finds the document bounds given an image and feature type.

        Args:
            image_file: path to the image file.
            feature: feature type to detect.

        Returns:
            List of coordinates for the corresponding feature type.
        """
        client = vision.ImageAnnotatorClient()

        bounds = []

        with open(image_file, "rb") as image_file:
            content = image_file.read()

        image = vision.Image(content=content)

        response = client.document_text_detection(image=image)
        document = response.full_text_annotation

        # Collect specified feature bounds by enumerating all document features
        for page in document.pages:
            for block in page.blocks:
                for paragraph in block.paragraphs:
                    for word in paragraph.words:
                        for symbol in word.symbols:
                            if feature == FeatureType.SYMBOL:
                                bounds.append(symbol.bounding_box)

                        if feature == FeatureType.WORD:
                            bounds.append(word.bounding_box)

                    if feature == FeatureType.PARA:
                        bounds.append(paragraph.bounding_box)

                if feature == FeatureType.BLOCK:
                    bounds.append(block.bounding_box)

        # The list `bounds` contains the coordinates of the bounding boxes.
        return bounds

## What's next


To search and filter code samples for other Google Cloud products, see the
[Google Cloud sample browser](https://docs.cloud.google.com/docs/samples?product=cloudvision).