def annotate(self, images=None, requests_pb=None):
        """Annotate an image to discover it's attributes.

        :type images: list of :class:`~google.cloud.vision.image.Image`
        :param images: A list of ``Image``.

        :rtype: list
        :returns: List of :class:`~googe.cloud.vision.annotations.Annotations`.

        :type requests_pb: list
        :param requests_pb: List of :class:`google.cloud.proto.vision.v1.\
                            image_annotator_b2.AnnotateImageRequest`.

        :rtype: list
        :returns: List of :class:`~googe.cloud.vision.annotations.Annotations`.
        """
        if any([images, requests_pb]) is False:
            return []

        requests = []
        if requests_pb is None:
            for image, features in images:
                requests.append(_make_request(image, features))
        else:
            requests = [json.loads(json_format.MessageToJson(request))
                        for request in requests_pb]

        data = {'requests': requests}

        api_response = self._connection.api_request(
            method='POST', path='/images:annotate', data=data)
        responses = api_response.get('responses')
        return [Annotations.from_api_repr(response) for response in responses]
Beispiel #2
0
    def annotate(self, image, features):
        """Annotate an image to discover it's attributes.

        :type image: :class:`~google.cloud.vision.image.Image`
        :param image: A instance of ``Image``.

        :type features:  list of :class:`~google.cloud.vision.feature.Feature`
        :param features: The type of detection that the Vision API should
                         use to determine image attributes. Pricing is
                         based on the number of Feature Types.

                         See: https://cloud.google.com/vision/docs/pricing
        :rtype: dict
        :returns: List of annotations.
        """
        request = _make_request(image, features)

        data = {'requests': [request]}
        api_response = self._connection.api_request(
            method='POST', path='/images:annotate', data=data)
        images = api_response.get('responses')
        if len(images) == 1:
            return Annotations.from_api_repr(images[0])
        elif len(images) > 1:
            raise NotImplementedError(
                'Multiple image processing is not yet supported.')
    def annotate(self, image, features):
        """Annotate an image to discover it's attributes.

        :type image: :class:`~google.cloud.vision.image.Image`
        :param image: A instance of ``Image``.

        :type features:  list of :class:`~google.cloud.vision.feature.Feature`
        :param features: The type of detection that the Vision API should
                         use to determine image attributes. Pricing is
                         based on the number of Feature Types.

                         See: https://cloud.google.com/vision/docs/pricing
        :rtype: dict
        :returns: List of annotations.
        """
        request = _make_request(image, features)

        data = {'requests': [request]}
        api_response = self._connection.api_request(method='POST',
                                                    path='/images:annotate',
                                                    data=data)
        images = api_response.get('responses')
        if len(images) == 1:
            return Annotations.from_api_repr(images[0])
        elif len(images) > 1:
            raise NotImplementedError(
                'Multiple image processing is not yet supported.')
Beispiel #4
0
    def _detect_annotation(self, features):
        """Generic method for detecting annotations.

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`
                         indicating the type of annotations to perform.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.entity.EntityAnnotation`,
                  :class:`~google.cloud.vision.face.Face`,
                  :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`,
                  :class:`~google.cloud.vision.sage.SafeSearchAnnotation`,
        """
        results = self.client.annotate(self, features)
        return Annotations.from_api_repr(results)
Beispiel #5
0
    def _detect_annotation(self, features):
        """Generic method for detecting annotations.

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`
                         indicating the type of annotations to perform.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.entity.EntityAnnotation`,
                  :class:`~google.cloud.vision.face.Face`,
                  :class:`~google.cloud.vision.color.ImagePropertiesAnnotation`,
                  :class:`~google.cloud.vision.sage.SafeSearchAnnotation`,
        """
        results = self.client._vision_api.annotate(self, features)
        return Annotations.from_api_repr(results)
Beispiel #6
0
    def annotate(self, images):
        """Annotate an image to discover it's attributes.

        :type images: list of :class:`~google.cloud.vision.image.Image`
        :param images: A list of ``Image``.

        :rtype: list
        :returns: List of :class:`~googe.cloud.vision.annotations.Annotations`.
        """
        requests = []
        for image, features in images:
            requests.append(_make_request(image, features))
        data = {'requests': requests}
        api_response = self._connection.api_request(
            method='POST', path='/images:annotate', data=data)
        responses = api_response.get('responses')
        return [Annotations.from_api_repr(response) for response in responses]
Beispiel #7
0
    def annotate(self, image, features):
        """Annotate an image to discover it's attributes.

        :type image: :class:`~google.cloud.vision.image.Image`
        :param image: A instance of ``Image``.

        :type features:  list of :class:`~google.cloud.vision.feature.Feature`
        :param features: The type of detection that the Vision API should
                         use to determine image attributes. Pricing is
                         based on the number of Feature Types.

                         See: https://cloud.google.com/vision/docs/pricing
        :rtype: list
        :returns: List of :class:`~googe.cloud.vision.annotations.Annotations`.
        """
        request = _make_request(image, features)

        data = {'requests': [request]}
        api_response = self._connection.api_request(method='POST',
                                                    path='/images:annotate',
                                                    data=data)
        responses = api_response.get('responses')
        return [Annotations.from_api_repr(response) for response in responses]