text_annotation.proto 7.7 KB

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