tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/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          "ocrpara.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   }
00123   // Compute the margins between the edges of each row and this block's
00124   // polyblock, and store the results in the rows.
00125   void compute_row_margins();
00126 
00127   // get paragraphs
00128   PARA_LIST *para_list() {
00129     return &paras_;
00130   }
00132   C_BLOB_LIST *blob_list() {
00133     return &c_blobs;
00134   }
00135   C_BLOB_LIST *reject_blobs() {
00136     return &rej_blobs;
00137   }
00138   FCOORD re_rotation() const {
00139     return re_rotation_;         // How to transform coords back to image.
00140   }
00141   void set_re_rotation(const FCOORD& rotation) {
00142     re_rotation_ = rotation;
00143   }
00144   FCOORD classify_rotation() const {
00145     return classify_rotation_;   // Apply this before classifying.
00146   }
00147   void set_classify_rotation(const FCOORD& rotation) {
00148     classify_rotation_ = rotation;
00149   }
00150   FCOORD skew() const {
00151     return skew_;                // Direction of true horizontal.
00152   }
00153   void set_skew(const FCOORD& skew) {
00154     skew_ = skew;
00155   }
00156   const ICOORD& median_size() const {
00157     return median_size_;
00158   }
00159   void set_median_size(int x, int y) {
00160     median_size_.set_x(x);
00161     median_size_.set_y(y);
00162   }
00163 
00164   Pix* render_mask() {
00165     return PDBLK::render_mask(re_rotation_);
00166   }
00167 
00168   // Reflects the polygon in the y-axis and recomputes the bounding_box.
00169   // Does nothing to any contained rows/words/blobs etc.
00170   void reflect_polygon_in_y_axis();
00171 
00172   void rotate(const FCOORD& rotation);
00173 
00175   void sort_rows();
00176 
00178   void compress();
00179 
00181   void check_pitch();
00182 
00184   void compress(const ICOORD vec);
00185 
00187   void print(FILE *fp, BOOL8 dump);
00188 
00189   BLOCK& operator=(const BLOCK & source);
00190 
00191  private:
00192   BOOL8 proportional;          //< proportional
00193   bool right_to_left_;         //< major script is right to left.
00194   inT8 kerning;                //< inter blob gap
00195   inT16 spacing;               //< inter word gap
00196   inT16 pitch;                 //< pitch of non-props
00197   inT16 font_class;            //< correct font class
00198   inT32 xheight;               //< height of chars
00199   float cell_over_xheight_;    //< Ratio of cell height to xheight.
00200   STRING filename;             //< name of block
00201   ROW_LIST rows;               //< rows in block
00202   PARA_LIST paras_;            //< paragraphs of block
00203   C_BLOB_LIST c_blobs;         //< before textord
00204   C_BLOB_LIST rej_blobs;       //< duff stuff
00205   FCOORD re_rotation_;         //< How to transform coords back to image.
00206   FCOORD classify_rotation_;   //< Apply this before classifying.
00207   FCOORD skew_;                //< Direction of true horizontal.
00208   ICOORD median_size_;         //< Median size of blobs.
00209 };
00210 
00211 int decreasing_top_order(const void *row1, const void *row2);
00212 
00213 // A function to print segmentation stats for the given block list.
00214 void PrintSegmentationStats(BLOCK_LIST* block_list);
00215 
00216 // Extracts blobs fromo the given block list and adds them to the output list.
00217 // The block list must have been created by performing a page segmentation.
00218 void ExtractBlobsFromSegmentation(BLOCK_LIST* blocks,
00219                                   C_BLOB_LIST* output_blob_list);
00220 
00221 // Refreshes the words in the block_list by using blobs in the
00222 // new_blobs list.
00223 // Block list must have word segmentation in it.
00224 // It consumes the blobs provided in the new_blobs list. The blobs leftover in
00225 // the new_blobs list after the call weren't matched to any blobs of the words
00226 // in block list.
00227 // The output not_found_blobs is a list of blobs from the original segmentation
00228 // in the block_list for which no corresponding new blobs were found.
00229 void RefreshWordBlobsFromNewBlobs(BLOCK_LIST* block_list,
00230                                   C_BLOB_LIST* new_blobs,
00231                                   C_BLOB_LIST* not_found_blobs);
00232 
00233 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines