示例#1
0
    def from_pb(cls, face):
        """Factory: construct image properties from image.

        :type face: :class:`~google.cloud.vision_v1.proto.image_annotator_pb2.\
                    FaceAnnotation`
        :param face: Protobuf instace of `Face`.

        :rtype: :class:`~google.cloud.vision.face.FaceImageProperties`
        :returns: Instance populated with image property data.
        """
        blurred = _get_pb_likelihood(face.blurred_likelihood)
        underexposed = _get_pb_likelihood(face.under_exposed_likelihood)

        return cls(blurred, underexposed)
示例#2
0
    def from_pb(cls, emotions):
        """Factory: construct ``Emotions`` from Vision API response.

        :type emotions: :class:`~google.cloud.vision_v1.proto.\
                        image_annotator_pb2.FaceAnnotation`
        :param emotions: Response dictionary representing a face with emotions.

        :rtype: :class:`~google.cloud.vision.face.Emotions`
        :returns: Populated instance of ``Emotions``.
        """
        joy_likelihood = _get_pb_likelihood(emotions.joy_likelihood)
        sorrow_likelihood = _get_pb_likelihood(emotions.sorrow_likelihood)
        surprise_likelihood = _get_pb_likelihood(emotions.surprise_likelihood)
        anger_likelihood = _get_pb_likelihood(emotions.anger_likelihood)

        return cls(joy_likelihood, sorrow_likelihood, surprise_likelihood,
                   anger_likelihood)
示例#3
0
    def from_pb(cls, face):
        """Factory: construct an instance of a Face from an protobuf response

        :type face: :class:`~google.cloud.vision_v1.proto.\
                       image_annotator_pb2.AnnotateImageResponse`
        :param face: ``AnnotateImageResponse`` from gRPC call.

        :rtype: :class:`~google.cloud.vision.face.Face`
        :returns: A instance of `Face` with data parsed from ``response``.
        """
        face_data = {
            'angles': Angles.from_pb(face),
            'bounds': Bounds.from_pb(face.bounding_poly),
            'detection_confidence': face.detection_confidence,
            'emotions': Emotions.from_pb(face),
            'fd_bounds': FDBounds.from_pb(face.fd_bounding_poly),
            'headwear_likelihood': _get_pb_likelihood(
                face.headwear_likelihood),
            'image_properties': FaceImageProperties.from_pb(face),
            'landmarks': Landmarks.from_pb(face.landmarks),
            'landmarking_confidence': face.landmarking_confidence,
        }
        return cls(**face_data)