1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml">
4
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
5
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
6
<title>tesseract: /usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/shapeclassifier.h Source File</title>
8
<link href="tabs.css" rel="stylesheet" type="text/css"/>
9
<link href="doxygen.css" rel="stylesheet" type="text/css" />
10
<link href="navtree.css" rel="stylesheet" type="text/css"/>
11
<script type="text/javascript" src="jquery.js"></script>
12
<script type="text/javascript" src="resize.js"></script>
13
<script type="text/javascript" src="navtree.js"></script>
14
<script type="text/javascript">
15
$(document).ready(initResizable);
17
<link href="search/search.css" rel="stylesheet" type="text/css"/>
18
<script type="text/javascript" src="search/search.js"></script>
19
<script type="text/javascript">
20
$(document).ready(function() { searchBox.OnSelectItem(0); });
25
<div id="top"><!-- do not remove this div! -->
29
<table cellspacing="0" cellpadding="0">
31
<tr style="height: 56px;">
34
<td style="padding-left: 0.5em;">
35
<div id="projectname">tesseract
36
 <span id="projectnumber">3.03</span>
48
<!-- Generated by Doxygen 1.7.6.1 -->
49
<script type="text/javascript">
50
var searchBox = new SearchBox("searchBox", "search",false,'Search');
52
<div id="navrow1" class="tabs">
54
<li><a href="index.html"><span>Main Page</span></a></li>
55
<li><a href="pages.html"><span>Related Pages</span></a></li>
56
<li><a href="modules.html"><span>Modules</span></a></li>
57
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
58
<li><a href="annotated.html"><span>Classes</span></a></li>
59
<li class="current"><a href="files.html"><span>Files</span></a></li>
61
<div id="MSearchBox" class="MSearchBoxInactive">
63
<img id="MSearchSelect" src="search/mag_sel.png"
64
onmouseover="return searchBox.OnSearchSelectShow()"
65
onmouseout="return searchBox.OnSearchSelectHide()"
67
<input type="text" id="MSearchField" value="Search" accesskey="S"
68
onfocus="searchBox.OnSearchFieldFocus(true)"
69
onblur="searchBox.OnSearchFieldFocus(false)"
70
onkeyup="searchBox.OnSearchFieldChange(event)"/>
71
</span><span class="right">
72
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
78
<div id="navrow2" class="tabs2">
80
<li><a href="files.html"><span>File List</span></a></li>
81
<li><a href="globals.html"><span>File Members</span></a></li>
85
<div id="side-nav" class="ui-resizable side-nav-resizable">
87
<div id="nav-tree-contents">
90
<div id="splitbar" style="-moz-user-select:none;"
91
class="ui-resizable-handle">
94
<script type="text/javascript">
95
initNavTree('a00939.html','');
97
<div id="doc-content">
99
<div class="headertitle">
100
<div class="title">/usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/shapeclassifier.h</div> </div>
102
<div class="contents">
103
<a href="a00939.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright 2011 Google Inc. All Rights Reserved.</span>
104
<a name="l00002"></a>00002 <span class="comment">// Author: rays@google.com (Ray Smith)</span>
105
<a name="l00004"></a>00004 <span class="comment"></span><span class="comment">// File: shapeclassifier.h</span>
106
<a name="l00005"></a>00005 <span class="comment">// Description: Base interface class for classifiers that return a</span>
107
<a name="l00006"></a>00006 <span class="comment">// shape index.</span>
108
<a name="l00007"></a>00007 <span class="comment">// Author: Ray Smith</span>
109
<a name="l00008"></a>00008 <span class="comment">// Created: Tue Sep 13 11:26:32 PDT 2011</span>
110
<a name="l00009"></a>00009 <span class="comment">//</span>
111
<a name="l00010"></a>00010 <span class="comment">// (C) Copyright 2011, Google Inc.</span>
112
<a name="l00011"></a>00011 <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span>
113
<a name="l00012"></a>00012 <span class="comment">// you may not use this file except in compliance with the License.</span>
114
<a name="l00013"></a>00013 <span class="comment">// You may obtain a copy of the License at</span>
115
<a name="l00014"></a>00014 <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span>
116
<a name="l00015"></a>00015 <span class="comment">// Unless required by applicable law or agreed to in writing, software</span>
117
<a name="l00016"></a>00016 <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span>
118
<a name="l00017"></a>00017 <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
119
<a name="l00018"></a>00018 <span class="comment">// See the License for the specific language governing permissions and</span>
120
<a name="l00019"></a>00019 <span class="comment">// limitations under the License.</span>
121
<a name="l00020"></a>00020 <span class="comment">//</span>
122
<a name="l00022"></a>00022 <span class="comment"></span>
123
<a name="l00023"></a>00023 <span class="preprocessor">#ifndef TESSERACT_CLASSIFY_SHAPECLASSIFIER_H_</span>
124
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#define TESSERACT_CLASSIFY_SHAPECLASSIFIER_H_</span>
125
<a name="l00025"></a>00025 <span class="preprocessor"></span>
126
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="a00862.html">unichar.h</a>"</span>
127
<a name="l00027"></a>00027
128
<a name="l00028"></a>00028 <span class="keyword">template</span> <<span class="keyword">typename</span> T> <span class="keyword">class </span><a class="code" href="a00403.html">GenericVector</a>;
129
<a name="l00029"></a>00029 <span class="keyword">struct </span>Pix;
130
<a name="l00030"></a>00030 <span class="keyword">class </span><a class="code" href="a00532.html">ScrollView</a>;
131
<a name="l00031"></a>00031 <span class="keyword">class </span><a class="code" href="a00642.html">UNICHARSET</a>;
132
<a name="l00032"></a>00032
133
<a name="l00033"></a>00033 <span class="keyword">namespace </span><a class="code" href="a01266.html#afed58feacb84df2de88bdd613cfdba6d">tesseract</a> {
134
<a name="l00034"></a>00034
135
<a name="l00035"></a>00035 <span class="keyword">template</span> <<span class="keyword">typename</span> T> <span class="keyword">class </span>PointerVector;
136
<a name="l00036"></a>00036 <span class="keyword">struct </span>ShapeRating;
137
<a name="l00037"></a>00037 <span class="keyword">class </span>ShapeTable;
138
<a name="l00038"></a>00038 <span class="keyword">class </span>TrainingSample;
139
<a name="l00039"></a>00039 <span class="keyword">class </span>TrainingSampleSet;
140
<a name="l00040"></a>00040 <span class="keyword">struct </span>UnicharRating;
141
<a name="l00041"></a>00041
142
<a name="l00042"></a>00042 <span class="comment">// Interface base class for classifiers that produce ShapeRating results.</span>
143
<a name="l00043"></a><a class="code" href="a00540.html">00043</a> <span class="keyword">class </span><a class="code" href="a00540.html">ShapeClassifier</a> {
144
<a name="l00044"></a>00044 <span class="keyword">public</span>:
145
<a name="l00045"></a><a class="code" href="a00540.html#a8beb57719279f6b67f426dcccb6231b7">00045</a> <span class="keyword">virtual</span> <a class="code" href="a00540.html#a8beb57719279f6b67f426dcccb6231b7">~ShapeClassifier</a>() {}
146
<a name="l00046"></a>00046
147
<a name="l00047"></a>00047 <span class="comment">// Classifies the given [training] sample, writing to results.</span>
148
<a name="l00048"></a>00048 <span class="comment">// If page_pix is not NULL, the overriding function may call</span>
149
<a name="l00049"></a>00049 <span class="comment">// sample.GetSamplePix(padding, page_pix) to get an image of the sample</span>
150
<a name="l00050"></a>00050 <span class="comment">// padded (with real image data) by the given padding to extract features</span>
151
<a name="l00051"></a>00051 <span class="comment">// from the image of the character. Other members of TrainingSample:</span>
152
<a name="l00052"></a>00052 <span class="comment">// features(), micro_features(), cn_feature(), geo_feature() may be used</span>
153
<a name="l00053"></a>00053 <span class="comment">// to get the appropriate tesseract features.</span>
154
<a name="l00054"></a>00054 <span class="comment">// If debug is non-zero, then various degrees of classifier dependent debug</span>
155
<a name="l00055"></a>00055 <span class="comment">// information is provided.</span>
156
<a name="l00056"></a>00056 <span class="comment">// If keep_this (a UNICHAR_ID) is >= 0, then the results should always</span>
157
<a name="l00057"></a>00057 <span class="comment">// contain keep_this, and (if possible) anything of intermediate confidence.</span>
158
<a name="l00058"></a>00058 <span class="comment">// (Used for answering "Why didn't it get that right?" questions.) It must</span>
159
<a name="l00059"></a>00059 <span class="comment">// be a UNICHAR_ID as the callers have no clue how to choose the best shape</span>
160
<a name="l00060"></a>00060 <span class="comment">// that may contain a desired answer.</span>
161
<a name="l00061"></a>00061 <span class="comment">// The return value is the number of classes saved in results.</span>
162
<a name="l00062"></a>00062 <span class="comment">// NOTE that overriding functions MUST clear and sort the results by</span>
163
<a name="l00063"></a>00063 <span class="comment">// descending rating unless the classifier is working with a team of such</span>
164
<a name="l00064"></a>00064 <span class="comment">// classifiers.</span>
165
<a name="l00065"></a>00065 <span class="comment">// NOTE: Neither overload of ClassifySample is pure, but at least one must</span>
166
<a name="l00066"></a>00066 <span class="comment">// be overridden by a classifier in order for it to do anything.</span>
167
<a name="l00067"></a>00067 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="a00540.html#a7c02e74689b6591fd0d56ab2f0e92a86">UnicharClassifySample</a>(<span class="keyword">const</span> <a class="code" href="a00630.html">TrainingSample</a>& <a class="code" href="a00525.html">sample</a>, Pix* page_pix,
168
<a name="l00068"></a>00068 <span class="keywordtype">int</span> debug, <a class="code" href="a00862.html#a8578b19fa1ff5ca75080db1a18ecc32e">UNICHAR_ID</a> keep_this,
169
<a name="l00069"></a>00069 <a class="code" href="a00403.html">GenericVector<UnicharRating></a>* results);
170
<a name="l00070"></a>00070
171
<a name="l00071"></a>00071 <span class="keyword">protected</span>:
172
<a name="l00072"></a>00072 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="a00540.html#a0bd45d4adca11310d79afa0c0a312e5f">ClassifySample</a>(<span class="keyword">const</span> <a class="code" href="a00630.html">TrainingSample</a>& <a class="code" href="a00525.html">sample</a>, Pix* page_pix,
173
<a name="l00073"></a>00073 <span class="keywordtype">int</span> debug, <a class="code" href="a00862.html#a8578b19fa1ff5ca75080db1a18ecc32e">UNICHAR_ID</a> keep_this,
174
<a name="l00074"></a>00074 <a class="code" href="a00403.html">GenericVector<ShapeRating></a>* results);
175
<a name="l00075"></a>00075
176
<a name="l00076"></a>00076 <span class="keyword">public</span>:
177
<a name="l00077"></a>00077 <span class="comment">// Returns the shape that contains unichar_id that has the best result.</span>
178
<a name="l00078"></a>00078 <span class="comment">// If result is not NULL, it is set with the shape_id and rating.</span>
179
<a name="l00079"></a>00079 <span class="comment">// Returns -1 if ClassifySample fails to provide any result containing</span>
180
<a name="l00080"></a>00080 <span class="comment">// unichar_id. BestShapeForUnichar does not need to be overridden if</span>
181
<a name="l00081"></a>00081 <span class="comment">// ClassifySample respects the keep_this rule.</span>
182
<a name="l00082"></a>00082 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="a00540.html#a57b3d00a13eb4e73f9a5284a74e789d9">BestShapeForUnichar</a>(<span class="keyword">const</span> <a class="code" href="a00630.html">TrainingSample</a>& <a class="code" href="a00525.html">sample</a>, Pix* page_pix,
183
<a name="l00083"></a>00083 <a class="code" href="a00862.html#a8578b19fa1ff5ca75080db1a18ecc32e">UNICHAR_ID</a> unichar_id, <a class="code" href="a00543.html">ShapeRating</a>* result);
184
<a name="l00084"></a>00084
185
<a name="l00085"></a>00085 <span class="comment">// Provides access to the ShapeTable that this classifier works with.</span>
186
<a name="l00086"></a>00086 <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="a00544.html">ShapeTable</a>* <a class="code" href="a00540.html#ab5e612b18003a7c0ceae685ea1fe8571">GetShapeTable</a>() <span class="keyword">const</span> = 0;
187
<a name="l00087"></a>00087 <span class="comment">// Provides access to the UNICHARSET that this classifier works with.</span>
188
<a name="l00088"></a>00088 <span class="comment">// Must be overridden IFF GetShapeTable() returns NULL.</span>
189
<a name="l00089"></a>00089 <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="a00642.html">UNICHARSET</a>& <a class="code" href="a00540.html#a327269e74451ae730d5ee6795f0ed21a">GetUnicharset</a>() <span class="keyword">const</span>;
190
<a name="l00090"></a>00090
191
<a name="l00091"></a>00091 <span class="comment">// Visual debugger classifies the given sample, displays the results and</span>
192
<a name="l00092"></a>00092 <span class="comment">// solicits user input to display other classifications. Returns when</span>
193
<a name="l00093"></a>00093 <span class="comment">// the user has finished with debugging the sample.</span>
194
<a name="l00094"></a>00094 <span class="comment">// Probably doesn't need to be overridden if the subclass provides</span>
195
<a name="l00095"></a>00095 <span class="comment">// DisplayClassifyAs.</span>
196
<a name="l00096"></a>00096 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00540.html#a9bb8cad25572380e63fc9b51fc2c857c">DebugDisplay</a>(<span class="keyword">const</span> <a class="code" href="a00630.html">TrainingSample</a>& <a class="code" href="a00525.html">sample</a>, Pix* page_pix,
197
<a name="l00097"></a>00097 <a class="code" href="a00862.html#a8578b19fa1ff5ca75080db1a18ecc32e">UNICHAR_ID</a> unichar_id);
198
<a name="l00098"></a>00098
199
<a name="l00099"></a>00099
200
<a name="l00100"></a>00100 <span class="comment">// Displays classification as the given unichar_id. Creates as many windows</span>
201
<a name="l00101"></a>00101 <span class="comment">// as it feels fit, using index as a guide for placement. Adds any created</span>
202
<a name="l00102"></a>00102 <span class="comment">// windows to the windows output and returns a new index that may be used</span>
203
<a name="l00103"></a>00103 <span class="comment">// by any subsequent classifiers. Caller waits for the user to view and</span>
204
<a name="l00104"></a>00104 <span class="comment">// then destroys the windows by clearing the vector.</span>
205
<a name="l00105"></a>00105 <span class="keyword">virtual</span> <span class="keywordtype">int</span> <a class="code" href="a00540.html#a0687b15edcbd8fe3d3d611e1d073c3f4">DisplayClassifyAs</a>(<span class="keyword">const</span> <a class="code" href="a00630.html">TrainingSample</a>& <a class="code" href="a00525.html">sample</a>, Pix* page_pix,
206
<a name="l00106"></a>00106 <a class="code" href="a00862.html#a8578b19fa1ff5ca75080db1a18ecc32e">UNICHAR_ID</a> unichar_id, <span class="keywordtype">int</span> index,
207
<a name="l00107"></a>00107 <a class="code" href="a00504.html">PointerVector<ScrollView></a>* windows);
208
<a name="l00108"></a>00108
209
<a name="l00109"></a>00109 <span class="comment">// Prints debug information on the results. context is some introductory/title</span>
210
<a name="l00110"></a>00110 <span class="comment">// message.</span>
211
<a name="l00111"></a>00111 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00540.html#a1857da78597dd078f51204097c4f3146">UnicharPrintResults</a>(
212
<a name="l00112"></a>00112 <span class="keyword">const</span> <span class="keywordtype">char</span>* context, <span class="keyword">const</span> <a class="code" href="a00403.html">GenericVector<UnicharRating></a>& results) <span class="keyword">const</span>;
213
<a name="l00113"></a>00113 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00540.html#aa91458caf58bc2ff1a4837ae2761fd3a">PrintResults</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* context,
214
<a name="l00114"></a>00114 <span class="keyword">const</span> <a class="code" href="a00403.html">GenericVector<ShapeRating></a>& results) <span class="keyword">const</span>;
215
<a name="l00115"></a>00115
216
<a name="l00116"></a>00116 <span class="keyword">protected</span>:
217
<a name="l00117"></a>00117 <span class="comment">// Removes any result that has all its unichars covered by a better choice,</span>
218
<a name="l00118"></a>00118 <span class="comment">// regardless of font.</span>
219
<a name="l00119"></a>00119 <span class="keywordtype">void</span> <a class="code" href="a00540.html#a3d89d23ffe2b0f04f9360d75243d904e">FilterDuplicateUnichars</a>(<a class="code" href="a00403.html">GenericVector<ShapeRating></a>* results) <span class="keyword">const</span>;
220
<a name="l00120"></a>00120 };
221
<a name="l00121"></a>00121
222
<a name="l00122"></a>00122 } <span class="comment">// namespace tesseract.</span>
223
<a name="l00123"></a>00123
224
<a name="l00124"></a>00124 <span class="preprocessor">#endif // TESSERACT_CLASSIFY_SHAPECLASSIFIER_H_</span>
225
</pre></div></div><!-- contents -->
227
<!-- window showing the filter options -->
228
<div id="MSearchSelectWindow"
229
onmouseover="return searchBox.OnSearchSelectShow()"
230
onmouseout="return searchBox.OnSearchSelectHide()"
231
onkeydown="return searchBox.OnSearchSelectKey(event)">
232
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div>
234
<!-- iframe showing the search results (closed by default) -->
235
<div id="MSearchResultsWindow">
236
<iframe src="javascript:void(0)" frameborder="0"
237
name="MSearchResults" id="MSearchResults">
241
<div id="nav-path" class="navpath">
243
<li class="navelem"><a class="el" href="a00939.html">shapeclassifier.h</a> </li>
245
<li class="footer">Generated on Mon Feb 3 2014 10:59:09 for tesseract by
246
<a href="http://www.doxygen.org/index.html">
247
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>