~ubuntu-branches/ubuntu/vivid/tesseract/vivid

« back to all changes in this revision

Viewing changes to doc/html/a00906_source.html

  • Committer: Package Import Robot
  • Author(s): Jeff Breidenbach
  • Date: 2014-02-03 11:10:20 UTC
  • mfrom: (1.3.1) (19.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140203111020-igquodd7pjlp3uri
Tags: 3.03.01-1
* New upstream release, includes critical fix to PDF rendering
* Complete leptonlib transition (see bug #735509)
* Promote from experimental to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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">
 
3
<head>
 
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/intfx.cpp Source File</title>
 
7
 
 
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);
 
16
</script>
 
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); });
 
21
</script>
 
22
 
 
23
</head>
 
24
<body>
 
25
<div id="top"><!-- do not remove this div! -->
 
26
 
 
27
 
 
28
<div id="titlearea">
 
29
<table cellspacing="0" cellpadding="0">
 
30
 <tbody>
 
31
 <tr style="height: 56px;">
 
32
  
 
33
  
 
34
  <td style="padding-left: 0.5em;">
 
35
   <div id="projectname">tesseract
 
36
   &#160;<span id="projectnumber">3.03</span>
 
37
   </div>
 
38
   
 
39
  </td>
 
40
  
 
41
  
 
42
  
 
43
 </tr>
 
44
 </tbody>
 
45
</table>
 
46
</div>
 
47
 
 
48
<!-- Generated by Doxygen 1.7.6.1 -->
 
49
<script type="text/javascript">
 
50
var searchBox = new SearchBox("searchBox", "search",false,'Search');
 
51
</script>
 
52
  <div id="navrow1" class="tabs">
 
53
    <ul class="tablist">
 
54
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
 
55
      <li><a href="pages.html"><span>Related&#160;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>
 
60
      <li>
 
61
        <div id="MSearchBox" class="MSearchBoxInactive">
 
62
        <span class="left">
 
63
          <img id="MSearchSelect" src="search/mag_sel.png"
 
64
               onmouseover="return searchBox.OnSearchSelectShow()"
 
65
               onmouseout="return searchBox.OnSearchSelectHide()"
 
66
               alt=""/>
 
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>
 
73
          </span>
 
74
        </div>
 
75
      </li>
 
76
    </ul>
 
77
  </div>
 
78
  <div id="navrow2" class="tabs2">
 
79
    <ul class="tablist">
 
80
      <li><a href="files.html"><span>File&#160;List</span></a></li>
 
81
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
 
82
    </ul>
 
83
  </div>
 
84
</div>
 
85
<div id="side-nav" class="ui-resizable side-nav-resizable">
 
86
  <div id="nav-tree">
 
87
    <div id="nav-tree-contents">
 
88
    </div>
 
89
  </div>
 
90
  <div id="splitbar" style="-moz-user-select:none;" 
 
91
       class="ui-resizable-handle">
 
92
  </div>
 
93
</div>
 
94
<script type="text/javascript">
 
95
  initNavTree('a00906.html','');
 
96
</script>
 
97
<div id="doc-content">
 
98
<div class="header">
 
99
  <div class="headertitle">
 
100
<div class="title">/usr/local/google/home/jbreiden/tesseract-ocr-read-only/classify/intfx.cpp</div>  </div>
 
101
</div><!--header-->
 
102
<div class="contents">
 
103
<a href="a00906.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/******************************************************************************</span>
 
104
<a name="l00002"></a>00002 <span class="comment"> **      Filename:    intfx.c</span>
 
105
<a name="l00003"></a>00003 <span class="comment"> **      Purpose:     Integer character normalization &amp; feature extraction</span>
 
106
<a name="l00004"></a>00004 <span class="comment"> **      Author:      Robert Moss, rays@google.com (Ray Smith)</span>
 
107
<a name="l00005"></a>00005 <span class="comment"> **      History:     Tue May 21 15:51:57 MDT 1991, RWM, Created.</span>
 
108
<a name="l00006"></a>00006 <span class="comment"> **                   Tue Feb 28 10:42:00 PST 2012, vastly rewritten to allow</span>
 
109
<a name="l00007"></a>00007 <span class="comment">                                                    greyscale fx and non-linear</span>
 
110
<a name="l00008"></a>00008 <span class="comment">                                                    normalization.</span>
 
111
<a name="l00009"></a>00009 <span class="comment"> **</span>
 
112
<a name="l00010"></a>00010 <span class="comment"> **      (c) Copyright Hewlett-Packard Company, 1988.</span>
 
113
<a name="l00011"></a>00011 <span class="comment"> ** Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
 
114
<a name="l00012"></a>00012 <span class="comment"> ** you may not use this file except in compliance with the License.</span>
 
115
<a name="l00013"></a>00013 <span class="comment"> ** You may obtain a copy of the License at</span>
 
116
<a name="l00014"></a>00014 <span class="comment"> ** http://www.apache.org/licenses/LICENSE-2.0</span>
 
117
<a name="l00015"></a>00015 <span class="comment"> ** Unless required by applicable law or agreed to in writing, software</span>
 
118
<a name="l00016"></a>00016 <span class="comment"> ** distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
 
119
<a name="l00017"></a>00017 <span class="comment"> ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
 
120
<a name="l00018"></a>00018 <span class="comment"> ** See the License for the specific language governing permissions and</span>
 
121
<a name="l00019"></a>00019 <span class="comment"> ** limitations under the License.</span>
 
122
<a name="l00020"></a>00020 <span class="comment"> ******************************************************************************/</span>
 
123
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;<a class="code" href="a00907.html">intfx.h</a>&quot;</span>
 
124
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;allheaders.h&quot;</span>
 
125
<a name="l00026"></a>00026 <span class="preprocessor">#include &quot;<a class="code" href="a00814.html">ccutil.h</a>&quot;</span>
 
126
<a name="l00027"></a>00027 <span class="preprocessor">#include &quot;<a class="code" href="a00878.html">classify.h</a>&quot;</span>
 
127
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="a01026.html">const.h</a>&quot;</span>
 
128
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;<a class="code" href="a00830.html">helpers.h</a>&quot;</span>
 
129
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="a00909.html">intmatcher.h</a>&quot;</span>
 
130
<a name="l00031"></a>00031 <span class="preprocessor">#include &quot;<a class="code" href="a00753.html">linlsq.h</a>&quot;</span>
 
131
<a name="l00032"></a>00032 <span class="preprocessor">#include &quot;<a class="code" href="a00839.html">ndminx.h</a>&quot;</span>
 
132
<a name="l00033"></a>00033 <span class="preprocessor">#include &quot;<a class="code" href="a00759.html">normalis.h</a>&quot;</span>
 
133
<a name="l00034"></a>00034 <span class="preprocessor">#include &quot;<a class="code" href="a00798.html">statistc.h</a>&quot;</span>
 
134
<a name="l00035"></a>00035 <span class="preprocessor">#include &quot;<a class="code" href="a00945.html">trainingsample.h</a>&quot;</span>
 
135
<a name="l00036"></a>00036 
 
136
<a name="l00037"></a>00037 <span class="keyword">using</span> <a class="code" href="a00630.html">tesseract::TrainingSample</a>;
 
137
<a name="l00038"></a>00038 
 
138
<a name="l00042"></a>00042 <span class="comment">// Look up table for cos and sin to turn the intfx feature angle to a vector.</span>
 
139
<a name="l00043"></a>00043 <span class="comment">// Protected by atan_table_mutex.</span>
 
140
<a name="l00044"></a>00044 <span class="comment">// The entries are in binary degrees where a full circle is 256 binary degrees.</span>
 
141
<a name="l00045"></a>00045 <span class="keyword">static</span> <span class="keywordtype">float</span> cos_table[<a class="code" href="a00911.html#a5a763027f420d44c110f0887f297259c">INT_CHAR_NORM_RANGE</a>];
 
142
<a name="l00046"></a>00046 <span class="keyword">static</span> <span class="keywordtype">float</span> sin_table[<a class="code" href="a00911.html#a5a763027f420d44c110f0887f297259c">INT_CHAR_NORM_RANGE</a>];
 
143
<a name="l00047"></a>00047 <span class="comment">// Guards write access to AtanTable so we dont create it more than once.</span>
 
144
<a name="l00048"></a><a class="code" href="a00906.html#ac4a1776ca13b7a287e68b1dcd590a240">00048</a> <a class="code" href="a00296.html">tesseract::CCUtilMutex</a> <a class="code" href="a00906.html#ac4a1776ca13b7a287e68b1dcd590a240">atan_table_mutex</a>;
 
145
<a name="l00049"></a>00049 
 
146
<a name="l00050"></a>00050 
 
147
<a name="l00054"></a>00054 <span class="comment">/*---------------------------------------------------------------------------*/</span>
 
148
<a name="l00055"></a><a class="code" href="a00907.html#a1281b17b87e56c99d53fe6bb1f7c2d55">00055</a> <span class="keywordtype">void</span> <a class="code" href="a00906.html#a1281b17b87e56c99d53fe6bb1f7c2d55">InitIntegerFX</a>() {
 
149
<a name="l00056"></a>00056   <span class="keyword">static</span> <span class="keywordtype">bool</span> atan_table_init = <span class="keyword">false</span>;
 
150
<a name="l00057"></a>00057   atan_table_mutex.<a class="code" href="a00296.html#a9b593dd73dc2510c71739841e37ee17c">Lock</a>();
 
151
<a name="l00058"></a>00058   <span class="keywordflow">if</span> (!atan_table_init) {
 
152
<a name="l00059"></a>00059     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="a00911.html#a5a763027f420d44c110f0887f297259c">INT_CHAR_NORM_RANGE</a>; ++i) {
 
153
<a name="l00060"></a>00060       cos_table[i] = cos(i * 2 * <a class="code" href="a01026.html#a598a3330b3c21701223ee0ca14316eca">PI</a> / INT_CHAR_NORM_RANGE + <a class="code" href="a01026.html#a598a3330b3c21701223ee0ca14316eca">PI</a>);
 
154
<a name="l00061"></a>00061       sin_table[i] = sin(i * 2 * <a class="code" href="a01026.html#a598a3330b3c21701223ee0ca14316eca">PI</a> / INT_CHAR_NORM_RANGE + <a class="code" href="a01026.html#a598a3330b3c21701223ee0ca14316eca">PI</a>);
 
155
<a name="l00062"></a>00062     }
 
156
<a name="l00063"></a>00063     atan_table_init = <span class="keyword">true</span>;
 
157
<a name="l00064"></a>00064   }
 
158
<a name="l00065"></a>00065   atan_table_mutex.<a class="code" href="a00296.html#a0cc750edb4d5b9baca124ebee032c09b">Unlock</a>();
 
159
<a name="l00066"></a>00066 }
 
160
<a name="l00067"></a>00067 
 
161
<a name="l00068"></a>00068 <span class="comment">// Returns a vector representing the direction of a feature with the given</span>
 
162
<a name="l00069"></a>00069 <span class="comment">// theta direction in an INT_FEATURE_STRUCT.</span>
 
163
<a name="l00070"></a><a class="code" href="a00907.html#a31bfe591242811378902d7342621a59b">00070</a> <a class="code" href="a00375.html">FCOORD</a> <a class="code" href="a00906.html#a31bfe591242811378902d7342621a59b">FeatureDirection</a>(<a class="code" href="a00831.html#a458fe97f82495945f8071bb3c18d1783">uinT8</a> theta) {
 
164
<a name="l00071"></a>00071   <span class="keywordflow">return</span> <a class="code" href="a00375.html">FCOORD</a>(cos_table[theta], sin_table[theta]);
 
165
<a name="l00072"></a>00072 }
 
166
<a name="l00073"></a>00073 
 
167
<a name="l00074"></a>00074 <span class="keyword">namespace </span><a class="code" href="a01266.html#afed58feacb84df2de88bdd613cfdba6d">tesseract</a> {
 
168
<a name="l00075"></a>00075 
 
169
<a name="l00076"></a>00076 <span class="comment">// Generates a TrainingSample from a TBLOB. Extracts features and sets</span>
 
170
<a name="l00077"></a>00077 <span class="comment">// the bounding box, so classifiers that operate on the image can work.</span>
 
171
<a name="l00078"></a>00078 <span class="comment">// TODO(rays) BlobToTrainingSample must remain a global function until</span>
 
172
<a name="l00079"></a>00079 <span class="comment">// the FlexFx and FeatureDescription code can be removed and LearnBlob</span>
 
173
<a name="l00080"></a>00080 <span class="comment">// made a member of Classify.</span>
 
174
<a name="l00081"></a><a class="code" href="a01265.html#aec054a83368226096efc7b63c67749b5">00081</a> <a class="code" href="a00630.html">TrainingSample</a>* <a class="code" href="a01265.html#aec054a83368226096efc7b63c67749b5">BlobToTrainingSample</a>(
 
175
<a name="l00082"></a>00082     <span class="keyword">const</span> <a class="code" href="a00591.html">TBLOB</a>&amp; blob, <span class="keywordtype">bool</span> nonlinear_norm, <a class="code" href="a00422.html">INT_FX_RESULT_STRUCT</a>* fx_info,
 
176
<a name="l00083"></a>00083     <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a>* bl_features) {
 
177
<a name="l00084"></a>00084   <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a> cn_features;
 
178
<a name="l00085"></a>00085   <a class="code" href="a00314.html#a2e861cf56ef6e2eb15a0f2a1544e738a">Classify::ExtractFeatures</a>(blob, nonlinear_norm, bl_features,
 
179
<a name="l00086"></a>00086                             &amp;cn_features, fx_info, NULL);
 
180
<a name="l00087"></a>00087   <span class="comment">// TODO(rays) Use blob-&gt;PreciseBoundingBox() instead.</span>
 
181
<a name="l00088"></a>00088   <a class="code" href="a00592.html">TBOX</a> box = blob.<a class="code" href="a00591.html#a8f1f8f110170fe12cf8147d504cd0ea2">bounding_box</a>();
 
182
<a name="l00089"></a>00089   <a class="code" href="a00630.html">TrainingSample</a>* <a class="code" href="a00525.html">sample</a> = NULL;
 
183
<a name="l00090"></a>00090   <span class="keywordtype">int</span> num_features = fx_info-&gt;<a class="code" href="a00422.html#ac2c7a180de0d0778efed530aa06e47ad">NumCN</a>;
 
184
<a name="l00091"></a>00091   <span class="keywordflow">if</span> (num_features &gt; 0) {
 
185
<a name="l00092"></a>00092     sample = <a class="code" href="a00630.html#a019742290eba1aa3c2674366240fc3bd">TrainingSample::CopyFromFeatures</a>(*fx_info, box, &amp;cn_features[0],
 
186
<a name="l00093"></a>00093                                               num_features);
 
187
<a name="l00094"></a>00094   }
 
188
<a name="l00095"></a>00095   <span class="keywordflow">if</span> (sample != NULL) {
 
189
<a name="l00096"></a>00096     <span class="comment">// Set the bounding box (in original image coordinates) in the sample.</span>
 
190
<a name="l00097"></a>00097     <a class="code" href="a00629.html">TPOINT</a> topleft, botright;
 
191
<a name="l00098"></a>00098     topleft.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a> = box.<a class="code" href="a00592.html#a724fabf566586b663577dfa944ffbc61">left</a>();
 
192
<a name="l00099"></a>00099     topleft.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a> = box.<a class="code" href="a00592.html#adf92e9fdac1bdf11c10d1c4d1178791a">top</a>();
 
193
<a name="l00100"></a>00100     botright.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a> = box.<a class="code" href="a00592.html#a8703081c1a1c26db3a4dddaca1028e34">right</a>();
 
194
<a name="l00101"></a>00101     botright.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a> = box.<a class="code" href="a00592.html#a4451d237f1cd18c4982d63fe36a11fc3">bottom</a>();
 
195
<a name="l00102"></a>00102     <a class="code" href="a00629.html">TPOINT</a> original_topleft, original_botright;
 
196
<a name="l00103"></a>00103     blob.<a class="code" href="a00591.html#af626620405a70f8dc400c1cfb95a02f0">denorm</a>().<a class="code" href="a00352.html#afb0790f980cc477b448397e6a9ecd9f8">DenormTransform</a>(NULL, topleft, &amp;original_topleft);
 
197
<a name="l00104"></a>00104     blob.<a class="code" href="a00591.html#af626620405a70f8dc400c1cfb95a02f0">denorm</a>().<a class="code" href="a00352.html#afb0790f980cc477b448397e6a9ecd9f8">DenormTransform</a>(NULL, botright, &amp;original_botright);
 
198
<a name="l00105"></a>00105     sample-&gt;<a class="code" href="a00630.html#ac0c0e309ecce8fdbc6c05cb586587907">set_bounding_box</a>(<a class="code" href="a00592.html">TBOX</a>(original_topleft.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a>, original_botright.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a>,
 
199
<a name="l00106"></a>00106                                   original_botright.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a>, original_topleft.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a>));
 
200
<a name="l00107"></a>00107   }
 
201
<a name="l00108"></a>00108   <span class="keywordflow">return</span> sample;
 
202
<a name="l00109"></a>00109 }
 
203
<a name="l00110"></a>00110 
 
204
<a name="l00111"></a>00111 <span class="comment">// Computes the DENORMS for bl(baseline) and cn(character) normalization</span>
 
205
<a name="l00112"></a>00112 <span class="comment">// during feature extraction. The input denorm describes the current state</span>
 
206
<a name="l00113"></a>00113 <span class="comment">// of the blob, which is usually a baseline-normalized word.</span>
 
207
<a name="l00114"></a>00114 <span class="comment">// The Transforms setup are as follows:</span>
 
208
<a name="l00115"></a>00115 <span class="comment">// Baseline Normalized (bl) Output:</span>
 
209
<a name="l00116"></a>00116 <span class="comment">//   We center the grapheme by aligning the x-coordinate of its centroid with</span>
 
210
<a name="l00117"></a>00117 <span class="comment">//   x=128 and leaving the already-baseline-normalized y as-is.</span>
 
211
<a name="l00118"></a>00118 <span class="comment">//</span>
 
212
<a name="l00119"></a>00119 <span class="comment">// Character Normalized (cn) Output:</span>
 
213
<a name="l00120"></a>00120 <span class="comment">//   We align the grapheme&#39;s centroid at the origin and scale it</span>
 
214
<a name="l00121"></a>00121 <span class="comment">//   asymmetrically in x and y so that the 2nd moments are a standard value</span>
 
215
<a name="l00122"></a>00122 <span class="comment">//   (51.2) ie the result is vaguely square.</span>
 
216
<a name="l00123"></a>00123 <span class="comment">// If classify_nonlinear_norm is true:</span>
 
217
<a name="l00124"></a>00124 <span class="comment">//   A non-linear normalization is setup that attempts to evenly distribute</span>
 
218
<a name="l00125"></a>00125 <span class="comment">//   edges across x and y.</span>
 
219
<a name="l00126"></a>00126 <span class="comment">//</span>
 
220
<a name="l00127"></a>00127 <span class="comment">// Some of the fields of fx_info are also setup:</span>
 
221
<a name="l00128"></a>00128 <span class="comment">// Length: Total length of outline.</span>
 
222
<a name="l00129"></a>00129 <span class="comment">// Rx:     Rounded y second moment. (Reversed by convention.)</span>
 
223
<a name="l00130"></a>00130 <span class="comment">// Ry:     rounded x second moment.</span>
 
224
<a name="l00131"></a>00131 <span class="comment">// Xmean:  Rounded x center of mass of the blob.</span>
 
225
<a name="l00132"></a>00132 <span class="comment">// Ymean:  Rounded y center of mass of the blob.</span>
 
226
<a name="l00133"></a><a class="code" href="a00314.html#a5cfb743c9a90895346549c9ca32c8654">00133</a> <span class="keywordtype">void</span> <a class="code" href="a00314.html#a5cfb743c9a90895346549c9ca32c8654">Classify::SetupBLCNDenorms</a>(<span class="keyword">const</span> <a class="code" href="a00591.html">TBLOB</a>&amp; blob, <span class="keywordtype">bool</span> nonlinear_norm,
 
227
<a name="l00134"></a>00134                                 <a class="code" href="a00352.html">DENORM</a>* bl_denorm, <a class="code" href="a00352.html">DENORM</a>* cn_denorm,
 
228
<a name="l00135"></a>00135                                 <a class="code" href="a00422.html">INT_FX_RESULT_STRUCT</a>* fx_info) {
 
229
<a name="l00136"></a>00136   <span class="comment">// Compute 1st and 2nd moments of the original outline.</span>
 
230
<a name="l00137"></a>00137   <a class="code" href="a00375.html">FCOORD</a> center, second_moments;
 
231
<a name="l00138"></a>00138   <span class="keywordtype">int</span> length = blob.<a class="code" href="a00591.html#af9a956b2f1a871f6343064148b81caba">ComputeMoments</a>(&amp;center, &amp;second_moments);
 
232
<a name="l00139"></a>00139   <span class="keywordflow">if</span> (fx_info != NULL) {
 
233
<a name="l00140"></a>00140     fx_info-&gt;<a class="code" href="a00422.html#afea938630215615240c35afad4e6df0e">Length</a> = length;
 
234
<a name="l00141"></a>00141     fx_info-&gt;<a class="code" href="a00422.html#a761357b2a8e539be5dd5be9ab6427535">Rx</a> = <a class="code" href="a00830.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(second_moments.<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>());
 
235
<a name="l00142"></a>00142     fx_info-&gt;<a class="code" href="a00422.html#a5bc44d7c44209bf894b7c806839cb62d">Ry</a> = <a class="code" href="a00830.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(second_moments.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>());
 
236
<a name="l00143"></a>00143 
 
237
<a name="l00144"></a>00144     fx_info-&gt;<a class="code" href="a00422.html#a4248f47c8d5d20a3849164df3fdcf9bc">Xmean</a> = <a class="code" href="a00830.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(center.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>());
 
238
<a name="l00145"></a>00145     fx_info-&gt;<a class="code" href="a00422.html#a7acb1b39e74035eb698d8ab2ca8f689e">Ymean</a> = <a class="code" href="a00830.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(center.<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>());
 
239
<a name="l00146"></a>00146   }
 
240
<a name="l00147"></a>00147   <span class="comment">// Setup the denorm for Baseline normalization.</span>
 
241
<a name="l00148"></a>00148   bl_denorm-&gt;<a class="code" href="a00352.html#ac94eaa8655afedfbb5f47dee47c7b28c">SetupNormalization</a>(NULL, NULL, &amp;blob.<a class="code" href="a00591.html#af626620405a70f8dc400c1cfb95a02f0">denorm</a>(), center.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>(), 128.0f,
 
242
<a name="l00149"></a>00149                                 1.0f, 1.0f, 128.0f, 128.0f);
 
243
<a name="l00150"></a>00150   <span class="comment">// Setup the denorm for character normalization.</span>
 
244
<a name="l00151"></a>00151   <span class="keywordflow">if</span> (nonlinear_norm) {
 
245
<a name="l00152"></a>00152     <a class="code" href="a00403.html">GenericVector&lt;GenericVector&lt;int&gt;</a> &gt; x_coords;
 
246
<a name="l00153"></a>00153     <a class="code" href="a00403.html">GenericVector&lt;GenericVector&lt;int&gt;</a> &gt; y_coords;
 
247
<a name="l00154"></a>00154     <a class="code" href="a00592.html">TBOX</a> box;
 
248
<a name="l00155"></a>00155     blob.<a class="code" href="a00591.html#a24bfb2484e195f0f7ddf8abfe09b89a5">GetPreciseBoundingBox</a>(&amp;box);
 
249
<a name="l00156"></a>00156     box.<a class="code" href="a00592.html#ad78f4f7e9746def02b0d2e8e8a2b3ceb">pad</a>(1, 1);
 
250
<a name="l00157"></a>00157     blob.<a class="code" href="a00591.html#a349f2832aa98688a9a3d16e25144fae6">GetEdgeCoords</a>(box, &amp;x_coords, &amp;y_coords);
 
251
<a name="l00158"></a>00158     cn_denorm-&gt;<a class="code" href="a00352.html#a2ccfd0a56dbc74d26e569b1c53135cbe">SetupNonLinear</a>(&amp;blob.<a class="code" href="a00591.html#af626620405a70f8dc400c1cfb95a02f0">denorm</a>(), box, <a class="code" href="a00831.html#a05682ca8de174141447ff05a2289a27c">MAX_UINT8</a>, <a class="code" href="a00831.html#a05682ca8de174141447ff05a2289a27c">MAX_UINT8</a>,
 
252
<a name="l00159"></a>00159                               0.0f, 0.0f, x_coords, y_coords);
 
253
<a name="l00160"></a>00160   } <span class="keywordflow">else</span> {
 
254
<a name="l00161"></a>00161     cn_denorm-&gt;<a class="code" href="a00352.html#ac94eaa8655afedfbb5f47dee47c7b28c">SetupNormalization</a>(NULL, NULL, &amp;blob.<a class="code" href="a00591.html#af626620405a70f8dc400c1cfb95a02f0">denorm</a>(),
 
255
<a name="l00162"></a>00162                                   center.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>(), center.<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>(),
 
256
<a name="l00163"></a>00163                                   51.2f / second_moments.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>(),
 
257
<a name="l00164"></a>00164                                   51.2f / second_moments.<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>(),
 
258
<a name="l00165"></a>00165                                   128.0f, 128.0f);
 
259
<a name="l00166"></a>00166   }
 
260
<a name="l00167"></a>00167 }
 
261
<a name="l00168"></a>00168 
 
262
<a name="l00169"></a>00169 <span class="comment">// Helper normalizes the direction, assuming that it is at the given</span>
 
263
<a name="l00170"></a>00170 <span class="comment">// unnormed_pos, using the given denorm, starting at the root_denorm.</span>
 
264
<a name="l00171"></a><a class="code" href="a01265.html#abf01c360f73cc6614bdf2bb9c0728b27">00171</a> <a class="code" href="a00831.html#a458fe97f82495945f8071bb3c18d1783">uinT8</a> <a class="code" href="a01265.html#abf01c360f73cc6614bdf2bb9c0728b27">NormalizeDirection</a>(<a class="code" href="a00831.html#a458fe97f82495945f8071bb3c18d1783">uinT8</a> dir, <span class="keyword">const</span> <a class="code" href="a00375.html">FCOORD</a>&amp; unnormed_pos,
 
265
<a name="l00172"></a>00172                          <span class="keyword">const</span> <a class="code" href="a00352.html">DENORM</a>&amp; denorm, <span class="keyword">const</span> <a class="code" href="a00352.html">DENORM</a>* root_denorm) {
 
266
<a name="l00173"></a>00173   <span class="comment">// Convert direction to a vector.</span>
 
267
<a name="l00174"></a>00174   <a class="code" href="a00375.html">FCOORD</a> unnormed_end;
 
268
<a name="l00175"></a>00175   unnormed_end.<a class="code" href="a00375.html#ad8413eb2fb192a8de469b20a417adf38">from_direction</a>(dir);
 
269
<a name="l00176"></a>00176   unnormed_end += unnormed_pos;
 
270
<a name="l00177"></a>00177   <a class="code" href="a00375.html">FCOORD</a> normed_pos, normed_end;
 
271
<a name="l00178"></a>00178   denorm.<a class="code" href="a00352.html#ae03c30ba35bf10e4f33d9186915c0884">NormTransform</a>(root_denorm, unnormed_pos, &amp;normed_pos);
 
272
<a name="l00179"></a>00179   denorm.<a class="code" href="a00352.html#ae03c30ba35bf10e4f33d9186915c0884">NormTransform</a>(root_denorm, unnormed_end, &amp;normed_end);
 
273
<a name="l00180"></a>00180   normed_end -= normed_pos;
 
274
<a name="l00181"></a>00181   <span class="keywordflow">return</span> normed_end.<a class="code" href="a00375.html#ac4a4eb3596ff292d3b16e40e26f563e5">to_direction</a>();
 
275
<a name="l00182"></a>00182 }
 
276
<a name="l00183"></a>00183 
 
277
<a name="l00184"></a>00184 <span class="comment">// Helper returns the mean direction vector from the given stats. Use the</span>
 
278
<a name="l00185"></a>00185 <span class="comment">// mean direction from dirs if there is information available, otherwise, use</span>
 
279
<a name="l00186"></a>00186 <span class="comment">// the fit_vector from point_diffs.</span>
 
280
<a name="l00187"></a>00187 <span class="keyword">static</span> <a class="code" href="a00375.html">FCOORD</a> MeanDirectionVector(<span class="keyword">const</span> <a class="code" href="a00454.html">LLSQ</a>&amp; point_diffs, <span class="keyword">const</span> <a class="code" href="a00454.html">LLSQ</a>&amp; dirs,
 
281
<a name="l00188"></a>00188                                   <span class="keyword">const</span> <a class="code" href="a00375.html">FCOORD</a>&amp; start_pt,
 
282
<a name="l00189"></a>00189                                   <span class="keyword">const</span> <a class="code" href="a00375.html">FCOORD</a>&amp; end_pt) {
 
283
<a name="l00190"></a>00190   <a class="code" href="a00375.html">FCOORD</a> fit_vector;
 
284
<a name="l00191"></a>00191   <span class="keywordflow">if</span> (dirs.<a class="code" href="a00454.html#ae9282d47723a9741da7fa97cd5fd8025">count</a>() &gt; 0) {
 
285
<a name="l00192"></a>00192     <span class="comment">// There were directions, so use them. To avoid wrap-around problems, we</span>
 
286
<a name="l00193"></a>00193     <span class="comment">// have 2 accumulators in dirs: x for normal directions and y for</span>
 
287
<a name="l00194"></a>00194     <span class="comment">// directions offset by 128. We will use the one with the least variance.</span>
 
288
<a name="l00195"></a>00195     <a class="code" href="a00375.html">FCOORD</a> mean_pt = dirs.<a class="code" href="a00454.html#ac786685f62b271ca20aa719a8a03aa3d">mean_point</a>();
 
289
<a name="l00196"></a>00196     <span class="keywordtype">double</span> mean_dir = 0.0;
 
290
<a name="l00197"></a>00197     <span class="keywordflow">if</span> (dirs.<a class="code" href="a00454.html#a27994b02b1ea16d8e3a6c951c90205dd">x_variance</a>() &lt;= dirs.<a class="code" href="a00454.html#a3e386f3db4343cca32ac4a4f028c6ea4">y_variance</a>()) {
 
291
<a name="l00198"></a>00198       mean_dir = mean_pt.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>();
 
292
<a name="l00199"></a>00199     } <span class="keywordflow">else</span> {
 
293
<a name="l00200"></a>00200       mean_dir = mean_pt.<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>() + 128;
 
294
<a name="l00201"></a>00201     }
 
295
<a name="l00202"></a>00202     fit_vector.<a class="code" href="a00375.html#ad8413eb2fb192a8de469b20a417adf38">from_direction</a>(<a class="code" href="a00830.html#a560c3ba94fe224dd67b10bd4cb5a6886">Modulo</a>(<a class="code" href="a00830.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(mean_dir), 256));
 
296
<a name="l00203"></a>00203   } <span class="keywordflow">else</span> {
 
297
<a name="l00204"></a>00204     <span class="comment">// There were no directions, so we rely on the vector_fit to the points.</span>
 
298
<a name="l00205"></a>00205     <span class="comment">// Since the vector_fit is 180 degrees ambiguous, we align with the</span>
 
299
<a name="l00206"></a>00206     <span class="comment">// supplied feature_dir by making the scalar product non-negative.</span>
 
300
<a name="l00207"></a>00207     <a class="code" href="a00375.html">FCOORD</a> feature_dir(end_pt - start_pt);
 
301
<a name="l00208"></a>00208     fit_vector = point_diffs.<a class="code" href="a00454.html#a1e15590443e86960c79ae5785f850d6d">vector_fit</a>();
 
302
<a name="l00209"></a>00209     <span class="keywordflow">if</span> (fit_vector.<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>() == 0.0f &amp;&amp; fit_vector.<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>() == 0.0f) {
 
303
<a name="l00210"></a>00210       <span class="comment">// There was only a single point. Use feature_dir directly.</span>
 
304
<a name="l00211"></a>00211       fit_vector = feature_dir;
 
305
<a name="l00212"></a>00212     } <span class="keywordflow">else</span> {
 
306
<a name="l00213"></a>00213       <span class="comment">// Sometimes the least mean squares fit is wrong, due to the small sample</span>
 
307
<a name="l00214"></a>00214       <span class="comment">// of points and scaling. Use a 90 degree rotated vector if that matches</span>
 
308
<a name="l00215"></a>00215       <span class="comment">// feature_dir better.</span>
 
309
<a name="l00216"></a>00216       <a class="code" href="a00375.html">FCOORD</a> fit_vector2 = !fit_vector;
 
310
<a name="l00217"></a>00217       <span class="comment">// The fit_vector is 180 degrees ambiguous, so resolve the ambiguity by</span>
 
311
<a name="l00218"></a>00218       <span class="comment">// insisting that the scalar product with the feature_dir should be +ve.</span>
 
312
<a name="l00219"></a>00219       <span class="keywordflow">if</span> (fit_vector % feature_dir &lt; 0.0)
 
313
<a name="l00220"></a>00220         fit_vector = -fit_vector;
 
314
<a name="l00221"></a>00221       <span class="keywordflow">if</span> (fit_vector2 % feature_dir &lt; 0.0)
 
315
<a name="l00222"></a>00222         fit_vector2 = -fit_vector2;
 
316
<a name="l00223"></a>00223       <span class="comment">// Even though fit_vector2 has a higher mean squared error, it might be</span>
 
317
<a name="l00224"></a>00224       <span class="comment">// a better fit, so use it if the dot product with feature_dir is bigger.</span>
 
318
<a name="l00225"></a>00225       <span class="keywordflow">if</span> (fit_vector2 % feature_dir &gt; fit_vector % feature_dir)
 
319
<a name="l00226"></a>00226         fit_vector = fit_vector2;
 
320
<a name="l00227"></a>00227     }
 
321
<a name="l00228"></a>00228   }
 
322
<a name="l00229"></a>00229   <span class="keywordflow">return</span> fit_vector;
 
323
<a name="l00230"></a>00230 }
 
324
<a name="l00231"></a>00231 
 
325
<a name="l00232"></a>00232 <span class="comment">// Helper computes one or more features corresponding to the given points.</span>
 
326
<a name="l00233"></a>00233 <span class="comment">// Emitted features are on the line defined by:</span>
 
327
<a name="l00234"></a>00234 <span class="comment">// start_pt + lambda * (end_pt - start_pt) for scalar lambda.</span>
 
328
<a name="l00235"></a>00235 <span class="comment">// Features are spaced at feature_length intervals.</span>
 
329
<a name="l00236"></a>00236 <span class="keyword">static</span> <span class="keywordtype">int</span> ComputeFeatures(<span class="keyword">const</span> <a class="code" href="a00375.html">FCOORD</a>&amp; start_pt, <span class="keyword">const</span> <a class="code" href="a00375.html">FCOORD</a>&amp; end_pt,
 
330
<a name="l00237"></a>00237                            <span class="keywordtype">double</span> feature_length,
 
331
<a name="l00238"></a>00238                            <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a>* features) {
 
332
<a name="l00239"></a>00239   <a class="code" href="a00375.html">FCOORD</a> feature_vector(end_pt - start_pt);
 
333
<a name="l00240"></a>00240   <span class="keywordflow">if</span> (feature_vector.x() == 0.0f &amp;&amp; feature_vector.y() == 0.0f) <span class="keywordflow">return</span> 0;
 
334
<a name="l00241"></a>00241   <span class="comment">// Compute theta for the feature based on its direction.</span>
 
335
<a name="l00242"></a>00242   <a class="code" href="a00831.html#a458fe97f82495945f8071bb3c18d1783">uinT8</a> theta = feature_vector.to_direction();
 
336
<a name="l00243"></a>00243   <span class="comment">// Compute the number of features and lambda_step.</span>
 
337
<a name="l00244"></a>00244   <span class="keywordtype">double</span> target_length = feature_vector.length();
 
338
<a name="l00245"></a>00245   <span class="keywordtype">int</span> num_features = <a class="code" href="a00830.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(target_length / feature_length);
 
339
<a name="l00246"></a>00246   <span class="keywordflow">if</span> (num_features == 0) <span class="keywordflow">return</span> 0;
 
340
<a name="l00247"></a>00247   <span class="comment">// Divide the length evenly into num_features pieces.</span>
 
341
<a name="l00248"></a>00248   <span class="keywordtype">double</span> lambda_step = 1.0 / num_features;
 
342
<a name="l00249"></a>00249   <span class="keywordtype">double</span> lambda = lambda_step / 2.0;
 
343
<a name="l00250"></a>00250   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> f = 0; f &lt; num_features; ++f, lambda += lambda_step) {
 
344
<a name="l00251"></a>00251     <a class="code" href="a00375.html">FCOORD</a> feature_pt(start_pt);
 
345
<a name="l00252"></a>00252     feature_pt += feature_vector * lambda;
 
346
<a name="l00253"></a>00253     <a class="code" href="a00421.html">INT_FEATURE_STRUCT</a> feature(feature_pt, theta);
 
347
<a name="l00254"></a>00254     features-&gt;<a class="code" href="a00403.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(feature);
 
348
<a name="l00255"></a>00255   }
 
349
<a name="l00256"></a>00256   <span class="keywordflow">return</span> num_features;
 
350
<a name="l00257"></a>00257 }
 
351
<a name="l00258"></a>00258 
 
352
<a name="l00259"></a>00259 <span class="comment">// Gathers outline points and their directions from start_index into dirs by</span>
 
353
<a name="l00260"></a>00260 <span class="comment">// stepping along the outline and normalizing the coordinates until the</span>
 
354
<a name="l00261"></a>00261 <span class="comment">// required feature_length has been collected or end_index is reached.</span>
 
355
<a name="l00262"></a>00262 <span class="comment">// On input pos must point to the position corresponding to start_index and on</span>
 
356
<a name="l00263"></a>00263 <span class="comment">// return pos is updated to the current raw position, and pos_normed is set to</span>
 
357
<a name="l00264"></a>00264 <span class="comment">// the normed version of pos.</span>
 
358
<a name="l00265"></a>00265 <span class="comment">// Since directions wrap-around, they need special treatment to get the mean.</span>
 
359
<a name="l00266"></a>00266 <span class="comment">// Provided the cluster of directions doesn&#39;t straddle the wrap-around point,</span>
 
360
<a name="l00267"></a>00267 <span class="comment">// the simple mean works. If they do, then, unless the directions are wildly</span>
 
361
<a name="l00268"></a>00268 <span class="comment">// varying, the cluster rotated by 180 degrees will not straddle the wrap-</span>
 
362
<a name="l00269"></a>00269 <span class="comment">// around point, so mean(dir + 180 degrees) - 180 degrees will work. Since</span>
 
363
<a name="l00270"></a>00270 <span class="comment">// LLSQ conveniently stores the mean of 2 variables, we use it to store</span>
 
364
<a name="l00271"></a>00271 <span class="comment">// dir and dir+128 (128 is 180 degrees) and then use the resulting mean</span>
 
365
<a name="l00272"></a>00272 <span class="comment">// with the least variance.</span>
 
366
<a name="l00273"></a>00273 <span class="keyword">static</span> <span class="keywordtype">int</span> GatherPoints(<span class="keyword">const</span> <a class="code" href="a00290.html">C_OUTLINE</a>* outline, <span class="keywordtype">double</span> feature_length,
 
367
<a name="l00274"></a>00274                         <span class="keyword">const</span> <a class="code" href="a00352.html">DENORM</a>&amp; denorm, <span class="keyword">const</span> <a class="code" href="a00352.html">DENORM</a>* root_denorm,
 
368
<a name="l00275"></a>00275                         <span class="keywordtype">int</span> start_index, <span class="keywordtype">int</span> end_index,
 
369
<a name="l00276"></a>00276                         <a class="code" href="a00409.html" title="integer coordinate">ICOORD</a>* pos, <a class="code" href="a00375.html">FCOORD</a>* pos_normed,
 
370
<a name="l00277"></a>00277                         <a class="code" href="a00454.html">LLSQ</a>* points, <a class="code" href="a00454.html">LLSQ</a>* dirs) {
 
371
<a name="l00278"></a>00278   <span class="keywordtype">int</span> step_length = outline-&gt;<a class="code" href="a00290.html#afb87d87d3d48e964937b068f55f3ca3a">pathlength</a>();
 
372
<a name="l00279"></a>00279   <a class="code" href="a00409.html" title="integer coordinate">ICOORD</a> step = outline-&gt;<a class="code" href="a00290.html#aea43094f29c8fc05632b449b45b66072">step</a>(start_index % step_length);
 
373
<a name="l00280"></a>00280   <span class="comment">// Prev_normed is the start point of this collection and will be set on the</span>
 
374
<a name="l00281"></a>00281   <span class="comment">// first iteration, and on later iterations used to determine the length</span>
 
375
<a name="l00282"></a>00282   <span class="comment">// that has been collected.</span>
 
376
<a name="l00283"></a>00283   <a class="code" href="a00375.html">FCOORD</a> prev_normed;
 
377
<a name="l00284"></a>00284   points-&gt;<a class="code" href="a00454.html#a9f7b92005193802bc03539a6ae48a27a">clear</a>();
 
378
<a name="l00285"></a>00285   dirs-&gt;<a class="code" href="a00454.html#a9f7b92005193802bc03539a6ae48a27a">clear</a>();
 
379
<a name="l00286"></a>00286   <span class="keywordtype">int</span> num_points = 0;
 
380
<a name="l00287"></a>00287   <span class="keywordtype">int</span> index;
 
381
<a name="l00288"></a>00288   <span class="keywordflow">for</span> (index = start_index; index &lt;= end_index; ++index, *pos += step) {
 
382
<a name="l00289"></a>00289     step = outline-&gt;<a class="code" href="a00290.html#aea43094f29c8fc05632b449b45b66072">step</a>(index % step_length);
 
383
<a name="l00290"></a>00290     <span class="keywordtype">int</span> edge_weight = outline-&gt;<a class="code" href="a00290.html#a83cfe59f946875d73725db32ea3ab654">edge_strength_at_index</a>(index % step_length);
 
384
<a name="l00291"></a>00291     <span class="keywordflow">if</span> (edge_weight == 0) {
 
385
<a name="l00292"></a>00292       <span class="comment">// This point has conflicting gradient and step direction, so ignore it.</span>
 
386
<a name="l00293"></a>00293       <span class="keywordflow">continue</span>;
 
387
<a name="l00294"></a>00294     }
 
388
<a name="l00295"></a>00295     <span class="comment">// Get the sub-pixel precise location and normalize.</span>
 
389
<a name="l00296"></a>00296     <a class="code" href="a00375.html">FCOORD</a> f_pos = outline-&gt;<a class="code" href="a00290.html#a24cb67fffde9453f84f49477fd8e2340">sub_pixel_pos_at_index</a>(*pos, index % step_length);
 
390
<a name="l00297"></a>00297     denorm.<a class="code" href="a00352.html#ae03c30ba35bf10e4f33d9186915c0884">NormTransform</a>(root_denorm, f_pos, pos_normed);
 
391
<a name="l00298"></a>00298     <span class="keywordflow">if</span> (num_points == 0) {
 
392
<a name="l00299"></a>00299       <span class="comment">// The start of this segment.</span>
 
393
<a name="l00300"></a>00300       prev_normed = *pos_normed;
 
394
<a name="l00301"></a>00301     } <span class="keywordflow">else</span> {
 
395
<a name="l00302"></a>00302       <a class="code" href="a00375.html">FCOORD</a> offset = *pos_normed - prev_normed;
 
396
<a name="l00303"></a>00303       <span class="keywordtype">float</span> length = offset.<a class="code" href="a00375.html#a57c525156717d9e0823230eb5b84255d" title="find length">length</a>();
 
397
<a name="l00304"></a>00304       <span class="keywordflow">if</span> (length &gt; feature_length) {
 
398
<a name="l00305"></a>00305         <span class="comment">// We have gone far enough from the start. We will use this point in</span>
 
399
<a name="l00306"></a>00306         <span class="comment">// the next set so return what we have so far.</span>
 
400
<a name="l00307"></a>00307         <span class="keywordflow">return</span> index;
 
401
<a name="l00308"></a>00308       }
 
402
<a name="l00309"></a>00309     }
 
403
<a name="l00310"></a>00310     points-&gt;<a class="code" href="a00454.html#aa439294be0539828cf042f8941125b3c">add</a>(pos_normed-&gt;<a class="code" href="a00375.html#a9edadbfc357c730f62fa3c92677b0d58">x</a>(), pos_normed-&gt;<a class="code" href="a00375.html#a397f7ce997b246df18e7bd5a20cc422e">y</a>(), edge_weight);
 
404
<a name="l00311"></a>00311     <span class="keywordtype">int</span> <a class="code" href="a00801.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a> = outline-&gt;<a class="code" href="a00290.html#a078ccf813b6e40841ba27109f882f8bc">direction_at_index</a>(index % step_length);
 
405
<a name="l00312"></a>00312     <span class="keywordflow">if</span> (direction &gt;= 0) {
 
406
<a name="l00313"></a>00313       direction = <a class="code" href="a01265.html#abf01c360f73cc6614bdf2bb9c0728b27">NormalizeDirection</a>(direction, f_pos, denorm, root_denorm);
 
407
<a name="l00314"></a>00314       <span class="comment">// Use both the direction and direction +128 so we are not trying to</span>
 
408
<a name="l00315"></a>00315       <span class="comment">// take the mean of something straddling the wrap-around point.</span>
 
409
<a name="l00316"></a>00316       dirs-&gt;<a class="code" href="a00454.html#aa439294be0539828cf042f8941125b3c">add</a>(direction, <a class="code" href="a00830.html#a560c3ba94fe224dd67b10bd4cb5a6886">Modulo</a>(direction + 128, 256));
 
410
<a name="l00317"></a>00317     }
 
411
<a name="l00318"></a>00318     ++num_points;
 
412
<a name="l00319"></a>00319   }
 
413
<a name="l00320"></a>00320   <span class="keywordflow">return</span> index;
 
414
<a name="l00321"></a>00321 }
 
415
<a name="l00322"></a>00322 
 
416
<a name="l00323"></a>00323 <span class="comment">// Extracts Tesseract features and appends them to the features vector.</span>
 
417
<a name="l00324"></a>00324 <span class="comment">// Startpt to lastpt, inclusive, MUST have the same src_outline member,</span>
 
418
<a name="l00325"></a>00325 <span class="comment">// which may be NULL. The vector from lastpt to its next is included in</span>
 
419
<a name="l00326"></a>00326 <span class="comment">// the feature extraction. Hidden edges should be excluded by the caller.</span>
 
420
<a name="l00327"></a>00327 <span class="comment">// If force_poly is true, the features will be extracted from the polygonal</span>
 
421
<a name="l00328"></a>00328 <span class="comment">// approximation even if more accurate data is available.</span>
 
422
<a name="l00329"></a>00329 <span class="keyword">static</span> <span class="keywordtype">void</span> ExtractFeaturesFromRun(
 
423
<a name="l00330"></a>00330     <span class="keyword">const</span> <a class="code" href="a00362.html">EDGEPT</a>* startpt, <span class="keyword">const</span> <a class="code" href="a00362.html">EDGEPT</a>* lastpt,
 
424
<a name="l00331"></a>00331     <span class="keyword">const</span> <a class="code" href="a00352.html">DENORM</a>&amp; denorm, <span class="keywordtype">double</span> feature_length, <span class="keywordtype">bool</span> force_poly,
 
425
<a name="l00332"></a>00332     <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a>* features) {
 
426
<a name="l00333"></a>00333   <span class="keyword">const</span> <a class="code" href="a00362.html">EDGEPT</a>* endpt = lastpt-&gt;<a class="code" href="a00362.html#a196f7786194752f89e364a586d24884d">next</a>;
 
427
<a name="l00334"></a>00334   <span class="keyword">const</span> <a class="code" href="a00290.html">C_OUTLINE</a>* outline = startpt-&gt;<a class="code" href="a00362.html#a6c94887c0e59312611b9cbc9edf9d5fb">src_outline</a>;
 
428
<a name="l00335"></a>00335   <span class="keywordflow">if</span> (outline != NULL &amp;&amp; !force_poly) {
 
429
<a name="l00336"></a>00336     <span class="comment">// Detailed information is available. We have to normalize only from</span>
 
430
<a name="l00337"></a>00337     <span class="comment">// the root_denorm to denorm.</span>
 
431
<a name="l00338"></a>00338     <span class="keyword">const</span> <a class="code" href="a00352.html">DENORM</a>* root_denorm = denorm.<a class="code" href="a00352.html#a66d126c02ce733c7570a9e21c7ad7c4d">RootDenorm</a>();
 
432
<a name="l00339"></a>00339     <span class="keywordtype">int</span> total_features = 0;
 
433
<a name="l00340"></a>00340     <span class="comment">// Get the features from the outline.</span>
 
434
<a name="l00341"></a>00341     <span class="keywordtype">int</span> step_length = outline-&gt;<a class="code" href="a00290.html#afb87d87d3d48e964937b068f55f3ca3a">pathlength</a>();
 
435
<a name="l00342"></a>00342     <span class="keywordtype">int</span> start_index = startpt-&gt;<a class="code" href="a00362.html#a0c73291ef68cb65a10f973ff98a10424">start_step</a>;
 
436
<a name="l00343"></a>00343     <span class="comment">// pos is the integer coordinates of the binary image steps.</span>
 
437
<a name="l00344"></a>00344     <a class="code" href="a00409.html" title="integer coordinate">ICOORD</a> pos = outline-&gt;<a class="code" href="a00290.html#a5e3d80aede6a5701d07bfe42213fc783">position_at_index</a>(start_index);
 
438
<a name="l00345"></a>00345     <span class="comment">// We use an end_index that allows us to use a positive increment, but that</span>
 
439
<a name="l00346"></a>00346     <span class="comment">// may be beyond the bounds of the outline steps/ due to wrap-around, to</span>
 
440
<a name="l00347"></a>00347     <span class="comment">// so we use % step_length everywhere, except for start_index.</span>
 
441
<a name="l00348"></a>00348     <span class="keywordtype">int</span> end_index = lastpt-&gt;<a class="code" href="a00362.html#a0c73291ef68cb65a10f973ff98a10424">start_step</a> + lastpt-&gt;<a class="code" href="a00362.html#a34a59945d65b7db4f0f8aa11a3cfe8c0">step_count</a>;
 
442
<a name="l00349"></a>00349     <span class="keywordflow">if</span> (end_index &lt;= start_index)
 
443
<a name="l00350"></a>00350       end_index += step_length;
 
444
<a name="l00351"></a>00351     <a class="code" href="a00454.html">LLSQ</a> prev_points;
 
445
<a name="l00352"></a>00352     <a class="code" href="a00454.html">LLSQ</a> prev_dirs;
 
446
<a name="l00353"></a>00353     <a class="code" href="a00375.html">FCOORD</a> prev_normed_pos = outline-&gt;<a class="code" href="a00290.html#a24cb67fffde9453f84f49477fd8e2340">sub_pixel_pos_at_index</a>(pos, start_index);
 
447
<a name="l00354"></a>00354     denorm.<a class="code" href="a00352.html#ae03c30ba35bf10e4f33d9186915c0884">NormTransform</a>(root_denorm, prev_normed_pos, &amp;prev_normed_pos);
 
448
<a name="l00355"></a>00355     <a class="code" href="a00454.html">LLSQ</a> points;
 
449
<a name="l00356"></a>00356     <a class="code" href="a00454.html">LLSQ</a> dirs;
 
450
<a name="l00357"></a>00357     <a class="code" href="a00375.html">FCOORD</a> normed_pos;
 
451
<a name="l00358"></a>00358     <span class="keywordtype">int</span> index = GatherPoints(outline, feature_length, denorm, root_denorm,
 
452
<a name="l00359"></a>00359                              start_index, end_index, &amp;pos, &amp;normed_pos,
 
453
<a name="l00360"></a>00360                              &amp;points, &amp;dirs);
 
454
<a name="l00361"></a>00361     <span class="keywordflow">while</span> (index &lt;= end_index) {
 
455
<a name="l00362"></a>00362       <span class="comment">// At each iteration we nominally have 3 accumulated sets of points and</span>
 
456
<a name="l00363"></a>00363       <span class="comment">// dirs: prev_points/dirs, points/dirs, next_points/dirs and sum them</span>
 
457
<a name="l00364"></a>00364       <span class="comment">// into sum_points/dirs, but we don&#39;t necessarily get any features out,</span>
 
458
<a name="l00365"></a>00365       <span class="comment">// so if that is the case, we keep accumulating instead of rotating the</span>
 
459
<a name="l00366"></a>00366       <span class="comment">// accumulators.</span>
 
460
<a name="l00367"></a>00367       <a class="code" href="a00454.html">LLSQ</a> next_points;
 
461
<a name="l00368"></a>00368       <a class="code" href="a00454.html">LLSQ</a> next_dirs;
 
462
<a name="l00369"></a>00369       <a class="code" href="a00375.html">FCOORD</a> next_normed_pos;
 
463
<a name="l00370"></a>00370       index = GatherPoints(outline, feature_length, denorm, root_denorm,
 
464
<a name="l00371"></a>00371                            index, end_index, &amp;pos, &amp;next_normed_pos,
 
465
<a name="l00372"></a>00372                            &amp;next_points, &amp;next_dirs);
 
466
<a name="l00373"></a>00373       <a class="code" href="a00454.html">LLSQ</a> sum_points(prev_points);
 
467
<a name="l00374"></a>00374       <span class="comment">// TODO(rays) find out why it is better to use just dirs and next_dirs</span>
 
468
<a name="l00375"></a>00375       <span class="comment">// in sum_dirs, instead of using prev_dirs as well.</span>
 
469
<a name="l00376"></a>00376       <a class="code" href="a00454.html">LLSQ</a> sum_dirs(dirs);
 
470
<a name="l00377"></a>00377       sum_points.add(points);
 
471
<a name="l00378"></a>00378       sum_points.add(next_points);
 
472
<a name="l00379"></a>00379       sum_dirs.add(next_dirs);
 
473
<a name="l00380"></a>00380       <span class="keywordtype">bool</span> made_features = <span class="keyword">false</span>;
 
474
<a name="l00381"></a>00381       <span class="comment">// If we have some points, we can try making some features.</span>
 
475
<a name="l00382"></a>00382       <span class="keywordflow">if</span> (sum_points.count() &gt; 0) {
 
476
<a name="l00383"></a>00383         <span class="comment">// We have gone far enough from the start. Make a feature and restart.</span>
 
477
<a name="l00384"></a>00384         <a class="code" href="a00375.html">FCOORD</a> fit_pt = sum_points.mean_point();
 
478
<a name="l00385"></a>00385         <a class="code" href="a00375.html">FCOORD</a> fit_vector = MeanDirectionVector(sum_points, sum_dirs,
 
479
<a name="l00386"></a>00386                                                 prev_normed_pos, normed_pos);
 
480
<a name="l00387"></a>00387         <span class="comment">// The segment to which we fit features is the line passing through</span>
 
481
<a name="l00388"></a>00388         <span class="comment">// fit_pt in direction of fit_vector that starts nearest to</span>
 
482
<a name="l00389"></a>00389         <span class="comment">// prev_normed_pos and ends nearest to normed_pos.</span>
 
483
<a name="l00390"></a>00390         <a class="code" href="a00375.html">FCOORD</a> start_pos = prev_normed_pos.<a class="code" href="a00375.html#a6c7437f5231e6b168b47467e801df4d4">nearest_pt_on_line</a>(fit_pt,
 
484
<a name="l00391"></a>00391                                                               fit_vector);
 
485
<a name="l00392"></a>00392         <a class="code" href="a00375.html">FCOORD</a> end_pos = normed_pos.<a class="code" href="a00375.html#a6c7437f5231e6b168b47467e801df4d4">nearest_pt_on_line</a>(fit_pt, fit_vector);
 
486
<a name="l00393"></a>00393         <span class="comment">// Possible correction to match the adjacent polygon segment.</span>
 
487
<a name="l00394"></a>00394         <span class="keywordflow">if</span> (total_features == 0 &amp;&amp; startpt != endpt) {
 
488
<a name="l00395"></a>00395           <a class="code" href="a00375.html">FCOORD</a> poly_pos(startpt-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a>, startpt-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a>);
 
489
<a name="l00396"></a>00396           denorm.<a class="code" href="a00352.html#a379321502d4634137436539518311b9d">LocalNormTransform</a>(poly_pos, &amp;start_pos);
 
490
<a name="l00397"></a>00397         }
 
491
<a name="l00398"></a>00398         <span class="keywordflow">if</span> (index &gt; end_index &amp;&amp; startpt != endpt) {
 
492
<a name="l00399"></a>00399           <a class="code" href="a00375.html">FCOORD</a> poly_pos(endpt-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a>, endpt-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a>);
 
493
<a name="l00400"></a>00400           denorm.<a class="code" href="a00352.html#a379321502d4634137436539518311b9d">LocalNormTransform</a>(poly_pos, &amp;end_pos);
 
494
<a name="l00401"></a>00401         }
 
495
<a name="l00402"></a>00402         <span class="keywordtype">int</span> num_features = ComputeFeatures(start_pos, end_pos, feature_length,
 
496
<a name="l00403"></a>00403                                            features);
 
497
<a name="l00404"></a>00404         <span class="keywordflow">if</span> (num_features &gt; 0) {
 
498
<a name="l00405"></a>00405           <span class="comment">// We made some features so shuffle the accumulators.</span>
 
499
<a name="l00406"></a>00406           prev_points = points;
 
500
<a name="l00407"></a>00407           prev_dirs = dirs;
 
501
<a name="l00408"></a>00408           prev_normed_pos = normed_pos;
 
502
<a name="l00409"></a>00409           points = next_points;
 
503
<a name="l00410"></a>00410           dirs = next_dirs;
 
504
<a name="l00411"></a>00411           made_features = <span class="keyword">true</span>;
 
505
<a name="l00412"></a>00412           total_features += num_features;
 
506
<a name="l00413"></a>00413         }
 
507
<a name="l00414"></a>00414         <span class="comment">// The end of the next set becomes the end next time around.</span>
 
508
<a name="l00415"></a>00415         normed_pos = next_normed_pos;
 
509
<a name="l00416"></a>00416       }
 
510
<a name="l00417"></a>00417       <span class="keywordflow">if</span> (!made_features) {
 
511
<a name="l00418"></a>00418         <span class="comment">// We didn&#39;t make any features, so keep the prev accumulators and</span>
 
512
<a name="l00419"></a>00419         <span class="comment">// add the next ones into the current.</span>
 
513
<a name="l00420"></a>00420         points.<a class="code" href="a00454.html#aa439294be0539828cf042f8941125b3c">add</a>(next_points);
 
514
<a name="l00421"></a>00421         dirs.<a class="code" href="a00454.html#aa439294be0539828cf042f8941125b3c">add</a>(next_dirs);
 
515
<a name="l00422"></a>00422       }
 
516
<a name="l00423"></a>00423     }
 
517
<a name="l00424"></a>00424   } <span class="keywordflow">else</span> {
 
518
<a name="l00425"></a>00425     <span class="comment">// There is no outline, so we are forced to use the polygonal approximation.</span>
 
519
<a name="l00426"></a>00426     <span class="keyword">const</span> <a class="code" href="a00362.html">EDGEPT</a>* pt = startpt;
 
520
<a name="l00427"></a>00427     <span class="keywordflow">do</span> {
 
521
<a name="l00428"></a>00428       <a class="code" href="a00375.html">FCOORD</a> start_pos(pt-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a>, pt-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a>);
 
522
<a name="l00429"></a>00429       <a class="code" href="a00375.html">FCOORD</a> end_pos(pt-&gt;<a class="code" href="a00362.html#a196f7786194752f89e364a586d24884d">next</a>-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#aa9c98655c3a2a0437821e5a3d3418b0f">x</a>, pt-&gt;<a class="code" href="a00362.html#a196f7786194752f89e364a586d24884d">next</a>-&gt;<a class="code" href="a00362.html#adee462d390e637a8393ba373c8d2a1bb">pos</a>.<a class="code" href="a00629.html#a6d62f015b74612e43975e439a096039c">y</a>);
 
523
<a name="l00430"></a>00430       denorm.<a class="code" href="a00352.html#a379321502d4634137436539518311b9d">LocalNormTransform</a>(start_pos, &amp;start_pos);
 
524
<a name="l00431"></a>00431       denorm.<a class="code" href="a00352.html#a379321502d4634137436539518311b9d">LocalNormTransform</a>(end_pos, &amp;end_pos);
 
525
<a name="l00432"></a>00432       ComputeFeatures(start_pos, end_pos, feature_length, features);
 
526
<a name="l00433"></a>00433     } <span class="keywordflow">while</span> ((pt = pt-&gt;<a class="code" href="a00362.html#a196f7786194752f89e364a586d24884d">next</a>) != endpt);
 
527
<a name="l00434"></a>00434   }
 
528
<a name="l00435"></a>00435 }
 
529
<a name="l00436"></a>00436 
 
530
<a name="l00437"></a>00437 <span class="comment">// Extracts sets of 3-D features of length kStandardFeatureLength (=12.8), as</span>
 
531
<a name="l00438"></a>00438 <span class="comment">// (x,y) position and angle as measured counterclockwise from the vector</span>
 
532
<a name="l00439"></a>00439 <span class="comment">// &lt;-1, 0&gt;, from blob using two normalizations defined by bl_denorm and</span>
 
533
<a name="l00440"></a>00440 <span class="comment">// cn_denorm. See SetpuBLCNDenorms for definitions.</span>
 
534
<a name="l00441"></a>00441 <span class="comment">// If outline_cn_counts is not NULL, on return it contains the cumulative</span>
 
535
<a name="l00442"></a>00442 <span class="comment">// number of cn features generated for each outline in the blob (in order).</span>
 
536
<a name="l00443"></a>00443 <span class="comment">// Thus after the first outline, there were (*outline_cn_counts)[0] features,</span>
 
537
<a name="l00444"></a>00444 <span class="comment">// after the second outline, there were (*outline_cn_counts)[1] features etc.</span>
 
538
<a name="l00445"></a><a class="code" href="a00314.html#a2e861cf56ef6e2eb15a0f2a1544e738a">00445</a> <span class="keywordtype">void</span> <a class="code" href="a00314.html#a2e861cf56ef6e2eb15a0f2a1544e738a">Classify::ExtractFeatures</a>(<span class="keyword">const</span> <a class="code" href="a00591.html">TBLOB</a>&amp; blob,
 
539
<a name="l00446"></a>00446                                <span class="keywordtype">bool</span> nonlinear_norm,
 
540
<a name="l00447"></a>00447                                <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a>* bl_features,
 
541
<a name="l00448"></a>00448                                <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a>* cn_features,
 
542
<a name="l00449"></a>00449                                <a class="code" href="a00422.html">INT_FX_RESULT_STRUCT</a>* results,
 
543
<a name="l00450"></a>00450                                <a class="code" href="a00403.html">GenericVector&lt;int&gt;</a>* outline_cn_counts) {
 
544
<a name="l00451"></a>00451   <a class="code" href="a00352.html">DENORM</a> bl_denorm, cn_denorm;
 
545
<a name="l00452"></a>00452   <a class="code" href="a00314.html#a5cfb743c9a90895346549c9ca32c8654">tesseract::Classify::SetupBLCNDenorms</a>(blob, nonlinear_norm,
 
546
<a name="l00453"></a>00453                                         &amp;bl_denorm, &amp;cn_denorm, results);
 
547
<a name="l00454"></a>00454   <span class="keywordflow">if</span> (outline_cn_counts != NULL)
 
548
<a name="l00455"></a>00455     outline_cn_counts-&gt;<a class="code" href="a00403.html#a980882b5ebc3e72fdedbdbe345196f21">truncate</a>(0);
 
549
<a name="l00456"></a>00456   <span class="comment">// Iterate the outlines.</span>
 
550
<a name="l00457"></a>00457   <span class="keywordflow">for</span> (<a class="code" href="a00613.html">TESSLINE</a>* ol = blob.<a class="code" href="a00591.html#a3c9282cad4102157d214bcc6311cda07">outlines</a>; ol != NULL; ol = ol-&gt;<a class="code" href="a00613.html#a0fb224d43ea53a791f0957fa92793bef">next</a>) {
 
551
<a name="l00458"></a>00458     <span class="comment">// Iterate the polygon.</span>
 
552
<a name="l00459"></a>00459     <a class="code" href="a00362.html">EDGEPT</a>* loop_pt = ol-&gt;FindBestStartPt();
 
553
<a name="l00460"></a>00460     <a class="code" href="a00362.html">EDGEPT</a>* pt = loop_pt;
 
554
<a name="l00461"></a>00461     <span class="keywordflow">if</span> (pt == NULL) <span class="keywordflow">continue</span>;
 
555
<a name="l00462"></a>00462     <span class="keywordflow">do</span> {
 
556
<a name="l00463"></a>00463       <span class="keywordflow">if</span> (pt-&gt;<a class="code" href="a00362.html#a7e6e4c9b9bcc3b1e66ab62bb7641c39a">IsHidden</a>()) <span class="keywordflow">continue</span>;
 
557
<a name="l00464"></a>00464       <span class="comment">// Find a run of equal src_outline.</span>
 
558
<a name="l00465"></a>00465       <a class="code" href="a00362.html">EDGEPT</a>* last_pt = pt;
 
559
<a name="l00466"></a>00466       <span class="keywordflow">do</span> {
 
560
<a name="l00467"></a>00467         last_pt = last_pt-&gt;<a class="code" href="a00362.html#a196f7786194752f89e364a586d24884d">next</a>;
 
561
<a name="l00468"></a>00468       } <span class="keywordflow">while</span> (last_pt != loop_pt &amp;&amp; !last_pt-&gt;<a class="code" href="a00362.html#a7e6e4c9b9bcc3b1e66ab62bb7641c39a">IsHidden</a>() &amp;&amp;
 
562
<a name="l00469"></a>00469                last_pt-&gt;<a class="code" href="a00362.html#a6c94887c0e59312611b9cbc9edf9d5fb">src_outline</a> == pt-&gt;<a class="code" href="a00362.html#a6c94887c0e59312611b9cbc9edf9d5fb">src_outline</a>);
 
563
<a name="l00470"></a>00470       last_pt = last_pt-&gt;<a class="code" href="a00362.html#a8326da8daf597bcdc5a05064a37cbbb1">prev</a>;
 
564
<a name="l00471"></a>00471       <span class="comment">// Until the adaptive classifier can be weaned off polygon segments,</span>
 
565
<a name="l00472"></a>00472       <span class="comment">// we have to force extraction from the polygon for the bl_features.</span>
 
566
<a name="l00473"></a>00473       ExtractFeaturesFromRun(pt, last_pt, bl_denorm, <a class="code" href="a00907.html#a93b4cb1304560729fb942b6de45f12f7">kStandardFeatureLength</a>,
 
567
<a name="l00474"></a>00474                              <span class="keyword">true</span>, bl_features);
 
568
<a name="l00475"></a>00475       ExtractFeaturesFromRun(pt, last_pt, cn_denorm, <a class="code" href="a00907.html#a93b4cb1304560729fb942b6de45f12f7">kStandardFeatureLength</a>,
 
569
<a name="l00476"></a>00476                              <span class="keyword">false</span>, cn_features);
 
570
<a name="l00477"></a>00477       pt = last_pt;
 
571
<a name="l00478"></a>00478     } <span class="keywordflow">while</span> ((pt = pt-&gt;<a class="code" href="a00362.html#a196f7786194752f89e364a586d24884d">next</a>) != loop_pt);
 
572
<a name="l00479"></a>00479     <span class="keywordflow">if</span> (outline_cn_counts != NULL)
 
573
<a name="l00480"></a>00480       outline_cn_counts-&gt;<a class="code" href="a00403.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(cn_features-&gt;<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>());
 
574
<a name="l00481"></a>00481   }
 
575
<a name="l00482"></a>00482   results-&gt;<a class="code" href="a00422.html#a1ad9961af805ce0f4d6f8f4c5e60d368">NumBL</a> = bl_features-&gt;<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>();
 
576
<a name="l00483"></a>00483   results-&gt;<a class="code" href="a00422.html#ac2c7a180de0d0778efed530aa06e47ad">NumCN</a> = cn_features-&gt;<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>();
 
577
<a name="l00484"></a>00484   results-&gt;<a class="code" href="a00422.html#af340efbaccbb3e9040e9ff940e7655c9">YBottom</a> = blob.<a class="code" href="a00591.html#a8f1f8f110170fe12cf8147d504cd0ea2">bounding_box</a>().<a class="code" href="a00592.html#a4451d237f1cd18c4982d63fe36a11fc3">bottom</a>();
 
578
<a name="l00485"></a>00485   results-&gt;<a class="code" href="a00422.html#a5ea3a43ce4f2e9f1e87e64b74a0eb6db">YTop</a> = blob.<a class="code" href="a00591.html#a8f1f8f110170fe12cf8147d504cd0ea2">bounding_box</a>().<a class="code" href="a00592.html#adf92e9fdac1bdf11c10d1c4d1178791a">top</a>();
 
579
<a name="l00486"></a>00486   results-&gt;<a class="code" href="a00422.html#a2028a95c91e8741203cca5bea174b2a2">Width</a> = blob.<a class="code" href="a00591.html#a8f1f8f110170fe12cf8147d504cd0ea2">bounding_box</a>().<a class="code" href="a00592.html#af95494a2ccacc70cc2b83820b2948619">width</a>();
 
580
<a name="l00487"></a>00487 }
 
581
<a name="l00488"></a>00488 
 
582
<a name="l00489"></a>00489 }  <span class="comment">// namespace tesseract</span>
 
583
<a name="l00490"></a>00490 
 
584
<a name="l00491"></a>00491 
 
585
<a name="l00492"></a>00492 <span class="comment">/*--------------------------------------------------------------------------*/</span>
 
586
<a name="l00493"></a>00493 <span class="comment">// Extract a set of standard-sized features from Blobs and write them out in</span>
 
587
<a name="l00494"></a>00494 <span class="comment">// two formats: baseline normalized and character normalized.</span>
 
588
<a name="l00495"></a>00495 <span class="comment">//</span>
 
589
<a name="l00496"></a>00496 <span class="comment">// We presume the Blobs are already scaled so that x-height=128 units</span>
 
590
<a name="l00497"></a>00497 <span class="comment">//</span>
 
591
<a name="l00498"></a>00498 <span class="comment">// Standard Features:</span>
 
592
<a name="l00499"></a>00499 <span class="comment">//   We take all outline segments longer than 7 units and chop them into</span>
 
593
<a name="l00500"></a>00500 <span class="comment">//   standard-sized segments of approximately 13 = (64 / 5) units.</span>
 
594
<a name="l00501"></a>00501 <span class="comment">//   When writing these features out, we output their center and angle as</span>
 
595
<a name="l00502"></a>00502 <span class="comment">//   measured counterclockwise from the vector &lt;-1, 0&gt;</span>
 
596
<a name="l00503"></a>00503 <span class="comment">//</span>
 
597
<a name="l00504"></a>00504 <span class="comment">// Baseline Normalized Output:</span>
 
598
<a name="l00505"></a>00505 <span class="comment">//   We center the grapheme by aligning the x-coordinate of its centroid with</span>
 
599
<a name="l00506"></a>00506 <span class="comment">//   x=0 and subtracting 128 from the y-coordinate.</span>
 
600
<a name="l00507"></a>00507 <span class="comment">//</span>
 
601
<a name="l00508"></a>00508 <span class="comment">// Character Normalized Output:</span>
 
602
<a name="l00509"></a>00509 <span class="comment">//   We align the grapheme&#39;s centroid at the origin and scale it asymmetrically</span>
 
603
<a name="l00510"></a>00510 <span class="comment">//   in x and y so that the result is vaguely square.</span>
 
604
<a name="l00511"></a>00511 <span class="comment">//</span>
 
605
<a name="l00512"></a>00512 <span class="comment">// Deprecated! Prefer tesseract::Classify::ExtractFeatures instead.</span>
 
606
<a name="l00513"></a><a class="code" href="a00907.html#af18569f7217d37511e3900a20d803149">00513</a> <span class="keywordtype">bool</span> <a class="code" href="a00906.html#a208ebfc9989e1837d334418d3b93bb5f">ExtractIntFeat</a>(<span class="keyword">const</span> <a class="code" href="a00591.html">TBLOB</a>&amp; blob,
 
607
<a name="l00514"></a>00514                     <span class="keywordtype">bool</span> nonlinear_norm,
 
608
<a name="l00515"></a>00515                     <a class="code" href="a00911.html#a544a6c7d78d215e9a4da202daecfeb52">INT_FEATURE_ARRAY</a> baseline_features,
 
609
<a name="l00516"></a>00516                     <a class="code" href="a00911.html#a544a6c7d78d215e9a4da202daecfeb52">INT_FEATURE_ARRAY</a> charnorm_features,
 
610
<a name="l00517"></a>00517                     <a class="code" href="a00422.html">INT_FX_RESULT_STRUCT</a>* results) {
 
611
<a name="l00518"></a>00518   <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a> bl_features;
 
612
<a name="l00519"></a>00519   <a class="code" href="a00403.html">GenericVector&lt;INT_FEATURE_STRUCT&gt;</a> cn_features;
 
613
<a name="l00520"></a>00520   <a class="code" href="a00314.html#a2e861cf56ef6e2eb15a0f2a1544e738a">tesseract::Classify::ExtractFeatures</a>(blob, nonlinear_norm,
 
614
<a name="l00521"></a>00521                                        &amp;bl_features, &amp;cn_features, results,
 
615
<a name="l00522"></a>00522                                        NULL);
 
616
<a name="l00523"></a>00523   <span class="keywordflow">if</span> (bl_features.<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>() == 0 || cn_features.<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>() == 0 ||
 
617
<a name="l00524"></a>00524       bl_features.<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>() &gt; <a class="code" href="a00911.html#a4f7caedc4bed99355cae19efa51ade51">MAX_NUM_INT_FEATURES</a> ||
 
618
<a name="l00525"></a>00525       cn_features.<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>() &gt; <a class="code" href="a00911.html#a4f7caedc4bed99355cae19efa51ade51">MAX_NUM_INT_FEATURES</a>) {
 
619
<a name="l00526"></a>00526     <span class="keywordflow">return</span> <span class="keyword">false</span>;  <span class="comment">// Feature extraction failed.</span>
 
620
<a name="l00527"></a>00527   }
 
621
<a name="l00528"></a>00528   memcpy(baseline_features, &amp;bl_features[0],
 
622
<a name="l00529"></a>00529          bl_features.<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>() * <span class="keyword">sizeof</span>(bl_features[0]));
 
623
<a name="l00530"></a>00530   memcpy(charnorm_features, &amp;cn_features[0],
 
624
<a name="l00531"></a>00531          cn_features.<a class="code" href="a00403.html#a111b51dd0bf1324cfb69ef70703d8e70">size</a>() * <span class="keyword">sizeof</span>(cn_features[0]));
 
625
<a name="l00532"></a>00532   <span class="keywordflow">return</span> <span class="keyword">true</span>;
 
626
<a name="l00533"></a>00533 }
 
627
</pre></div></div><!-- contents -->
 
628
</div>
 
629
<!-- window showing the filter options -->
 
630
<div id="MSearchSelectWindow"
 
631
     onmouseover="return searchBox.OnSearchSelectShow()"
 
632
     onmouseout="return searchBox.OnSearchSelectHide()"
 
633
     onkeydown="return searchBox.OnSearchSelectKey(event)">
 
634
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>
 
635
 
 
636
<!-- iframe showing the search results (closed by default) -->
 
637
<div id="MSearchResultsWindow">
 
638
<iframe src="javascript:void(0)" frameborder="0" 
 
639
        name="MSearchResults" id="MSearchResults">
 
640
</iframe>
 
641
</div>
 
642
 
 
643
  <div id="nav-path" class="navpath">
 
644
    <ul>
 
645
      <li class="navelem"><a class="el" href="a00906.html">intfx.cpp</a>      </li>
 
646
 
 
647
    <li class="footer">Generated on Mon Feb 3 2014 10:59:09 for tesseract by
 
648
    <a href="http://www.doxygen.org/index.html">
 
649
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
 
650
   </ul>
 
651
 </div>
 
652
 
 
653
 
 
654
</body>
 
655
</html>