text_annotation.proto 7.8 KB

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