text_annotation.proto 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. // Copyright 2020 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. syntax = "proto3";
  15. package google.cloud.vision.v1;
  16. import "google/cloud/vision/v1/geometry.proto";
  17. import "google/api/annotations.proto";
  18. option cc_enable_arenas = true;
  19. option go_package = "google.golang.org/genproto/googleapis/cloud/vision/v1;vision";
  20. option java_multiple_files = true;
  21. option java_outer_classname = "TextAnnotationProto";
  22. option java_package = "com.google.cloud.vision.v1";
  23. option objc_class_prefix = "GCVN";
  24. // TextAnnotation contains a structured representation of OCR extracted text.
  25. // The hierarchy of an OCR extracted text structure is like this:
  26. // TextAnnotation -> Page -> Block -> Paragraph -> Word -> Symbol
  27. // Each structural component, starting from Page, may further have their own
  28. // properties. Properties describe detected languages, breaks etc.. Please refer
  29. // to the [TextAnnotation.TextProperty][google.cloud.vision.v1.TextAnnotation.TextProperty] message definition below for more
  30. // detail.
  31. message TextAnnotation {
  32. // Detected language for a structural component.
  33. message DetectedLanguage {
  34. // The BCP-47 language code, such as "en-US" or "sr-Latn". For more
  35. // information, see
  36. // http://www.unicode.org/reports/tr35/#Unicode_locale_identifier.
  37. string language_code = 1;
  38. // Confidence of detected language. Range [0, 1].
  39. float confidence = 2;
  40. }
  41. // Detected start or end of a structural component.
  42. message DetectedBreak {
  43. // Enum to denote the type of break found. New line, space etc.
  44. enum BreakType {
  45. // Unknown break label type.
  46. UNKNOWN = 0;
  47. // Regular space.
  48. SPACE = 1;
  49. // Sure space (very wide).
  50. SURE_SPACE = 2;
  51. // Line-wrapping break.
  52. EOL_SURE_SPACE = 3;
  53. // End-line hyphen that is not present in text; does not co-occur with
  54. // `SPACE`, `LEADER_SPACE`, or `LINE_BREAK`.
  55. HYPHEN = 4;
  56. // Line break that ends a paragraph.
  57. LINE_BREAK = 5;
  58. }
  59. // Detected break type.
  60. BreakType type = 1;
  61. // True if break prepends the element.
  62. bool is_prefix = 2;
  63. }
  64. // Additional information detected on the structural component.
  65. message TextProperty {
  66. // A list of detected languages together with confidence.
  67. repeated DetectedLanguage detected_languages = 1;
  68. // Detected start or end of a text segment.
  69. DetectedBreak detected_break = 2;
  70. }
  71. // List of pages detected by OCR.
  72. repeated Page pages = 1;
  73. // UTF-8 text detected on the pages.
  74. string text = 2;
  75. }
  76. // Detected page from OCR.
  77. message Page {
  78. // Additional information detected on the page.
  79. TextAnnotation.TextProperty property = 1;
  80. // Page width. For PDFs the unit is points. For images (including
  81. // TIFFs) the unit is pixels.
  82. int32 width = 2;
  83. // Page height. For PDFs the unit is points. For images (including
  84. // TIFFs) the unit is pixels.
  85. int32 height = 3;
  86. // List of blocks of text, images etc on this page.
  87. repeated Block blocks = 4;
  88. // Confidence of the OCR results on the page. Range [0, 1].
  89. float confidence = 5;
  90. }
  91. // Logical element on the page.
  92. message Block {
  93. // Type of a block (text, image etc) as identified by OCR.
  94. enum BlockType {
  95. // Unknown block type.
  96. UNKNOWN = 0;
  97. // Regular text block.
  98. TEXT = 1;
  99. // Table block.
  100. TABLE = 2;
  101. // Image block.
  102. PICTURE = 3;
  103. // Horizontal/vertical line box.
  104. RULER = 4;
  105. // Barcode block.
  106. BARCODE = 5;
  107. }
  108. // Additional information detected for the block.
  109. TextAnnotation.TextProperty property = 1;
  110. // The bounding box for the block.
  111. // The vertices are in the order of top-left, top-right, bottom-right,
  112. // bottom-left. When a rotation of the bounding box is detected the rotation
  113. // is represented as around the top-left corner as defined when the text is
  114. // read in the 'natural' orientation.
  115. // For example:
  116. //
  117. // * when the text is horizontal it might look like:
  118. //
  119. // 0----1
  120. // | |
  121. // 3----2
  122. //
  123. // * when it's rotated 180 degrees around the top-left corner it becomes:
  124. //
  125. // 2----3
  126. // | |
  127. // 1----0
  128. //
  129. // and the vertex order will still be (0, 1, 2, 3).
  130. BoundingPoly bounding_box = 2;
  131. // List of paragraphs in this block (if this blocks is of type text).
  132. repeated Paragraph paragraphs = 3;
  133. // Detected block type (text, image etc) for this block.
  134. BlockType block_type = 4;
  135. // Confidence of the OCR results on the block. Range [0, 1].
  136. float confidence = 5;
  137. }
  138. // Structural unit of text representing a number of words in certain order.
  139. message Paragraph {
  140. // Additional information detected for the paragraph.
  141. TextAnnotation.TextProperty property = 1;
  142. // The bounding box for the paragraph.
  143. // The vertices are in the order of top-left, top-right, bottom-right,
  144. // bottom-left. When a rotation of the bounding box is detected the rotation
  145. // is represented as around the top-left corner as defined when the text is
  146. // read in the 'natural' orientation.
  147. // For example:
  148. // * when the text is horizontal it might look like:
  149. // 0----1
  150. // | |
  151. // 3----2
  152. // * when it's rotated 180 degrees around the top-left corner it becomes:
  153. // 2----3
  154. // | |
  155. // 1----0
  156. // and the vertex order will still be (0, 1, 2, 3).
  157. BoundingPoly bounding_box = 2;
  158. // List of all words in this paragraph.
  159. repeated Word words = 3;
  160. // Confidence of the OCR results for the paragraph. Range [0, 1].
  161. float confidence = 4;
  162. }
  163. // A word representation.
  164. message Word {
  165. // Additional information detected for the word.
  166. TextAnnotation.TextProperty property = 1;
  167. // The bounding box for the word.
  168. // The vertices are in the order of top-left, top-right, bottom-right,
  169. // bottom-left. When a rotation of the bounding box is detected the rotation
  170. // is represented as around the top-left corner as defined when the text is
  171. // read in the 'natural' orientation.
  172. // For example:
  173. // * when the text is horizontal it might look like:
  174. // 0----1
  175. // | |
  176. // 3----2
  177. // * when it's rotated 180 degrees around the top-left corner it becomes:
  178. // 2----3
  179. // | |
  180. // 1----0
  181. // and the vertex order will still be (0, 1, 2, 3).
  182. BoundingPoly bounding_box = 2;
  183. // List of symbols in the word.
  184. // The order of the symbols follows the natural reading order.
  185. repeated Symbol symbols = 3;
  186. // Confidence of the OCR results for the word. Range [0, 1].
  187. float confidence = 4;
  188. }
  189. // A single symbol representation.
  190. message Symbol {
  191. // Additional information detected for the symbol.
  192. TextAnnotation.TextProperty property = 1;
  193. // The bounding box for the symbol.
  194. // The vertices are in the order of top-left, top-right, bottom-right,
  195. // bottom-left. When a rotation of the bounding box is detected the rotation
  196. // is represented as around the top-left corner as defined when the text is
  197. // read in the 'natural' orientation.
  198. // For example:
  199. // * when the text is horizontal it might look like:
  200. // 0----1
  201. // | |
  202. // 3----2
  203. // * when it's rotated 180 degrees around the top-left corner it becomes:
  204. // 2----3
  205. // | |
  206. // 1----0
  207. // and the vertex order will still be (0, 1, 2, 3).
  208. BoundingPoly bounding_box = 2;
  209. // The actual UTF-8 representation of the symbol.
  210. string text = 3;
  211. // Confidence of the OCR results for the symbol. Range [0, 1].
  212. float confidence = 4;
  213. }