def from_pb(cls, response):
        """Factory: construct ``CropHint`` from Vision gRPC response.

        :type response: :class:`google.cloud.vision_v1.proto.\
                        image_annotator_pb2.CropHint`
        :param response: gRPC response from Vision API with entity data.

        :rtype: :class:`~google.cloud.vision.crop_hint.CropHint`
        :returns: Instance of ``CropHint``.
        """
        bounds = Bounds.from_pb(response.bounding_poly)
        return cls(bounds, response.confidence, response.importance_fraction)
    def from_api_repr(cls, response):
        """Factory: construct ``CropHint`` from Vision API response.

        :type response: dict
        :param response: Dictionary response from Vision API with entity data.

        :rtype: :class:`~google.cloud.vision.crop_hint.CropHint`
        :returns: Instance of ``CropHint``.
        """
        bounds = Bounds.from_api_repr(response.get('boundingPoly'))
        confidence = response.get('confidence', 0.0)
        importance_fraction = response.get('importanceFraction', 0.0)
        return cls(bounds, confidence, importance_fraction)
    def from_pb(cls, response):
        """Factory: construct entity from Vision gRPC response.

        :type response: :class:`~google.cloud.vision_v1.proto.\
                        image_annotator_pb2.AnnotateImageResponse`
        :param response: gRPC response from Vision API with entity data.

        :rtype: :class:`~google.cloud.vision.entity.EntityAnnotation`
        :returns: Instance of ``EntityAnnotation``.
        """
        bounds = Bounds.from_pb(response.bounding_poly)
        description = response.description
        locale = response.locale
        locations = [LocationInformation.from_pb(location)
                     for location in response.locations]
        mid = response.mid
        score = response.score
        return cls(bounds, description, locale, locations, mid, score)
    def from_api_repr(cls, response):
        """Factory: construct entity from Vision API response.

        :type response: dict
        :param response: Dictionary response from Vision API with entity data.

        :rtype: :class:`~google.cloud.vision.entity.EntityAnnotation`
        :returns: Instance of ``EntityAnnotation``.
        """
        bounds = Bounds.from_api_repr(response.get('boundingPoly'))
        description = response['description']
        locale = response.get('locale', None)
        locations = [LocationInformation.from_api_repr(location)
                     for location in response.get('locations', ())]
        mid = response.get('mid', None)
        score = response.get('score', None)

        return cls(bounds, description, locale, locations, mid, score)
示例#5
0
    def from_api_repr(cls, response):
        """Factory: construct entity from Vision API response.

        :type response: dict
        :param response: Dictionary response from Vision API with entity data.

        :rtype: :class:`~google.cloud.vision.entity.EntityAnnotation`
        :returns: Instance of ``EntityAnnotation``.
        """
        bounds = Bounds.from_api_repr(response.get('boundingPoly'))
        description = response['description']
        locale = response.get('locale', None)
        locations = [LocationInformation.from_api_repr(location)
                     for location in response.get('locations', [])]
        mid = response.get('mid', None)
        score = response.get('score', None)

        return cls(bounds, description, locale, locations, mid, score)
示例#6
0
    def from_pb(cls, response):
        """Factory: construct entity from Vision gRPC response.

        :type response: :class:`~google.cloud.grpc.vision.v1.\
                        image_annotator_pb2.AnnotateImageResponse`
        :param response: gRPC response from Vision API with entity data.

        :rtype: :class:`~google.cloud.vision.entity.EntityAnnotation`
        :returns: Instance of ``EntityAnnotation``.
        """
        bounds = Bounds.from_pb(response.bounding_poly)
        description = response.description
        locale = response.locale
        locations = [LocationInformation.from_pb(location)
                     for location in response.locations]
        mid = response.mid
        score = response.score
        return cls(bounds, description, locale, locations, mid, score)