text_annotation.proto 7.9 KB

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