Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/tesseract/src/ccstruct/ocrblock.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 /********************************************************************** | |
| 2 * File: ocrblock.h (Formerly block.h) | |
| 3 * Description: Page block class definition. | |
| 4 * Author: Ray Smith | |
| 5 * | |
| 6 * (C) Copyright 1991, Hewlett-Packard Ltd. | |
| 7 ** Licensed under the Apache License, Version 2.0 (the "License"); | |
| 8 ** you may not use this file except in compliance with the License. | |
| 9 ** You may obtain a copy of the License at | |
| 10 ** http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 ** Unless required by applicable law or agreed to in writing, software | |
| 12 ** distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 ** See the License for the specific language governing permissions and | |
| 15 ** limitations under the License. | |
| 16 * | |
| 17 **********************************************************************/ | |
| 18 | |
| 19 #ifndef OCRBLOCK_H | |
| 20 #define OCRBLOCK_H | |
| 21 | |
| 22 #include "ocrpara.h" | |
| 23 #include "ocrrow.h" | |
| 24 #include "pdblock.h" | |
| 25 | |
| 26 namespace tesseract { | |
| 27 | |
| 28 class BLOCK; // forward decl | |
| 29 | |
| 30 ELISTIZEH(BLOCK) | |
| 31 | |
| 32 class TESS_API BLOCK : public ELIST_LINK | |
| 33 // page block | |
| 34 { | |
| 35 friend class BLOCK_RECT_IT; // block iterator | |
| 36 public: | |
| 37 BLOCK() : re_rotation_(1.0f, 0.0f), classify_rotation_(1.0f, 0.0f), skew_(1.0f, 0.0f) {} | |
| 38 BLOCK(const char *name, ///< filename | |
| 39 bool prop, ///< proportional | |
| 40 int16_t kern, ///< kerning | |
| 41 int16_t space, ///< spacing | |
| 42 TDimension xmin, ///< bottom left | |
| 43 TDimension ymin, | |
| 44 TDimension xmax, ///< top right | |
| 45 TDimension ymax); | |
| 46 | |
| 47 ~BLOCK() = default; | |
| 48 | |
| 49 /** | |
| 50 * set space size etc. | |
| 51 * @param prop proportional | |
| 52 * @param kern inter char size | |
| 53 * @param space inter word size | |
| 54 * @param ch_pitch pitch if fixed | |
| 55 */ | |
| 56 void set_stats(bool prop, int16_t kern, int16_t space, int16_t ch_pitch) { | |
| 57 proportional = prop; | |
| 58 kerning = static_cast<int8_t>(kern); | |
| 59 spacing = space; | |
| 60 pitch = ch_pitch; | |
| 61 } | |
| 62 /// set char size | |
| 63 void set_xheight(int32_t height) { | |
| 64 xheight = height; | |
| 65 } | |
| 66 /// set font class | |
| 67 void set_font_class(int16_t font) { | |
| 68 font_class = font; | |
| 69 } | |
| 70 /// return proportional | |
| 71 bool prop() const { | |
| 72 return proportional; | |
| 73 } | |
| 74 bool right_to_left() const { | |
| 75 return right_to_left_; | |
| 76 } | |
| 77 void set_right_to_left(bool value) { | |
| 78 right_to_left_ = value; | |
| 79 } | |
| 80 /// return pitch | |
| 81 int32_t fixed_pitch() const { | |
| 82 return pitch; | |
| 83 } | |
| 84 /// return kerning | |
| 85 int16_t kern() const { | |
| 86 return kerning; | |
| 87 } | |
| 88 /// return font class | |
| 89 int16_t font() const { | |
| 90 return font_class; | |
| 91 } | |
| 92 /// return spacing | |
| 93 int16_t space() const { | |
| 94 return spacing; | |
| 95 } | |
| 96 /// return filename | |
| 97 const char *name() const { | |
| 98 return filename.c_str(); | |
| 99 } | |
| 100 /// return xheight | |
| 101 int32_t x_height() const { | |
| 102 return xheight; | |
| 103 } | |
| 104 float cell_over_xheight() const { | |
| 105 return cell_over_xheight_; | |
| 106 } | |
| 107 void set_cell_over_xheight(float ratio) { | |
| 108 cell_over_xheight_ = ratio; | |
| 109 } | |
| 110 /// get rows | |
| 111 ROW_LIST *row_list() { | |
| 112 return &rows; | |
| 113 } | |
| 114 // Compute the margins between the edges of each row and this block's | |
| 115 // polyblock, and store the results in the rows. | |
| 116 void compute_row_margins(); | |
| 117 | |
| 118 // get paragraphs | |
| 119 PARA_LIST *para_list() { | |
| 120 return ¶s_; | |
| 121 } | |
| 122 /// get blobs | |
| 123 C_BLOB_LIST *blob_list() { | |
| 124 return &c_blobs; | |
| 125 } | |
| 126 C_BLOB_LIST *reject_blobs() { | |
| 127 return &rej_blobs; | |
| 128 } | |
| 129 FCOORD re_rotation() const { | |
| 130 return re_rotation_; // How to transform coords back to image. | |
| 131 } | |
| 132 void set_re_rotation(const FCOORD &rotation) { | |
| 133 re_rotation_ = rotation; | |
| 134 } | |
| 135 FCOORD classify_rotation() const { | |
| 136 return classify_rotation_; // Apply this before classifying. | |
| 137 } | |
| 138 void set_classify_rotation(const FCOORD &rotation) { | |
| 139 classify_rotation_ = rotation; | |
| 140 } | |
| 141 FCOORD skew() const { | |
| 142 return skew_; // Direction of true horizontal. | |
| 143 } | |
| 144 void set_skew(const FCOORD &skew) { | |
| 145 skew_ = skew; | |
| 146 } | |
| 147 const ICOORD &median_size() const { | |
| 148 return median_size_; | |
| 149 } | |
| 150 void set_median_size(int x, int y) { | |
| 151 median_size_.set_x(x); | |
| 152 median_size_.set_y(y); | |
| 153 } | |
| 154 | |
| 155 Image render_mask(TBOX *mask_box) { | |
| 156 return pdblk.render_mask(re_rotation_, mask_box); | |
| 157 } | |
| 158 | |
| 159 // Returns the bounding box including the desired combination of upper and | |
| 160 // lower noise/diacritic elements. | |
| 161 TBOX restricted_bounding_box(bool upper_dots, bool lower_dots) const; | |
| 162 | |
| 163 // Reflects the polygon in the y-axis and recomputes the bounding_box. | |
| 164 // Does nothing to any contained rows/words/blobs etc. | |
| 165 void reflect_polygon_in_y_axis(); | |
| 166 | |
| 167 void rotate(const FCOORD &rotation); | |
| 168 | |
| 169 /// decreasing y order | |
| 170 void sort_rows(); | |
| 171 | |
| 172 /// shrink white space | |
| 173 void compress(); | |
| 174 | |
| 175 /// check proportional | |
| 176 void check_pitch(); | |
| 177 | |
| 178 /// shrink white space and move by vector | |
| 179 void compress(const ICOORD vec); | |
| 180 | |
| 181 /// dump whole table | |
| 182 void print(FILE *fp, bool dump); | |
| 183 | |
| 184 BLOCK &operator=(const BLOCK &source); | |
| 185 PDBLK pdblk; ///< Page Description Block | |
| 186 | |
| 187 private: | |
| 188 bool proportional = false; ///< proportional | |
| 189 bool right_to_left_ = false; ///< major script is right to left. | |
| 190 int8_t kerning = 0; ///< inter blob gap | |
| 191 int16_t spacing = 0; ///< inter word gap | |
| 192 int16_t pitch = 0; ///< pitch of non-props | |
| 193 int16_t font_class = 0; ///< correct font class | |
| 194 int32_t xheight = 0; ///< height of chars | |
| 195 float cell_over_xheight_ = 0.0f; ///< Ratio of cell height to xheight. | |
| 196 std::string filename; ///< name of block | |
| 197 ROW_LIST rows; ///< rows in block | |
| 198 PARA_LIST paras_; ///< paragraphs of block | |
| 199 C_BLOB_LIST c_blobs; ///< before textord | |
| 200 C_BLOB_LIST rej_blobs; ///< duff stuff | |
| 201 FCOORD re_rotation_; ///< How to transform coords back to image. | |
| 202 FCOORD classify_rotation_; ///< Apply this before classifying. | |
| 203 FCOORD skew_; ///< Direction of true horizontal. | |
| 204 ICOORD median_size_; ///< Median size of blobs. | |
| 205 }; | |
| 206 | |
| 207 // A function to print segmentation stats for the given block list. | |
| 208 void PrintSegmentationStats(BLOCK_LIST *block_list); | |
| 209 | |
| 210 // Extracts blobs fromo the given block list and adds them to the output list. | |
| 211 // The block list must have been created by performing a page segmentation. | |
| 212 void ExtractBlobsFromSegmentation(BLOCK_LIST *blocks, C_BLOB_LIST *output_blob_list); | |
| 213 | |
| 214 // Refreshes the words in the block_list by using blobs in the | |
| 215 // new_blobs list. | |
| 216 // Block list must have word segmentation in it. | |
| 217 // It consumes the blobs provided in the new_blobs list. The blobs leftover in | |
| 218 // the new_blobs list after the call weren't matched to any blobs of the words | |
| 219 // in block list. | |
| 220 // The output not_found_blobs is a list of blobs from the original segmentation | |
| 221 // in the block_list for which no corresponding new blobs were found. | |
| 222 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST *block_list, C_BLOB_LIST *new_blobs, | |
| 223 C_BLOB_LIST *not_found_blobs); | |
| 224 | |
| 225 } // namespace tesseract | |
| 226 | |
| 227 #endif |
