This repository has been archived by the owner on Feb 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 85
/
image_annotator.py
1203 lines (1005 loc) · 46.5 KB
/
image_annotator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import proto # type: ignore
from google.cloud.vision_v1.types import geometry
from google.cloud.vision_v1.types import product_search
from google.cloud.vision_v1.types import text_annotation
from google.cloud.vision_v1.types import web_detection as gcv_web_detection
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import color_pb2 # type: ignore
from google.type import latlng_pb2 # type: ignore
__protobuf__ = proto.module(
package="google.cloud.vision.v1",
manifest={
"Likelihood",
"Feature",
"ImageSource",
"Image",
"FaceAnnotation",
"LocationInfo",
"Property",
"EntityAnnotation",
"LocalizedObjectAnnotation",
"SafeSearchAnnotation",
"LatLongRect",
"ColorInfo",
"DominantColorsAnnotation",
"ImageProperties",
"CropHint",
"CropHintsAnnotation",
"CropHintsParams",
"WebDetectionParams",
"TextDetectionParams",
"ImageContext",
"AnnotateImageRequest",
"ImageAnnotationContext",
"AnnotateImageResponse",
"BatchAnnotateImagesRequest",
"BatchAnnotateImagesResponse",
"AnnotateFileRequest",
"AnnotateFileResponse",
"BatchAnnotateFilesRequest",
"BatchAnnotateFilesResponse",
"AsyncAnnotateFileRequest",
"AsyncAnnotateFileResponse",
"AsyncBatchAnnotateImagesRequest",
"AsyncBatchAnnotateImagesResponse",
"AsyncBatchAnnotateFilesRequest",
"AsyncBatchAnnotateFilesResponse",
"InputConfig",
"OutputConfig",
"GcsSource",
"GcsDestination",
"OperationMetadata",
},
)
class Likelihood(proto.Enum):
r"""A bucketized representation of likelihood, which is intended
to give clients highly stable results across model upgrades.
"""
UNKNOWN = 0
VERY_UNLIKELY = 1
UNLIKELY = 2
POSSIBLE = 3
LIKELY = 4
VERY_LIKELY = 5
class Feature(proto.Message):
r"""The type of Google Cloud Vision API detection to perform, and the
maximum number of results to return for that type. Multiple
``Feature`` objects can be specified in the ``features`` list.
Attributes:
type_ (google.cloud.vision_v1.types.Feature.Type):
The feature type.
max_results (int):
Maximum number of results of this type. Does not apply to
``TEXT_DETECTION``, ``DOCUMENT_TEXT_DETECTION``, or
``CROP_HINTS``.
model (str):
Model to use for the feature.
Supported values: "builtin/stable" (the default
if unset) and "builtin/latest".
"""
class Type(proto.Enum):
r"""Type of Google Cloud Vision API feature to be extracted."""
TYPE_UNSPECIFIED = 0
FACE_DETECTION = 1
LANDMARK_DETECTION = 2
LOGO_DETECTION = 3
LABEL_DETECTION = 4
TEXT_DETECTION = 5
DOCUMENT_TEXT_DETECTION = 11
SAFE_SEARCH_DETECTION = 6
IMAGE_PROPERTIES = 7
CROP_HINTS = 9
WEB_DETECTION = 10
PRODUCT_SEARCH = 12
OBJECT_LOCALIZATION = 19
type_ = proto.Field(proto.ENUM, number=1, enum=Type,)
max_results = proto.Field(proto.INT32, number=2,)
model = proto.Field(proto.STRING, number=3,)
class ImageSource(proto.Message):
r"""External image source (Google Cloud Storage or web URL image
location).
Attributes:
gcs_image_uri (str):
**Use ``image_uri`` instead.**
The Google Cloud Storage URI of the form
``gs://bucket_name/object_name``. Object versioning is not
supported. See `Google Cloud Storage Request
URIs <https://cloud.google.com/storage/docs/reference-uris>`__
for more info.
image_uri (str):
The URI of the source image. Can be either:
1. A Google Cloud Storage URI of the form
``gs://bucket_name/object_name``. Object versioning is
not supported. See `Google Cloud Storage Request
URIs <https://cloud.google.com/storage/docs/reference-uris>`__
for more info.
2. A publicly-accessible image HTTP/HTTPS URL. When fetching
images from HTTP/HTTPS URLs, Google cannot guarantee that
the request will be completed. Your request may fail if
the specified host denies the request (e.g. due to
request throttling or DOS prevention), or if Google
throttles requests to the site for abuse prevention. You
should not depend on externally-hosted images for
production applications.
When both ``gcs_image_uri`` and ``image_uri`` are specified,
``image_uri`` takes precedence.
"""
gcs_image_uri = proto.Field(proto.STRING, number=1,)
image_uri = proto.Field(proto.STRING, number=2,)
class Image(proto.Message):
r"""Client image to perform Google Cloud Vision API tasks over.
Attributes:
content (bytes):
Image content, represented as a stream of bytes. Note: As
with all ``bytes`` fields, protobuffers use a pure binary
representation, whereas JSON representations use base64.
Currently, this field only works for BatchAnnotateImages
requests. It does not work for AsyncBatchAnnotateImages
requests.
source (google.cloud.vision_v1.types.ImageSource):
Google Cloud Storage image location, or publicly-accessible
image URL. If both ``content`` and ``source`` are provided
for an image, ``content`` takes precedence and is used to
perform the image annotation request.
"""
content = proto.Field(proto.BYTES, number=1,)
source = proto.Field(proto.MESSAGE, number=2, message="ImageSource",)
class FaceAnnotation(proto.Message):
r"""A face annotation object contains the results of face
detection.
Attributes:
bounding_poly (google.cloud.vision_v1.types.BoundingPoly):
The bounding polygon around the face. The coordinates of the
bounding box are in the original image's scale. The bounding
box is computed to "frame" the face in accordance with human
expectations. It is based on the landmarker results. Note
that one or more x and/or y coordinates may not be generated
in the ``BoundingPoly`` (the polygon will be unbounded) if
only a partial face appears in the image to be annotated.
fd_bounding_poly (google.cloud.vision_v1.types.BoundingPoly):
The ``fd_bounding_poly`` bounding polygon is tighter than
the ``boundingPoly``, and encloses only the skin part of the
face. Typically, it is used to eliminate the face from any
image analysis that detects the "amount of skin" visible in
an image. It is not based on the landmarker results, only on
the initial face detection, hence the fd (face detection)
prefix.
landmarks (Sequence[google.cloud.vision_v1.types.FaceAnnotation.Landmark]):
Detected face landmarks.
roll_angle (float):
Roll angle, which indicates the amount of
clockwise/anti-clockwise rotation of the face relative to
the image vertical about the axis perpendicular to the face.
Range [-180,180].
pan_angle (float):
Yaw angle, which indicates the leftward/rightward angle that
the face is pointing relative to the vertical plane
perpendicular to the image. Range [-180,180].
tilt_angle (float):
Pitch angle, which indicates the upwards/downwards angle
that the face is pointing relative to the image's horizontal
plane. Range [-180,180].
detection_confidence (float):
Detection confidence. Range [0, 1].
landmarking_confidence (float):
Face landmarking confidence. Range [0, 1].
joy_likelihood (google.cloud.vision_v1.types.Likelihood):
Joy likelihood.
sorrow_likelihood (google.cloud.vision_v1.types.Likelihood):
Sorrow likelihood.
anger_likelihood (google.cloud.vision_v1.types.Likelihood):
Anger likelihood.
surprise_likelihood (google.cloud.vision_v1.types.Likelihood):
Surprise likelihood.
under_exposed_likelihood (google.cloud.vision_v1.types.Likelihood):
Under-exposed likelihood.
blurred_likelihood (google.cloud.vision_v1.types.Likelihood):
Blurred likelihood.
headwear_likelihood (google.cloud.vision_v1.types.Likelihood):
Headwear likelihood.
"""
class Landmark(proto.Message):
r"""A face-specific landmark (for example, a face feature).
Attributes:
type_ (google.cloud.vision_v1.types.FaceAnnotation.Landmark.Type):
Face landmark type.
position (google.cloud.vision_v1.types.Position):
Face landmark position.
"""
class Type(proto.Enum):
r"""Face landmark (feature) type. Left and right are defined from the
vantage of the viewer of the image without considering mirror
projections typical of photos. So, ``LEFT_EYE``, typically, is the
person's right eye.
"""
UNKNOWN_LANDMARK = 0
LEFT_EYE = 1
RIGHT_EYE = 2
LEFT_OF_LEFT_EYEBROW = 3
RIGHT_OF_LEFT_EYEBROW = 4
LEFT_OF_RIGHT_EYEBROW = 5
RIGHT_OF_RIGHT_EYEBROW = 6
MIDPOINT_BETWEEN_EYES = 7
NOSE_TIP = 8
UPPER_LIP = 9
LOWER_LIP = 10
MOUTH_LEFT = 11
MOUTH_RIGHT = 12
MOUTH_CENTER = 13
NOSE_BOTTOM_RIGHT = 14
NOSE_BOTTOM_LEFT = 15
NOSE_BOTTOM_CENTER = 16
LEFT_EYE_TOP_BOUNDARY = 17
LEFT_EYE_RIGHT_CORNER = 18
LEFT_EYE_BOTTOM_BOUNDARY = 19
LEFT_EYE_LEFT_CORNER = 20
RIGHT_EYE_TOP_BOUNDARY = 21
RIGHT_EYE_RIGHT_CORNER = 22
RIGHT_EYE_BOTTOM_BOUNDARY = 23
RIGHT_EYE_LEFT_CORNER = 24
LEFT_EYEBROW_UPPER_MIDPOINT = 25
RIGHT_EYEBROW_UPPER_MIDPOINT = 26
LEFT_EAR_TRAGION = 27
RIGHT_EAR_TRAGION = 28
LEFT_EYE_PUPIL = 29
RIGHT_EYE_PUPIL = 30
FOREHEAD_GLABELLA = 31
CHIN_GNATHION = 32
CHIN_LEFT_GONION = 33
CHIN_RIGHT_GONION = 34
LEFT_CHEEK_CENTER = 35
RIGHT_CHEEK_CENTER = 36
type_ = proto.Field(proto.ENUM, number=3, enum="FaceAnnotation.Landmark.Type",)
position = proto.Field(proto.MESSAGE, number=4, message=geometry.Position,)
bounding_poly = proto.Field(proto.MESSAGE, number=1, message=geometry.BoundingPoly,)
fd_bounding_poly = proto.Field(
proto.MESSAGE, number=2, message=geometry.BoundingPoly,
)
landmarks = proto.RepeatedField(proto.MESSAGE, number=3, message=Landmark,)
roll_angle = proto.Field(proto.FLOAT, number=4,)
pan_angle = proto.Field(proto.FLOAT, number=5,)
tilt_angle = proto.Field(proto.FLOAT, number=6,)
detection_confidence = proto.Field(proto.FLOAT, number=7,)
landmarking_confidence = proto.Field(proto.FLOAT, number=8,)
joy_likelihood = proto.Field(proto.ENUM, number=9, enum="Likelihood",)
sorrow_likelihood = proto.Field(proto.ENUM, number=10, enum="Likelihood",)
anger_likelihood = proto.Field(proto.ENUM, number=11, enum="Likelihood",)
surprise_likelihood = proto.Field(proto.ENUM, number=12, enum="Likelihood",)
under_exposed_likelihood = proto.Field(proto.ENUM, number=13, enum="Likelihood",)
blurred_likelihood = proto.Field(proto.ENUM, number=14, enum="Likelihood",)
headwear_likelihood = proto.Field(proto.ENUM, number=15, enum="Likelihood",)
class LocationInfo(proto.Message):
r"""Detected entity location information.
Attributes:
lat_lng (google.type.latlng_pb2.LatLng):
lat/long location coordinates.
"""
lat_lng = proto.Field(proto.MESSAGE, number=1, message=latlng_pb2.LatLng,)
class Property(proto.Message):
r"""A ``Property`` consists of a user-supplied name/value pair.
Attributes:
name (str):
Name of the property.
value (str):
Value of the property.
uint64_value (int):
Value of numeric properties.
"""
name = proto.Field(proto.STRING, number=1,)
value = proto.Field(proto.STRING, number=2,)
uint64_value = proto.Field(proto.UINT64, number=3,)
class EntityAnnotation(proto.Message):
r"""Set of detected entity features.
Attributes:
mid (str):
Opaque entity ID. Some IDs may be available in `Google
Knowledge Graph Search
API <https://developers.google.com/knowledge-graph/>`__.
locale (str):
The language code for the locale in which the entity textual
``description`` is expressed.
description (str):
Entity textual description, expressed in its ``locale``
language.
score (float):
Overall score of the result. Range [0, 1].
confidence (float):
**Deprecated. Use ``score`` instead.** The accuracy of the
entity detection in an image. For example, for an image in
which the "Eiffel Tower" entity is detected, this field
represents the confidence that there is a tower in the query
image. Range [0, 1].
topicality (float):
The relevancy of the ICA (Image Content Annotation) label to
the image. For example, the relevancy of "tower" is likely
higher to an image containing the detected "Eiffel Tower"
than to an image containing a detected distant towering
building, even though the confidence that there is a tower
in each image may be the same. Range [0, 1].
bounding_poly (google.cloud.vision_v1.types.BoundingPoly):
Image region to which this entity belongs. Not produced for
``LABEL_DETECTION`` features.
locations (Sequence[google.cloud.vision_v1.types.LocationInfo]):
The location information for the detected entity. Multiple
``LocationInfo`` elements can be present because one
location may indicate the location of the scene in the
image, and another location may indicate the location of the
place where the image was taken. Location information is
usually present for landmarks.
properties (Sequence[google.cloud.vision_v1.types.Property]):
Some entities may have optional user-supplied ``Property``
(name/value) fields, such a score or string that qualifies
the entity.
"""
mid = proto.Field(proto.STRING, number=1,)
locale = proto.Field(proto.STRING, number=2,)
description = proto.Field(proto.STRING, number=3,)
score = proto.Field(proto.FLOAT, number=4,)
confidence = proto.Field(proto.FLOAT, number=5,)
topicality = proto.Field(proto.FLOAT, number=6,)
bounding_poly = proto.Field(proto.MESSAGE, number=7, message=geometry.BoundingPoly,)
locations = proto.RepeatedField(proto.MESSAGE, number=8, message="LocationInfo",)
properties = proto.RepeatedField(proto.MESSAGE, number=9, message="Property",)
class LocalizedObjectAnnotation(proto.Message):
r"""Set of detected objects with bounding boxes.
Attributes:
mid (str):
Object ID that should align with
EntityAnnotation mid.
language_code (str):
The BCP-47 language code, such as "en-US" or "sr-Latn". For
more information, see
http://www.unicode.org/reports/tr35/#Unicode_locale_identifier.
name (str):
Object name, expressed in its ``language_code`` language.
score (float):
Score of the result. Range [0, 1].
bounding_poly (google.cloud.vision_v1.types.BoundingPoly):
Image region to which this object belongs.
This must be populated.
"""
mid = proto.Field(proto.STRING, number=1,)
language_code = proto.Field(proto.STRING, number=2,)
name = proto.Field(proto.STRING, number=3,)
score = proto.Field(proto.FLOAT, number=4,)
bounding_poly = proto.Field(proto.MESSAGE, number=5, message=geometry.BoundingPoly,)
class SafeSearchAnnotation(proto.Message):
r"""Set of features pertaining to the image, computed by computer
vision methods over safe-search verticals (for example, adult,
spoof, medical, violence).
Attributes:
adult (google.cloud.vision_v1.types.Likelihood):
Represents the adult content likelihood for
the image. Adult content may contain elements
such as nudity, pornographic images or cartoons,
or sexual activities.
spoof (google.cloud.vision_v1.types.Likelihood):
Spoof likelihood. The likelihood that an
modification was made to the image's canonical
version to make it appear funny or offensive.
medical (google.cloud.vision_v1.types.Likelihood):
Likelihood that this is a medical image.
violence (google.cloud.vision_v1.types.Likelihood):
Likelihood that this image contains violent
content.
racy (google.cloud.vision_v1.types.Likelihood):
Likelihood that the request image contains
racy content. Racy content may include (but is
not limited to) skimpy or sheer clothing,
strategically covered nudity, lewd or
provocative poses, or close-ups of sensitive
body areas.
adult_confidence (float):
Confidence of adult_score. Range [0, 1]. 0 means not
confident, 1 means very confident.
spoof_confidence (float):
Confidence of spoof_score. Range [0, 1]. 0 means not
confident, 1 means very confident.
medical_confidence (float):
Confidence of medical_score. Range [0, 1]. 0 means not
confident, 1 means very confident.
violence_confidence (float):
Confidence of violence_score. Range [0, 1]. 0 means not
confident, 1 means very confident.
racy_confidence (float):
Confidence of racy_score. Range [0, 1]. 0 means not
confident, 1 means very confident.
nsfw_confidence (float):
Confidence of nsfw_score. Range [0, 1]. 0 means not
confident, 1 means very confident.
"""
adult = proto.Field(proto.ENUM, number=1, enum="Likelihood",)
spoof = proto.Field(proto.ENUM, number=2, enum="Likelihood",)
medical = proto.Field(proto.ENUM, number=3, enum="Likelihood",)
violence = proto.Field(proto.ENUM, number=4, enum="Likelihood",)
racy = proto.Field(proto.ENUM, number=9, enum="Likelihood",)
adult_confidence = proto.Field(proto.FLOAT, number=16,)
spoof_confidence = proto.Field(proto.FLOAT, number=18,)
medical_confidence = proto.Field(proto.FLOAT, number=20,)
violence_confidence = proto.Field(proto.FLOAT, number=22,)
racy_confidence = proto.Field(proto.FLOAT, number=24,)
nsfw_confidence = proto.Field(proto.FLOAT, number=26,)
class LatLongRect(proto.Message):
r"""Rectangle determined by min and max ``LatLng`` pairs.
Attributes:
min_lat_lng (google.type.latlng_pb2.LatLng):
Min lat/long pair.
max_lat_lng (google.type.latlng_pb2.LatLng):
Max lat/long pair.
"""
min_lat_lng = proto.Field(proto.MESSAGE, number=1, message=latlng_pb2.LatLng,)
max_lat_lng = proto.Field(proto.MESSAGE, number=2, message=latlng_pb2.LatLng,)
class ColorInfo(proto.Message):
r"""Color information consists of RGB channels, score, and the
fraction of the image that the color occupies in the image.
Attributes:
color (google.type.color_pb2.Color):
RGB components of the color.
score (float):
Image-specific score for this color. Value in range [0, 1].
pixel_fraction (float):
The fraction of pixels the color occupies in the image.
Value in range [0, 1].
"""
color = proto.Field(proto.MESSAGE, number=1, message=color_pb2.Color,)
score = proto.Field(proto.FLOAT, number=2,)
pixel_fraction = proto.Field(proto.FLOAT, number=3,)
class DominantColorsAnnotation(proto.Message):
r"""Set of dominant colors and their corresponding scores.
Attributes:
colors (Sequence[google.cloud.vision_v1.types.ColorInfo]):
RGB color values with their score and pixel
fraction.
"""
colors = proto.RepeatedField(proto.MESSAGE, number=1, message="ColorInfo",)
class ImageProperties(proto.Message):
r"""Stores image properties, such as dominant colors.
Attributes:
dominant_colors (google.cloud.vision_v1.types.DominantColorsAnnotation):
If present, dominant colors completed
successfully.
"""
dominant_colors = proto.Field(
proto.MESSAGE, number=1, message="DominantColorsAnnotation",
)
class CropHint(proto.Message):
r"""Single crop hint that is used to generate a new crop when
serving an image.
Attributes:
bounding_poly (google.cloud.vision_v1.types.BoundingPoly):
The bounding polygon for the crop region. The
coordinates of the bounding box are in the
original image's scale.
confidence (float):
Confidence of this being a salient region. Range [0, 1].
importance_fraction (float):
Fraction of importance of this salient region
with respect to the original image.
"""
bounding_poly = proto.Field(proto.MESSAGE, number=1, message=geometry.BoundingPoly,)
confidence = proto.Field(proto.FLOAT, number=2,)
importance_fraction = proto.Field(proto.FLOAT, number=3,)
class CropHintsAnnotation(proto.Message):
r"""Set of crop hints that are used to generate new crops when
serving images.
Attributes:
crop_hints (Sequence[google.cloud.vision_v1.types.CropHint]):
Crop hint results.
"""
crop_hints = proto.RepeatedField(proto.MESSAGE, number=1, message="CropHint",)
class CropHintsParams(proto.Message):
r"""Parameters for crop hints annotation request.
Attributes:
aspect_ratios (Sequence[float]):
Aspect ratios in floats, representing the
ratio of the width to the height of the image.
For example, if the desired aspect ratio is 4/3,
the corresponding float value should be 1.33333.
If not specified, the best possible crop is
returned. The number of provided aspect ratios
is limited to a maximum of 16; any aspect ratios
provided after the 16th are ignored.
"""
aspect_ratios = proto.RepeatedField(proto.FLOAT, number=1,)
class WebDetectionParams(proto.Message):
r"""Parameters for web detection request.
Attributes:
include_geo_results (bool):
Whether to include results derived from the
geo information in the image.
"""
include_geo_results = proto.Field(proto.BOOL, number=2,)
class TextDetectionParams(proto.Message):
r"""Parameters for text detections. This is used to control
TEXT_DETECTION and DOCUMENT_TEXT_DETECTION features.
Attributes:
enable_text_detection_confidence_score (bool):
By default, Cloud Vision API only includes confidence score
for DOCUMENT_TEXT_DETECTION result. Set the flag to true to
include confidence score for TEXT_DETECTION as well.
"""
enable_text_detection_confidence_score = proto.Field(proto.BOOL, number=9,)
class ImageContext(proto.Message):
r"""Image context and/or feature-specific parameters.
Attributes:
lat_long_rect (google.cloud.vision_v1.types.LatLongRect):
Not used.
language_hints (Sequence[str]):
List of languages to use for TEXT_DETECTION. In most cases,
an empty value yields the best results since it enables
automatic language detection. For languages based on the
Latin alphabet, setting ``language_hints`` is not needed. In
rare cases, when the language of the text in the image is
known, setting a hint will help get better results (although
it will be a significant hindrance if the hint is wrong).
Text detection returns an error if one or more of the
specified languages is not one of the `supported
languages <https://cloud.google.com/vision/docs/languages>`__.
crop_hints_params (google.cloud.vision_v1.types.CropHintsParams):
Parameters for crop hints annotation request.
product_search_params (google.cloud.vision_v1.types.ProductSearchParams):
Parameters for product search.
web_detection_params (google.cloud.vision_v1.types.WebDetectionParams):
Parameters for web detection.
text_detection_params (google.cloud.vision_v1.types.TextDetectionParams):
Parameters for text detection and document
text detection.
"""
lat_long_rect = proto.Field(proto.MESSAGE, number=1, message="LatLongRect",)
language_hints = proto.RepeatedField(proto.STRING, number=2,)
crop_hints_params = proto.Field(proto.MESSAGE, number=4, message="CropHintsParams",)
product_search_params = proto.Field(
proto.MESSAGE, number=5, message=product_search.ProductSearchParams,
)
web_detection_params = proto.Field(
proto.MESSAGE, number=6, message="WebDetectionParams",
)
text_detection_params = proto.Field(
proto.MESSAGE, number=12, message="TextDetectionParams",
)
class AnnotateImageRequest(proto.Message):
r"""Request for performing Google Cloud Vision API tasks over a
user-provided image, with user-requested features, and with
context information.
Attributes:
image (google.cloud.vision_v1.types.Image):
The image to be processed.
features (Sequence[google.cloud.vision_v1.types.Feature]):
Requested features.
image_context (google.cloud.vision_v1.types.ImageContext):
Additional context that may accompany the
image.
"""
image = proto.Field(proto.MESSAGE, number=1, message="Image",)
features = proto.RepeatedField(proto.MESSAGE, number=2, message="Feature",)
image_context = proto.Field(proto.MESSAGE, number=3, message="ImageContext",)
class ImageAnnotationContext(proto.Message):
r"""If an image was produced from a file (e.g. a PDF), this
message gives information about the source of that image.
Attributes:
uri (str):
The URI of the file used to produce the
image.
page_number (int):
If the file was a PDF or TIFF, this field
gives the page number within the file used to
produce the image.
"""
uri = proto.Field(proto.STRING, number=1,)
page_number = proto.Field(proto.INT32, number=2,)
class AnnotateImageResponse(proto.Message):
r"""Response to an image annotation request.
Attributes:
face_annotations (Sequence[google.cloud.vision_v1.types.FaceAnnotation]):
If present, face detection has completed
successfully.
landmark_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]):
If present, landmark detection has completed
successfully.
logo_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]):
If present, logo detection has completed
successfully.
label_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]):
If present, label detection has completed
successfully.
localized_object_annotations (Sequence[google.cloud.vision_v1.types.LocalizedObjectAnnotation]):
If present, localized object detection has
completed successfully. This will be sorted
descending by confidence score.
text_annotations (Sequence[google.cloud.vision_v1.types.EntityAnnotation]):
If present, text (OCR) detection has
completed successfully.
full_text_annotation (google.cloud.vision_v1.types.TextAnnotation):
If present, text (OCR) detection or document
(OCR) text detection has completed successfully.
This annotation provides the structural
hierarchy for the OCR detected text.
safe_search_annotation (google.cloud.vision_v1.types.SafeSearchAnnotation):
If present, safe-search annotation has
completed successfully.
image_properties_annotation (google.cloud.vision_v1.types.ImageProperties):
If present, image properties were extracted
successfully.
crop_hints_annotation (google.cloud.vision_v1.types.CropHintsAnnotation):
If present, crop hints have completed
successfully.
web_detection (google.cloud.vision_v1.types.WebDetection):
If present, web detection has completed
successfully.
product_search_results (google.cloud.vision_v1.types.ProductSearchResults):
If present, product search has completed
successfully.
error (google.rpc.status_pb2.Status):
If set, represents the error message for the operation. Note
that filled-in image annotations are guaranteed to be
correct, even when ``error`` is set.
context (google.cloud.vision_v1.types.ImageAnnotationContext):
If present, contextual information is needed
to understand where this image comes from.
"""
face_annotations = proto.RepeatedField(
proto.MESSAGE, number=1, message="FaceAnnotation",
)
landmark_annotations = proto.RepeatedField(
proto.MESSAGE, number=2, message="EntityAnnotation",
)
logo_annotations = proto.RepeatedField(
proto.MESSAGE, number=3, message="EntityAnnotation",
)
label_annotations = proto.RepeatedField(
proto.MESSAGE, number=4, message="EntityAnnotation",
)
localized_object_annotations = proto.RepeatedField(
proto.MESSAGE, number=22, message="LocalizedObjectAnnotation",
)
text_annotations = proto.RepeatedField(
proto.MESSAGE, number=5, message="EntityAnnotation",
)
full_text_annotation = proto.Field(
proto.MESSAGE, number=12, message=text_annotation.TextAnnotation,
)
safe_search_annotation = proto.Field(
proto.MESSAGE, number=6, message="SafeSearchAnnotation",
)
image_properties_annotation = proto.Field(
proto.MESSAGE, number=8, message="ImageProperties",
)
crop_hints_annotation = proto.Field(
proto.MESSAGE, number=11, message="CropHintsAnnotation",
)
web_detection = proto.Field(
proto.MESSAGE, number=13, message=gcv_web_detection.WebDetection,
)
product_search_results = proto.Field(
proto.MESSAGE, number=14, message=product_search.ProductSearchResults,
)
error = proto.Field(proto.MESSAGE, number=9, message=status_pb2.Status,)
context = proto.Field(proto.MESSAGE, number=21, message="ImageAnnotationContext",)
class BatchAnnotateImagesRequest(proto.Message):
r"""Multiple image annotation requests are batched into a single
service call.
Attributes:
requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]):
Required. Individual image annotation
requests for this batch.
parent (str):
Optional. Target project and location to make a call.
Format: ``projects/{project-id}/locations/{location-id}``.
If no parent is specified, a region will be chosen
automatically.
Supported location-ids: ``us``: USA country only, ``asia``:
East asia areas, like Japan, Taiwan, ``eu``: The European
Union.
Example: ``projects/project-A/locations/eu``.
"""
requests = proto.RepeatedField(
proto.MESSAGE, number=1, message="AnnotateImageRequest",
)
parent = proto.Field(proto.STRING, number=4,)
class BatchAnnotateImagesResponse(proto.Message):
r"""Response to a batch image annotation request.
Attributes:
responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]):
Individual responses to image annotation
requests within the batch.
"""
responses = proto.RepeatedField(
proto.MESSAGE, number=1, message="AnnotateImageResponse",
)
class AnnotateFileRequest(proto.Message):
r"""A request to annotate one single file, e.g. a PDF, TIFF or
GIF file.
Attributes:
input_config (google.cloud.vision_v1.types.InputConfig):
Required. Information about the input file.
features (Sequence[google.cloud.vision_v1.types.Feature]):
Required. Requested features.
image_context (google.cloud.vision_v1.types.ImageContext):
Additional context that may accompany the
image(s) in the file.
pages (Sequence[int]):
Pages of the file to perform image
annotation.
Pages starts from 1, we assume the first page of
the file is page 1. At most 5 pages are
supported per request. Pages can be negative.
Page 1 means the first page.
Page 2 means the second page.
Page -1 means the last page.
Page -2 means the second to the last page.
If the file is GIF instead of PDF or TIFF, page
refers to GIF frames.
If this field is empty, by default the service
performs image annotation for the first 5 pages
of the file.
"""
input_config = proto.Field(proto.MESSAGE, number=1, message="InputConfig",)
features = proto.RepeatedField(proto.MESSAGE, number=2, message="Feature",)
image_context = proto.Field(proto.MESSAGE, number=3, message="ImageContext",)
pages = proto.RepeatedField(proto.INT32, number=4,)
class AnnotateFileResponse(proto.Message):
r"""Response to a single file annotation request. A file may
contain one or more images, which individually have their own
responses.
Attributes:
input_config (google.cloud.vision_v1.types.InputConfig):
Information about the file for which this
response is generated.
responses (Sequence[google.cloud.vision_v1.types.AnnotateImageResponse]):
Individual responses to images found within the file. This
field will be empty if the ``error`` field is set.
total_pages (int):
This field gives the total number of pages in
the file.
error (google.rpc.status_pb2.Status):
If set, represents the error message for the failed request.
The ``responses`` field will not be set in this case.
"""
input_config = proto.Field(proto.MESSAGE, number=1, message="InputConfig",)
responses = proto.RepeatedField(
proto.MESSAGE, number=2, message="AnnotateImageResponse",
)
total_pages = proto.Field(proto.INT32, number=3,)
error = proto.Field(proto.MESSAGE, number=4, message=status_pb2.Status,)
class BatchAnnotateFilesRequest(proto.Message):
r"""A list of requests to annotate files using the
BatchAnnotateFiles API.
Attributes:
requests (Sequence[google.cloud.vision_v1.types.AnnotateFileRequest]):
Required. The list of file annotation
requests. Right now we support only one
AnnotateFileRequest in
BatchAnnotateFilesRequest.
parent (str):
Optional. Target project and location to make a call.
Format: ``projects/{project-id}/locations/{location-id}``.
If no parent is specified, a region will be chosen
automatically.
Supported location-ids: ``us``: USA country only, ``asia``:
East asia areas, like Japan, Taiwan, ``eu``: The European
Union.
Example: ``projects/project-A/locations/eu``.
"""
requests = proto.RepeatedField(
proto.MESSAGE, number=1, message="AnnotateFileRequest",
)
parent = proto.Field(proto.STRING, number=3,)
class BatchAnnotateFilesResponse(proto.Message):
r"""A list of file annotation responses.
Attributes:
responses (Sequence[google.cloud.vision_v1.types.AnnotateFileResponse]):
The list of file annotation responses, each
response corresponding to each
AnnotateFileRequest in
BatchAnnotateFilesRequest.
"""
responses = proto.RepeatedField(
proto.MESSAGE, number=1, message="AnnotateFileResponse",
)
class AsyncAnnotateFileRequest(proto.Message):
r"""An offline file annotation request.
Attributes:
input_config (google.cloud.vision_v1.types.InputConfig):
Required. Information about the input file.
features (Sequence[google.cloud.vision_v1.types.Feature]):
Required. Requested features.
image_context (google.cloud.vision_v1.types.ImageContext):
Additional context that may accompany the
image(s) in the file.
output_config (google.cloud.vision_v1.types.OutputConfig):
Required. The desired output location and
metadata (e.g. format).
"""
input_config = proto.Field(proto.MESSAGE, number=1, message="InputConfig",)
features = proto.RepeatedField(proto.MESSAGE, number=2, message="Feature",)
image_context = proto.Field(proto.MESSAGE, number=3, message="ImageContext",)
output_config = proto.Field(proto.MESSAGE, number=4, message="OutputConfig",)
class AsyncAnnotateFileResponse(proto.Message):
r"""The response for a single offline file annotation request.
Attributes:
output_config (google.cloud.vision_v1.types.OutputConfig):
The output location and metadata from
AsyncAnnotateFileRequest.
"""
output_config = proto.Field(proto.MESSAGE, number=1, message="OutputConfig",)
class AsyncBatchAnnotateImagesRequest(proto.Message):
r"""Request for async image annotation for a list of images.
Attributes:
requests (Sequence[google.cloud.vision_v1.types.AnnotateImageRequest]):
Required. Individual image annotation
requests for this batch.
output_config (google.cloud.vision_v1.types.OutputConfig):
Required. The desired output location and
metadata (e.g. format).
parent (str):
Optional. Target project and location to make a call.
Format: ``projects/{project-id}/locations/{location-id}``.