Tesseract  3.02
tesseract-ocr/textord/oldbasel.h
Go to the documentation of this file.
00001 /**********************************************************************
00002  * File:        oldbasel.h  (Formerly oldbl.h)
00003  * Description: A re-implementation of the old baseline algorithm.
00004  * Author:              Ray Smith
00005  * Created:             Wed Oct  6 09:41:48 BST 1993
00006  *
00007  * (C) Copyright 1993, 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           OLDBASEL_H
00021 #define           OLDBASEL_H
00022 
00023 #include          "params.h"
00024 #include          "blobbox.h"
00025 #include          "notdll.h"
00026 
00027 extern BOOL_VAR_H (textord_really_old_xheight, FALSE,
00028 "Use original wiseowl xheight");
00029 extern BOOL_VAR_H (textord_oldbl_debug, FALSE,
00030 "Debug old baseline generation");
00031 extern BOOL_VAR_H (textord_debug_baselines, FALSE,
00032 "Debug baseline generation");
00033 extern BOOL_VAR_H (textord_oldbl_paradef, TRUE, "Use para default mechanism");
00034 extern BOOL_VAR_H (textord_oldbl_split_splines, TRUE,
00035 "Split stepped splines");
00036 extern BOOL_VAR_H (textord_oldbl_merge_parts, TRUE,
00037 "Merge suspect partitions");
00038 extern BOOL_VAR_H (oldbl_xhfix, FALSE,
00039 "Fix bug in modes threshold for xheights");
00040 extern INT_VAR_H (oldbl_holed_losscount, 10,
00041 "Max lost before fallback line used");
00042 extern double_VAR_H (oldbl_dot_error_size, 1.26, "Max aspect ratio of a dot");
00043 extern double_VAR_H (textord_oldbl_jumplimit, 0.15,
00044 "X fraction for new partition");
00045 int get_blob_coords(                    //get boxes
00046                     TO_ROW *row,        //row to use
00047                     inT32 lineheight,   //block level
00048                     TBOX *blobcoords,    //ouput boxes
00049                     BOOL8 &holed_line,  //lost a lot of blobs
00050                     int &outcount       //no of real blobs
00051                    );
00052 void make_first_baseline (       //initial approximation
00053 TBOX blobcoords[],                /*blob bounding boxes */
00054 int blobcount,                   /*no of blobcoords */
00055 int xcoords[],                   /*coords for spline */
00056 int ycoords[],                   /*approximator */
00057 QSPLINE * spline,                /*initial spline */
00058 QSPLINE * baseline,              /*output spline */
00059 float jumplimit                  /*guess half descenders */
00060 );
00061 void make_holed_baseline (       //initial approximation
00062 TBOX blobcoords[],                /*blob bounding boxes */
00063 int blobcount,                   /*no of blobcoords */
00064 QSPLINE * spline,                /*initial spline */
00065 QSPLINE * baseline,              /*output spline */
00066 float gradient                   //of line
00067 );
00068 int partition_line (             //partition blobs
00069 TBOX blobcoords[],                //bounding boxes
00070 int blobcount,                   /*no of blobs on row */
00071 int *numparts,                   /*number of partitions */
00072 char partids[],                  /*partition no of each blob */
00073 int partsizes[],                 /*no in each partition */
00074 QSPLINE * spline,                /*curve to fit to */
00075 float jumplimit,                 /*allowed delta change */
00076 float ydiffs[]                   /*diff from spline */
00077 );
00078 void merge_oldbl_parts (         //partition blobs
00079 TBOX blobcoords[],                //bounding boxes
00080 int blobcount,                   /*no of blobs on row */
00081 char partids[],                  /*partition no of each blob */
00082 int partsizes[],                 /*no in each partition */
00083 int biggestpart,                 //major partition
00084 float jumplimit                  /*allowed delta change */
00085 );
00086 int get_ydiffs (                 //evaluate differences
00087 TBOX blobcoords[],                //bounding boxes
00088 int blobcount,                   /*no of blobs */
00089 QSPLINE * spline,                /*approximating spline */
00090 float ydiffs[]                   /*output */
00091 );
00092 int choose_partition (           //select partition
00093 register float diff,             /*diff from spline */
00094 float partdiffs[],               /*diff on all parts */
00095 int lastpart,                    /*last assigned partition */
00096 float jumplimit,                 /*new part threshold */
00097 float* drift,
00098 float* last_delta,
00099 int *partcount                   /*no of partitions */
00100 );
00101 int partition_coords (           //find relevant coords
00102 TBOX blobcoords[],                //bounding boxes
00103 int blobcount,                   /*no of blobs in row */
00104 char partids[],                  /*partition no of each blob */
00105 int bestpart,                    /*best new partition */
00106 int xcoords[],                   /*points to work on */
00107 int ycoords[]                    /*points to work on */
00108 );
00109 int segment_spline (             //make xstarts
00110 TBOX blobcoords[],                //boundign boxes
00111 int blobcount,                   /*no of blobs in row */
00112 int xcoords[],                   /*points to work on */
00113 int ycoords[],                   /*points to work on */
00114 int degree, int pointcount,      /*no of points */
00115 int xstarts[]                    //result
00116 );
00117 BOOL8 split_stepped_spline (     //make xstarts
00118 QSPLINE * baseline,              //current shot
00119 float jumplimit,                 //max step fuction
00120 int xcoords[],                   /*points to work on */
00121 int xstarts[],                   //result
00122 int &segments                    //no of segments
00123 );
00124 void insert_spline_point (       //get descenders
00125 int xstarts[],                   //starts to shuffle
00126 int segment,                     //insertion pt
00127 int coord1,                      //coords to add
00128 int coord2, int &segments        //total segments
00129 );
00130 void find_lesser_parts (         //get descenders
00131 TO_ROW * row,                    //row to process
00132 TBOX blobcoords[],                //bounding boxes
00133 int blobcount,                   /*no of blobs */
00134 char partids[],                  /*partition of each blob */
00135 int partsizes[],                 /*size of each part */
00136 int partcount,                   /*no of partitions */
00137 int bestpart                     /*biggest partition */
00138 );
00139 
00140 void old_first_xheight (         //the wiseowl way
00141 TO_ROW * row,                    /*current row */
00142 TBOX blobcoords[],                /*blob bounding boxes */
00143 int initialheight,               //initial guess
00144 int blobcount,                   /*blobs in blobcoords */
00145 QSPLINE * baseline,              /*established */
00146 float jumplimit                  /*min ascender height */
00147 );
00148 
00149 void make_first_xheight (        //find xheight
00150 TO_ROW * row,                    /*current row */
00151 TBOX blobcoords[],                /*blob bounding boxes */
00152 int lineheight,                  //initial guess
00153 int init_lineheight,             //block level guess
00154 int blobcount,                   /*blobs in blobcoords */
00155 QSPLINE * baseline,              /*established */
00156 float jumplimit                  /*min ascender height */
00157 );
00158 
00159 int *make_height_array (         //get array of heights
00160 TBOX blobcoords[],                /*blob bounding boxes */
00161 int blobcount,                   /*blobs in blobcoords */
00162 QSPLINE * baseline               /*established */
00163 );
00164 
00165 void find_top_modes (            //get modes
00166 STATS * stats,                   //stats to hack
00167 int statnum,                     //no of piles
00168 int modelist[], int modenum      //no of modes to get
00169 );
00170 
00171 void pick_x_height(TO_ROW * row,                    //row to do
00172 int modelist[],
00173 int lefts[], int rights[],
00174 STATS * heightstat,
00175 int mode_threshold);
00176 #endif