コード例 #1
0
    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]
コード例 #2
0
    def annotate(self, images):
        """Annotate images through GAX.

        :type images: list
        :param images: List containing pairs of
                       :class:`~google.cloud.vision.image.Image` and
                       :class:`~google.cloud.vision.feature.Feature`.
                       e.g. [(image, [feature_one, feature_two]),]

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.annotations.Annotations`.
        """
        requests = []
        for image, features in images:
            gapic_features = [
                _to_gapic_feature(feature) for feature in features
            ]
            gapic_image = _to_gapic_image(image)
            request = image_annotator_pb2.AnnotateImageRequest(
                image=gapic_image, features=gapic_features)
            requests.append(request)

        annotator_client = self._annotator_client
        responses = annotator_client.batch_annotate_images(requests).responses
        return [Annotations.from_pb(response) for response in responses]
コード例 #3
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.')
コード例 #4
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.')
コード例 #5
0
ファイル: image.py プロジェクト: Fkawala/gcloud-python
    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)
コード例 #6
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)
コード例 #7
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]
コード例 #8
0
ファイル: _gax.py プロジェクト: cadef/google-cloud-python
    def annotate(self, image, features):
        """Annotate images through GAX.

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

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`.

        :rtype: list
        :returns: List of
                  :class:`~google.cloud.vision.annotations.Annotations`.
        """
        gapic_features = [_to_gapic_feature(feature) for feature in features]
        gapic_image = _to_gapic_image(image)
        request = image_annotator_pb2.AnnotateImageRequest(
            image=gapic_image, features=gapic_features)
        requests = [request]
        annotator_client = self._annotator_client
        responses = annotator_client.batch_annotate_images(requests).responses
        return [Annotations.from_pb(response) for response in responses]
コード例 #9
0
ファイル: _http.py プロジェクト: cadef/google-cloud-python
    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]
コード例 #10
0
    def annotate(self, image, features):
        """Annotate images through GAX.

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

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`.

        :rtype: :class:`~google.cloud.vision.annotations.Annotations`
        :returns: Instance of ``Annotations`` with results or ``None``.
        """
        gapic_features = [_to_gapic_feature(feature) for feature in features]
        gapic_image = _to_gapic_image(image)
        request = image_annotator_pb2.AnnotateImageRequest(
            image=gapic_image, features=gapic_features)
        requests = [request]
        annotator_client = self._annotator_client
        images = annotator_client.batch_annotate_images(requests)
        if len(images.responses) == 1:
            return Annotations.from_pb(images.responses[0])
        elif len(images.responses) > 1:
            raise NotImplementedError(
                'Multiple image processing is not yet supported.')
コード例 #11
0
    def annotate(self, image, features):
        """Annotate images through GAX.

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

        :type features: list
        :param features: List of :class:`~google.cloud.vision.feature.Feature`.

        :rtype: :class:`~google.cloud.vision.annotations.Annotations`
        :returns: Instance of ``Annotations`` with results or ``None``.
        """
        gapic_features = [_to_gapic_feature(feature) for feature in features]
        gapic_image = _to_gapic_image(image)
        request = image_annotator_pb2.AnnotateImageRequest(
            image=gapic_image, features=gapic_features)
        requests = [request]
        annotator_client = self._annotator_client
        images = annotator_client.batch_annotate_images(requests)
        if len(images.responses) == 1:
            return Annotations.from_pb(images.responses[0])
        elif len(images.responses) > 1:
            raise NotImplementedError(
                'Multiple image processing is not yet supported.')