Tesseract 3.01
/data/source/tesseract-ocr/ccstruct/ocrblock.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        ocrblock.h  (Formerly block.h)
00003  * Description: Page block class definition.
00004  * Author:              Ray Smith
00005  * Created:             Thu Mar 14 17:32:01 GMT 1991
00006  *
00007  * (C) Copyright 1991, Hewlett-Packard Ltd.
00008  ** Licensed under the Apache License, Version 2.0 (the "License");
00009  ** you may not use this file except in compliance with the License.
00010  ** You may obtain a copy of the License at
00011  ** http://www.apache.org/licenses/LICENSE-2.0
00012  ** Unless required by applicable law or agreed to in writing, software
00013  ** distributed under the License is distributed on an "AS IS" BASIS,
00014  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  ** See the License for the specific language governing permissions and
00016  ** limitations under the License.
00017  *
00018  **********************************************************************/
00019 
00020 #ifndef           OCRBLOCK_H
00021 #define           OCRBLOCK_H
00022 
00023 #include          "img.h"
00024 #include          "ocrrow.h"
00025 #include          "pdblock.h"
00026 
00027 class BLOCK;                     //forward decl
00028 
00029 ELISTIZEH (BLOCK)
00030 class BLOCK:public ELIST_LINK, public PDBLK
00031 //page block
00032 {
00033   friend class BLOCK_RECT_IT;    //block iterator
00034 
00035  public:
00036   BLOCK()
00037     : re_rotation_(1.0f, 0.0f),
00038       classify_rotation_(1.0f, 0.0f),
00039       skew_(1.0f, 0.0f) {
00040     right_to_left_ = false;
00041     hand_poly = NULL;
00042   }
00043   BLOCK(const char *name,  //< filename
00044         BOOL8 prop,        //< proportional
00045         inT16 kern,        //< kerning
00046         inT16 space,       //< spacing
00047         inT16 xmin,        //< bottom left
00048         inT16 ymin,
00049         inT16 xmax,        //< top right
00050         inT16 ymax);
00051 
00052   ~BLOCK () {
00053   }
00054 
00062   void set_stats(BOOL8 prop,
00063                  inT16 kern,
00064                  inT16 space,
00065                  inT16 ch_pitch) {
00066     proportional = prop;
00067     kerning = (inT8) kern;
00068     spacing = space;
00069     pitch = ch_pitch;
00070   }
00072   void set_xheight(inT32 height) {
00073     xheight = height;
00074   }
00076   void set_font_class(inT16 font) {
00077     font_class = font;
00078   }
00080   BOOL8 prop() const {
00081     return proportional;
00082   }
00083   bool right_to_left() const {
00084     return right_to_left_;
00085   }
00086   void set_right_to_left(bool value) {
00087     right_to_left_ = value;
00088   }
00090   inT32 fixed_pitch() const {
00091     return pitch;
00092   }
00094   inT16 kern() const {
00095     return kerning;
00096   }
00098   inT16 font() const {
00099     return font_class;
00100   }
00102   inT16 space() const {
00103     return spacing;
00104   }
00106   const char *name() const {
00107     return filename.string ();
00108   }
00110   inT32 x_height() const {
00111     return xheight;
00112   }
00113   float cell_over_xheight() const {
00114     return cell_over_xheight_;
00115   }
00116   void set_cell_over_xheight(float ratio) {
00117     cell_over_xheight_ = ratio;
00118   }
00120   ROW_LIST *row_list() {
00121     return &rows;
00122   }
00124   C_BLOB_LIST *blob_list() {
00125     return &c_blobs;
00126   }
00127   C_BLOB_LIST *reject_blobs() {
00128     return &rej_blobs;
00129   }
00130   FCOORD re_rotation() const {
00131     return re_rotation_;         // How to transform coords back to image.
00132   }
00133   void set_re_rotation(const FCOORD& rotation) {
00134     re_rotation_ = rotation;
00135   }
00136   FCOORD classify_rotation() const {
00137     return classify_rotation_;   // Apply this before classifying.
00138   }
00139   void set_classify_rotation(const FCOORD& rotation) {
00140     classify_rotation_ = rotation;
00141   }
00142   FCOORD skew() const {
00143     return skew_;                // Direction of true horizontal.
00144   }
00145   void set_skew(const FCOORD& skew) {
00146     skew_ = skew;
00147   }
00148   const ICOORD& median_size() const {
00149     return median_size_;
00150   }
00151   void set_median_size(int x, int y) {
00152     median_size_.set_x(x);
00153     median_size_.set_y(y);
00154   }
00155 
00156   Pix* render_mask() {
00157     return PDBLK::render_mask(re_rotation_);
00158   }
00159 
00160   void rotate(const FCOORD& rotation);
00161 
00163   void sort_rows();
00164 
00166   void compress();
00167 
00169   void check_pitch();
00170 
00172   void compress(const ICOORD vec);
00173 
00175   void print(FILE *fp, BOOL8 dump);
00176 
00177   BLOCK& operator=(const BLOCK & source);
00178 
00179  private:
00180   BOOL8 proportional;          //< proportional
00181   bool right_to_left_;         //< major script is right to left.
00182   inT8 kerning;                //< inter blob gap
00183   inT16 spacing;               //< inter word gap
00184   inT16 pitch;                 //< pitch of non-props
00185   inT16 font_class;            //< correct font class
00186   inT32 xheight;               //< height of chars
00187   float cell_over_xheight_;    //< Ratio of cell height to xheight.
00188   STRING filename;             //< name of block
00189   ROW_LIST rows;               //< rows in block
00190   C_BLOB_LIST c_blobs;         //< before textord
00191   C_BLOB_LIST rej_blobs;       //< duff stuff
00192   FCOORD re_rotation_;         //< How to transform coords back to image.
00193   FCOORD classify_rotation_;   //< Apply this before classifying.
00194   FCOORD skew_;                //< Direction of true horizontal.
00195   ICOORD median_size_;         //< Median size of blobs.
00196 };
00197 
00198 int decreasing_top_order(const void *row1, const void *row2);
00199 
00200 // A function to print segmentation stats for the given block list.
00201 void PrintSegmentationStats(BLOCK_LIST* block_list);
00202 
00203 // Extracts blobs fromo the given block list and adds them to the output list.
00204 // The block list must have been created by performing a page segmentation.
00205 void ExtractBlobsFromSegmentation(BLOCK_LIST* blocks,
00206                                   C_BLOB_LIST* output_blob_list);
00207 
00208 // Refreshes the words in the block_list by using blobs in the
00209 // new_blobs list.
00210 // Block list must have word segmentation in it.
00211 // It consumes the blobs provided in the new_blobs list. The blobs leftover in
00212 // the new_blobs list after the call weren't matched to any blobs of the words
00213 // in block list.
00214 // The output not_found_blobs is a list of blobs from the original segmentation
00215 // in the block_list for which no corresponding new blobs were found.
00216 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
00217                                   C_BLOB_LIST* new_blobs,
00218                                   C_BLOB_LIST* not_found_blobs);
00219 
00220 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines