text_annotation.proto 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. // Copyright 2017 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.v1p1beta1;
  16. import "google/cloud/vision/v1p1beta1/geometry.proto";
  17. option cc_enable_arenas = true;
  18. option go_package = "google.golang.org/genproto/googleapis/cloud/vision/v1p1beta1;vision";
  19. option java_multiple_files = true;
  20. option java_outer_classname = "TextAnnotationProto";
  21. option java_package = "com.google.cloud.vision.v1p1beta1";
  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.v1p1beta1.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 in pixels.
  80. int32 width = 2;
  81. // Page height in pixels.
  82. int32 height = 3;
  83. // List of blocks of text, images etc on this page.
  84. repeated Block blocks = 4;
  85. // Confidence of the OCR results on the page. Range [0, 1].
  86. float confidence = 5;
  87. }
  88. // Logical element on the page.
  89. message Block {
  90. // Type of a block (text, image etc) as identified by OCR.
  91. enum BlockType {
  92. // Unknown block type.
  93. UNKNOWN = 0;
  94. // Regular text block.
  95. TEXT = 1;
  96. // Table block.
  97. TABLE = 2;
  98. // Image block.
  99. PICTURE = 3;
  100. // Horizontal/vertical line box.
  101. RULER = 4;
  102. // Barcode block.
  103. BARCODE = 5;
  104. }
  105. // Additional information detected for the block.
  106. TextAnnotation.TextProperty property = 1;
  107. // The bounding box for the block.
  108. // The vertices are in the order of top-left, top-right, bottom-right,
  109. // bottom-left. When a rotation of the bounding box is detected the rotation
  110. // is represented as around the top-left corner as defined when the text is
  111. // read in the 'natural' orientation.
  112. // For example:
  113. // * when the text is horizontal it might look like:
  114. // 0----1
  115. // | |
  116. // 3----2
  117. // * when it's rotated 180 degrees around the top-left corner it becomes:
  118. // 2----3
  119. // | |
  120. // 1----0
  121. // and the vertice order will still be (0, 1, 2, 3).
  122. BoundingPoly bounding_box = 2;
  123. // List of paragraphs in this block (if this blocks is of type text).
  124. repeated Paragraph paragraphs = 3;
  125. // Detected block type (text, image etc) for this block.
  126. BlockType block_type = 4;
  127. // Confidence of the OCR results on the block. Range [0, 1].
  128. float confidence = 5;
  129. }
  130. // Structural unit of text representing a number of words in certain order.
  131. message Paragraph {
  132. // Additional information detected for the paragraph.
  133. TextAnnotation.TextProperty property = 1;
  134. // The bounding box for the paragraph.
  135. // The vertices are in the order of top-left, top-right, bottom-right,
  136. // bottom-left. When a rotation of the bounding box is detected the rotation
  137. // is represented as around the top-left corner as defined when the text is
  138. // read in the 'natural' orientation.
  139. // For example:
  140. // * when the text is horizontal it might look like:
  141. // 0----1
  142. // | |
  143. // 3----2
  144. // * when it's rotated 180 degrees around the top-left corner it becomes:
  145. // 2----3
  146. // | |
  147. // 1----0
  148. // and the vertice order will still be (0, 1, 2, 3).
  149. BoundingPoly bounding_box = 2;
  150. // List of words in this paragraph.
  151. repeated Word words = 3;
  152. // Confidence of the OCR results for the paragraph. Range [0, 1].
  153. float confidence = 4;
  154. }
  155. // A word representation.
  156. message Word {
  157. // Additional information detected for the word.
  158. TextAnnotation.TextProperty property = 1;
  159. // The bounding box for the word.
  160. // The vertices are in the order of top-left, top-right, bottom-right,
  161. // bottom-left. When a rotation of the bounding box is detected the rotation
  162. // is represented as around the top-left corner as defined when the text is
  163. // read in the 'natural' orientation.
  164. // For example:
  165. // * when the text is horizontal it might look like:
  166. // 0----1
  167. // | |
  168. // 3----2
  169. // * when it's rotated 180 degrees around the top-left corner it becomes:
  170. // 2----3
  171. // | |
  172. // 1----0
  173. // and the vertice order will still be (0, 1, 2, 3).
  174. BoundingPoly bounding_box = 2;
  175. // List of symbols in the word.
  176. // The order of the symbols follows the natural reading order.
  177. repeated Symbol symbols = 3;
  178. // Confidence of the OCR results for the word. Range [0, 1].
  179. float confidence = 4;
  180. }
  181. // A single symbol representation.
  182. message Symbol {
  183. // Additional information detected for the symbol.
  184. TextAnnotation.TextProperty property = 1;
  185. // The bounding box for the symbol.
  186. // The vertices are in the order of top-left, top-right, bottom-right,
  187. // bottom-left. When a rotation of the bounding box is detected the rotation
  188. // is represented as around the top-left corner as defined when the text is
  189. // read in the 'natural' orientation.
  190. // For example:
  191. // * when the text is horizontal it might look like:
  192. // 0----1
  193. // | |
  194. // 3----2
  195. // * when it's rotated 180 degrees around the top-left corner it becomes:
  196. // 2----3
  197. // | |
  198. // 1----0
  199. // and the vertice order will still be (0, 1, 2, 3).
  200. BoundingPoly bounding_box = 2;
  201. // The actual UTF-8 representation of the symbol.
  202. string text = 3;
  203. // Confidence of the OCR results for the symbol. Range [0, 1].
  204. float confidence = 4;
  205. }