예제 #1
0
def _make_pb_entity():
    from google.cloud.grpc.vision.v1 import geometry_pb2
    from google.cloud.grpc.vision.v1 import image_annotator_pb2
    from google.type import latlng_pb2

    description = 'testing 1 2 3'
    locale = 'US'
    mid = 'm/w/45342234'
    score = 0.235434231

    entity_annotation = image_annotator_pb2.EntityAnnotation(
        mid=mid,
        locale=locale,
        description=description,
        score=score,
        bounding_poly=geometry_pb2.BoundingPoly(
            vertices=[
                geometry_pb2.Vertex(x=1, y=2),
            ],
        ),
        locations=[
            image_annotator_pb2.LocationInfo(
                lat_lng=latlng_pb2.LatLng(latitude=1.0, longitude=2.0),
            ),
        ],
    )
    return entity_annotation
예제 #2
0
    def test_logo_pb_annotation(self):
        from google.cloud.grpc.vision.v1 import image_annotator_pb2

        description = 'testing 1 2 3'
        locale = 'US'
        mid = 'm/w/45342234'
        score = 0.875
        entity_annotation = image_annotator_pb2.EntityAnnotation()
        entity_annotation.mid = mid
        entity_annotation.locale = locale
        entity_annotation.description = description
        entity_annotation.score = score
        entity_annotation.bounding_poly.vertices.add()
        entity_annotation.bounding_poly.vertices[0].x = 1
        entity_annotation.bounding_poly.vertices[0].y = 2
        entity_annotation.locations.add()
        entity_annotation.locations[0].lat_lng.latitude = 1.0
        entity_annotation.locations[0].lat_lng.longitude = 2.0

        entity_class = self._get_target_class()
        entity = entity_class.from_pb(entity_annotation)

        self.assertEqual(entity.description, description)
        self.assertEqual(entity.mid, mid)
        self.assertEqual(entity.locale, locale)
        self.assertEqual(entity.score, score)
        self.assertEqual(entity.bounds.vertices[0].x_coordinate, 1)
        self.assertEqual(entity.bounds.vertices[0].y_coordinate, 2)
        self.assertEqual(entity.locations[0].latitude, 1.0)
        self.assertEqual(entity.locations[0].longitude, 2.0)