0
|
1 |
/* Page.h
|
|
2 |
The Page class is the primary class used for the OCR system
|
|
3 |
It has two data representations of a page of text, an RLEMap
|
|
4 |
and a BitMap.
|
|
5 |
|
|
6 |
*/
|
|
7 |
|
|
8 |
#ifndef _PAGE_H
|
|
9 |
#define _PAGE_H
|
|
10 |
#include "system.h"
|
|
11 |
#include "Component.h"
|
|
12 |
#include "RLEMap.h"
|
|
13 |
#include "BitMap.h"
|
|
14 |
#include "LineMarker.h"
|
|
15 |
#include "Word.h"
|
|
16 |
#include "tcl_interface.h"
|
|
17 |
|
|
18 |
class Page {
|
|
19 |
public:
|
|
20 |
// Constructor, Destructor
|
|
21 |
friend int main(int argc, char** argv);
|
|
22 |
friend void testocr(int argc, char ** argv);
|
|
23 |
Page();
|
|
24 |
~Page();
|
|
25 |
|
|
26 |
|
|
27 |
// Read is from 2 level TIFF files.
|
|
28 |
// Calls BitMap function. readMap then converts to RLE
|
|
29 |
|
|
30 |
MapStatus readMap(char * filename); // Calls BitMap::readMap
|
|
31 |
|
|
32 |
Angle skewAngle(); // returns skew estimate
|
|
33 |
int deskew(int deskew_method); /* one for rle, 0 for bitmap rot */
|
|
34 |
|
|
35 |
MapStatus setLines();
|
|
36 |
/* Sets fnumlines to the # of text lines
|
|
37 |
and dimensions and sets flineinfo for start and end row
|
|
38 |
for each line. */
|
|
39 |
void Page::display_line_boundaries();
|
|
40 |
/* highlights the space between lines of text in TCL//TK */
|
|
41 |
|
|
42 |
MapStatus extractComponents();
|
|
43 |
/* Extract Component information for each line of text
|
|
44 |
Does connected component analysis then projects up and
|
|
45 |
down to catch circumflexes. A component list is created
|
|
46 |
for each line of text Assumes image has already been deskewed
|
|
47 |
using deskew and that setLines has been run to determine
|
|
48 |
text line boundaries ***/
|
|
49 |
|
|
50 |
MapStatus recognize();
|
|
51 |
/* Recongnize whole page. Run after extractComponents.
|
|
52 |
learn() or readLearnedGroups() must also be run
|
|
53 |
before this function **/
|
|
54 |
|
|
55 |
MapStatus recognize(int linenum); // just one line
|
|
56 |
/* Recognize characters
|
|
57 |
Perform Character Recogition on a line of components.
|
|
58 |
Use the global variable LearnedGroups for comparison.
|
|
59 |
***/
|
|
60 |
|
|
61 |
MapStatus extractWords();
|
|
62 |
/* Find the start and end of words using avgSpacing and
|
|
63 |
add to word list fWordList */
|
|
64 |
|
|
65 |
void spellcheck();
|
|
66 |
/* spellcheck the list of words (set the mispelled field
|
|
67 |
in each word) */
|
|
68 |
|
|
69 |
int send_words_to_tcl();
|
|
70 |
/* Send words to user interface */
|
|
71 |
int writeWordPos(char * filename);
|
|
72 |
/* Write upper left point coordinates, confidence and translation to
|
|
73 |
file */
|
|
74 |
int writeAscii(char * filename);
|
|
75 |
/** Write words out to acii file **/
|
|
76 |
|
|
77 |
|
|
78 |
void printComponents();
|
|
79 |
/* Prints out a little bitmap for each bad component in the list.
|
|
80 |
Uses ConfidenceThreshold as a cutoff for printing characters.
|
|
81 |
Just used for debugging*/
|
|
82 |
void printComponent(Component* comp);
|
|
83 |
|
|
84 |
void Page::printWords();
|
|
85 |
/* prints out bitmap for each component delimiting between words.*/
|
|
86 |
|
|
87 |
|
|
88 |
int get_height();
|
|
89 |
int get_width();
|
|
90 |
inline BitMap * bmap() {return fBitMap;};
|
|
91 |
inline RLEMap * rmap() {return fRLEMap;};
|
|
92 |
inline Words * words() {return fWordList;};
|
|
93 |
inline Components * line(int i) {return fLineComponents[i];};
|
|
94 |
|
|
95 |
int numLines() {return fnumLines;};
|
|
96 |
LineMarker * lineinfo() {return flineinfo;};
|
|
97 |
int avgSpacing() {return favgSpacing;};
|
|
98 |
|
|
99 |
private:
|
|
100 |
int fnumLines; // Number of lines
|
|
101 |
LineMarker * flineinfo; // for each line - start and end row
|
|
102 |
// in RLEMap
|
|
103 |
int favgSpacing ; // Avg spacing between comp (in pixels)
|
|
104 |
Components ** fLineComponents; // A list of components for each line
|
|
105 |
|
|
106 |
Words * fWordList; // A list of words in the document
|
|
107 |
RLEMap * fRLEMap; // Pointer to an RLEMap represntation
|
|
108 |
BitMap * fBitMap; // Pointer to BitMap representation
|
|
109 |
|
|
110 |
int spacing(ListElement * compa, ListElement * compb);
|
|
111 |
// helper function for extractWords
|
|
112 |
// Returns # of horizontal blank pixels between 2 components
|
|
113 |
void divideAndRecognize (Components * list, ListElement * ptr, Distance d);
|
|
114 |
void uniteAndRecognize(Components * list, ListElement * ptr, Distance d);
|
|
115 |
};
|
|
116 |
#endif
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|