tesseract  3.03
/usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/mfoutline.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  **     Filename:    mfoutline.h
00003  **     Purpose:     Interface spec for fx outline structures
00004  **     Author:      Dan Johnson
00005  **     History:     Thu May 17 08:55:32 1990, DSJ, Created.
00006  **
00007  **     (c) Copyright Hewlett-Packard Company, 1988.
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 #ifndef   MFOUTLINE_H
00019 #define   MFOUTLINE_H
00020 
00024 #include "blobs.h"
00025 #include "host.h"
00026 #include "oldlist.h"
00027 #include "fpoint.h"
00028 #include "params.h"
00029 
00030 #define NORMAL_X_HEIGHT   (0.5)
00031 #define NORMAL_BASELINE   (0.0)
00032 
00033 typedef LIST MFOUTLINE;
00034 
00035 typedef enum {
00036   north, south, east, west, northeast, northwest, southeast, southwest
00037 } DIRECTION;
00038 
00039 typedef struct {
00040   FPOINT Point;
00041   FLOAT32 Slope;
00042   unsigned Padding:20;
00043   BOOL8 Hidden:TRUE;
00044   BOOL8 ExtremityMark:TRUE;
00045   DIRECTION Direction:4;
00046   DIRECTION PreviousDirection:4;
00047 } MFEDGEPT;
00048 
00049 typedef enum {
00050   outer, hole
00051 } OUTLINETYPE;
00052 
00053 typedef struct {
00054   FLOAT64 Mx, My;                /* first moment of all outlines */
00055   FLOAT64 L;                     /* total length of all outlines */
00056   FLOAT64 x, y;                  /* center of mass of all outlines */
00057   FLOAT64 Ix, Iy;                /* second moments about center of mass axes */
00058   FLOAT64 Rx, Ry;                /* radius of gyration about center of mass axes */
00059 } OUTLINE_STATS;
00060 
00061 typedef enum {
00062   baseline, character
00063 } NORM_METHOD;
00064 
00068 #define AverageOf(A,B)    (((A) + (B)) / 2)
00069 
00070 /* macro for computing the scale factor to use to normalize characters */
00071 #define MF_SCALE_FACTOR  (NORMAL_X_HEIGHT / kBlnXHeight)
00072 
00073 /* macros for manipulating micro-feature outlines */
00074 #define DegenerateOutline(O)  (((O) == NIL_LIST) || ((O) == list_rest(O)))
00075 #define PointAt(O)    ((MFEDGEPT *) first_node (O))
00076 #define NextPointAfter(E) (list_rest (E))
00077 #define MakeOutlineCircular(O)  (set_rest (last (O), (O)))
00078 
00079 /* macros for manipulating micro-feature outline edge points */
00080 #define ClearMark(P)    ((P)->ExtremityMark = FALSE)
00081 #define MarkPoint(P)    ((P)->ExtremityMark = TRUE)
00082 
00086 void ComputeBlobCenter(TBLOB *Blob, TPOINT *BlobCenter);
00087 
00088 LIST ConvertBlob(TBLOB *Blob);
00089 
00090 MFOUTLINE ConvertOutline(TESSLINE *Outline);
00091 
00092 LIST ConvertOutlines(TESSLINE *Outline,
00093                      LIST ConvertedOutlines,
00094                      OUTLINETYPE OutlineType);
00095 
00096 void FilterEdgeNoise(MFOUTLINE Outline, FLOAT32 NoiseSegmentLength);
00097 
00098 void FindDirectionChanges(MFOUTLINE Outline,
00099                           FLOAT32 MinSlope,
00100                           FLOAT32 MaxSlope);
00101 
00102 void FreeMFOutline(void *agr);  //MFOUTLINE                             Outline);
00103 
00104 void FreeOutlines(LIST Outlines);
00105 
00106 void MarkDirectionChanges(MFOUTLINE Outline);
00107 
00108 MFEDGEPT *NewEdgePoint();
00109 
00110 MFOUTLINE NextExtremity(MFOUTLINE EdgePoint);
00111 
00112 void NormalizeOutline(MFOUTLINE Outline,
00113                       FLOAT32 XOrigin);
00114 
00115 /*----------------------------------------------------------------------------
00116           Private Function Prototypes
00117 -----------------------------------------------------------------------------*/
00118 void ChangeDirection(MFOUTLINE Start, MFOUTLINE End, DIRECTION Direction);
00119 
00120 // Normalizes the Outline in-place using cn_denorm's local transformation,
00121 // then converts from the integer feature range [0,255] to the clusterer
00122 // feature range of [-0.5, 0.5].
00123 void CharNormalizeOutline(MFOUTLINE Outline, const DENORM& cn_denorm);
00124 
00125 void ComputeDirection(MFEDGEPT *Start,
00126                       MFEDGEPT *Finish,
00127                       FLOAT32 MinSlope,
00128                       FLOAT32 MaxSlope);
00129 
00130 void FinishOutlineStats(register OUTLINE_STATS *OutlineStats);
00131 
00132 void InitOutlineStats(OUTLINE_STATS *OutlineStats);
00133 
00134 MFOUTLINE NextDirectionChange(MFOUTLINE EdgePoint);
00135 
00136 void UpdateOutlineStats(register OUTLINE_STATS *OutlineStats,
00137                         register FLOAT32 x1,
00138                         register FLOAT32 x2,
00139                         register FLOAT32 y1,
00140                         register FLOAT32 y2);
00141 
00142 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines