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

« back to all changes in this revision

Viewing changes to doc/html/a01219_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/wordrec/associate.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('a01219.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/wordrec/associate.cpp</div>  </div>
 
101
</div><!--header-->
 
102
<div class="contents">
 
103
<a href="a01219.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
 
104
<a name="l00002"></a>00002 <span class="comment">// File:        associate.cpp</span>
 
105
<a name="l00003"></a>00003 <span class="comment">// Description: Functions for scoring segmentation paths according to</span>
 
106
<a name="l00004"></a>00004 <span class="comment">//              their character widths, gap widths and seam cuts.</span>
 
107
<a name="l00005"></a>00005 <span class="comment">// Author:      Daria Antonova</span>
 
108
<a name="l00006"></a>00006 <span class="comment">// Created:     Mon Mar 8 11:26:43 PDT 2010</span>
 
109
<a name="l00007"></a>00007 <span class="comment">//</span>
 
110
<a name="l00008"></a>00008 <span class="comment">// (C) Copyright 2010, Google Inc.</span>
 
111
<a name="l00009"></a>00009 <span class="comment">// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
 
112
<a name="l00010"></a>00010 <span class="comment">// you may not use this file except in compliance with the License.</span>
 
113
<a name="l00011"></a>00011 <span class="comment">// You may obtain a copy of the License at</span>
 
114
<a name="l00012"></a>00012 <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span>
 
115
<a name="l00013"></a>00013 <span class="comment">// Unless required by applicable law or agreed to in writing, software</span>
 
116
<a name="l00014"></a>00014 <span class="comment">// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
 
117
<a name="l00015"></a>00015 <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
 
118
<a name="l00016"></a>00016 <span class="comment">// See the License for the specific language governing permissions and</span>
 
119
<a name="l00017"></a>00017 <span class="comment">// limitations under the License.</span>
 
120
<a name="l00018"></a>00018 <span class="comment">//</span>
 
121
<a name="l00020"></a>00020 <span class="comment"></span>
 
122
<a name="l00021"></a>00021 
 
123
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
 
124
<a name="l00023"></a>00023 <span class="preprocessor">#ifdef __UNIX__</span>
 
125
<a name="l00024"></a>00024 <span class="preprocessor"></span><span class="preprocessor">#include &lt;assert.h&gt;</span>
 
126
<a name="l00025"></a>00025 <span class="preprocessor">#endif</span>
 
127
<a name="l00026"></a>00026 <span class="preprocessor"></span><span class="preprocessor">#include &lt;math.h&gt;</span>
 
128
<a name="l00027"></a>00027 
 
129
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="a01220.html">associate.h</a>&quot;</span>
 
130
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;<a class="code" href="a00759.html">normalis.h</a>&quot;</span>
 
131
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="a00769.html">pageres.h</a>&quot;</span>
 
132
<a name="l00031"></a>00031 
 
133
<a name="l00032"></a>00032 <span class="keyword">namespace </span><a class="code" href="a01266.html#afed58feacb84df2de88bdd613cfdba6d">tesseract</a> {
 
134
<a name="l00033"></a>00033 
 
135
<a name="l00034"></a>00034 <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="a00262.html#a3bbebfa62ab6a7838649af61e9ef965f">AssociateUtils::kMaxFixedPitchCharAspectRatio</a> = 2.0f;
 
136
<a name="l00035"></a>00035 <span class="keyword">const</span> <span class="keywordtype">float</span> <a class="code" href="a00262.html#aa6ed9abceac9a721db5d174ff0e7c119">AssociateUtils::kMinGap</a> = 0.03f;
 
137
<a name="l00036"></a>00036 
 
138
<a name="l00037"></a><a class="code" href="a00262.html#addbd0b3d90043ef77d53523d3591dd59">00037</a> <span class="keywordtype">void</span> <a class="code" href="a00262.html#addbd0b3d90043ef77d53523d3591dd59">AssociateUtils::ComputeStats</a>(<span class="keywordtype">int</span> col, <span class="keywordtype">int</span> row,
 
139
<a name="l00038"></a>00038                                   <span class="keyword">const</span> <a class="code" href="a00261.html">AssociateStats</a> *parent_stats,
 
140
<a name="l00039"></a>00039                                   <span class="keywordtype">int</span> parent_path_length,
 
141
<a name="l00040"></a>00040                                   <span class="keywordtype">bool</span> fixed_pitch,
 
142
<a name="l00041"></a>00041                                   <span class="keywordtype">float</span> max_char_wh_ratio,
 
143
<a name="l00042"></a>00042                                   <a class="code" href="a00650.html">WERD_RES</a> *word_res,
 
144
<a name="l00043"></a>00043                                   <span class="keywordtype">bool</span> debug,
 
145
<a name="l00044"></a>00044                                   <a class="code" href="a00261.html">AssociateStats</a> *stats) {
 
146
<a name="l00045"></a>00045   stats-&gt;<a class="code" href="a00261.html#a94932d58d48ea9317ce3d813d63079ec">Clear</a>();
 
147
<a name="l00046"></a>00046 
 
148
<a name="l00047"></a>00047   <a class="code" href="a00823.html#a93a603f4063a6b9403d81caa245a583b">ASSERT_HOST</a>(word_res != NULL);
 
149
<a name="l00048"></a>00048   <span class="keywordflow">if</span> (word_res-&gt;<a class="code" href="a00650.html#a3aeb8deef67c5383e1a116049b994be4">blob_widths</a>.<a class="code" href="a00403.html#afb0d8c52a603b6aa965d63bbf06a27dd">empty</a>()) {
 
150
<a name="l00049"></a>00049     <span class="keywordflow">return</span>;
 
151
<a name="l00050"></a>00050   }
 
152
<a name="l00051"></a>00051   <span class="keywordflow">if</span> (debug) {
 
153
<a name="l00052"></a>00052     <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;AssociateUtils::ComputeStats() for col=%d, row=%d%s\n&quot;</span>,
 
154
<a name="l00053"></a>00053             col, row, fixed_pitch ? <span class="stringliteral">&quot; (fixed pitch)&quot;</span> : <span class="stringliteral">&quot;&quot;</span>);
 
155
<a name="l00054"></a>00054   }
 
156
<a name="l00055"></a>00055   <span class="keywordtype">float</span> normalizing_height = <a class="code" href="a00759.html#af974e6755e636c8bc7cbe57e3bcbdd73">kBlnXHeight</a>;
 
157
<a name="l00056"></a>00056   <a class="code" href="a00521.html">ROW</a>* blob_row = word_res-&gt;<a class="code" href="a00650.html#ad19fe10ab70cd975f21ae9c74753879a">blob_row</a>;
 
158
<a name="l00057"></a>00057   <span class="comment">// TODO(rays/daria) Can unicharset.script_has_xheight be useful here?</span>
 
159
<a name="l00058"></a>00058   <span class="keywordflow">if</span> (fixed_pitch &amp;&amp; blob_row != NULL) {
 
160
<a name="l00059"></a>00059     <span class="comment">// For fixed pitch language like CJK, we use the full text height</span>
 
161
<a name="l00060"></a>00060     <span class="comment">// as the normalizing factor so we are not dependent on xheight</span>
 
162
<a name="l00061"></a>00061     <span class="comment">// calculation.</span>
 
163
<a name="l00062"></a>00062     <span class="keywordflow">if</span> (blob_row-&gt;<a class="code" href="a00521.html#ab657f290bd4e99106c7ea8868ce7072f">body_size</a>() &gt; 0.0f) {
 
164
<a name="l00063"></a>00063       normalizing_height = word_res-&gt;<a class="code" href="a00650.html#a202d9d5d2a462d84012011c689e16605">denorm</a>.<a class="code" href="a00352.html#a712ca9b7a1041d92e53ee7023b870fc6">y_scale</a>() * blob_row-&gt;<a class="code" href="a00521.html#ab657f290bd4e99106c7ea8868ce7072f">body_size</a>();
 
165
<a name="l00064"></a>00064     } <span class="keywordflow">else</span> {
 
166
<a name="l00065"></a>00065       normalizing_height = word_res-&gt;<a class="code" href="a00650.html#a202d9d5d2a462d84012011c689e16605">denorm</a>.<a class="code" href="a00352.html#a712ca9b7a1041d92e53ee7023b870fc6">y_scale</a>() *
 
167
<a name="l00066"></a>00066           (blob_row-&gt;<a class="code" href="a00521.html#a2954f94ec4eefe1e3729912e5b8ea779">x_height</a>() + blob_row-&gt;<a class="code" href="a00521.html#a594cf3a3fd6dd203c8d0e58aa0c5227f">ascenders</a>());
 
168
<a name="l00067"></a>00067     }
 
169
<a name="l00068"></a>00068     <span class="keywordflow">if</span> (debug) {
 
170
<a name="l00069"></a>00069       <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;normalizing height = %g (scale %g xheight %g ascenders %g)\n&quot;</span>,
 
171
<a name="l00070"></a>00070               normalizing_height, word_res-&gt;<a class="code" href="a00650.html#a202d9d5d2a462d84012011c689e16605">denorm</a>.<a class="code" href="a00352.html#a712ca9b7a1041d92e53ee7023b870fc6">y_scale</a>(),
 
172
<a name="l00071"></a>00071               blob_row-&gt;<a class="code" href="a00521.html#a2954f94ec4eefe1e3729912e5b8ea779">x_height</a>(), blob_row-&gt;<a class="code" href="a00521.html#a594cf3a3fd6dd203c8d0e58aa0c5227f">ascenders</a>());
 
173
<a name="l00072"></a>00072     }
 
174
<a name="l00073"></a>00073   }
 
175
<a name="l00074"></a>00074   <span class="keywordtype">float</span> wh_ratio = word_res-&gt;<a class="code" href="a00650.html#a7104318921889ed38e23323e97a079fd">GetBlobsWidth</a>(col, row) / normalizing_height;
 
176
<a name="l00075"></a>00075   <span class="keywordflow">if</span> (wh_ratio &gt; max_char_wh_ratio) stats-&gt;<a class="code" href="a00261.html#a477458043cffc5f8f1387b53616e1148">bad_shape</a> = <span class="keyword">true</span>;
 
177
<a name="l00076"></a>00076   <span class="comment">// Compute the gap sum for this shape. If there are only negative or only</span>
 
178
<a name="l00077"></a>00077   <span class="comment">// positive gaps, record their sum in stats-&gt;gap_sum. However, if there is</span>
 
179
<a name="l00078"></a>00078   <span class="comment">// a mixture, record only the sum of the positive gaps.</span>
 
180
<a name="l00079"></a>00079   <span class="comment">// TODO(antonova): explain fragment.</span>
 
181
<a name="l00080"></a>00080   <span class="keywordtype">int</span> negative_gap_sum = 0;
 
182
<a name="l00081"></a>00081   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> c = col; c &lt; row; ++c) {
 
183
<a name="l00082"></a>00082     <span class="keywordtype">int</span> gap = word_res-&gt;<a class="code" href="a00650.html#a14a8fa4736d57b643471c48291e23bfb">GetBlobsGap</a>(c);
 
184
<a name="l00083"></a>00083     (gap &gt; 0) ? stats-&gt;<a class="code" href="a00261.html#a9350993c1c0e901679569dcc1c7a2027">gap_sum</a> += gap : negative_gap_sum += gap;
 
185
<a name="l00084"></a>00084   }
 
186
<a name="l00085"></a>00085   <span class="keywordflow">if</span> (stats-&gt;<a class="code" href="a00261.html#a9350993c1c0e901679569dcc1c7a2027">gap_sum</a> == 0) stats-&gt;<a class="code" href="a00261.html#a9350993c1c0e901679569dcc1c7a2027">gap_sum</a> = negative_gap_sum;
 
187
<a name="l00086"></a>00086   <span class="keywordflow">if</span> (debug) {
 
188
<a name="l00087"></a>00087     <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;wh_ratio=%g (max_char_wh_ratio=%g) gap_sum=%d %s\n&quot;</span>,
 
189
<a name="l00088"></a>00088             wh_ratio, max_char_wh_ratio, stats-&gt;<a class="code" href="a00261.html#a9350993c1c0e901679569dcc1c7a2027">gap_sum</a>,
 
190
<a name="l00089"></a>00089             stats-&gt;<a class="code" href="a00261.html#a477458043cffc5f8f1387b53616e1148">bad_shape</a> ? <span class="stringliteral">&quot;bad_shape&quot;</span> : <span class="stringliteral">&quot;&quot;</span>);
 
191
<a name="l00090"></a>00090   }
 
192
<a name="l00091"></a>00091   <span class="comment">// Compute shape_cost (for fixed pitch mode).</span>
 
193
<a name="l00092"></a>00092   <span class="keywordflow">if</span> (fixed_pitch) {
 
194
<a name="l00093"></a>00093     <span class="keywordtype">bool</span> end_row = (row == (word_res-&gt;<a class="code" href="a00650.html#af7454f140688a32b2bebb60ab36e91ee">ratings</a>-&gt;<a class="code" href="a00264.html#a82cbdd8a6eb23048b3d1cb656d34a364">dimension</a>() - 1));
 
195
<a name="l00094"></a>00094 
 
196
<a name="l00095"></a>00095     <span class="comment">// Ensure that the blob has gaps on the left and the right sides</span>
 
197
<a name="l00096"></a>00096     <span class="comment">// (except for beginning and ending punctuation) and that there is</span>
 
198
<a name="l00097"></a>00097     <span class="comment">// no cutting through ink at the blob boundaries.</span>
 
199
<a name="l00098"></a>00098     <span class="keywordflow">if</span> (col &gt; 0) {
 
200
<a name="l00099"></a>00099       <span class="keywordtype">float</span> left_gap = word_res-&gt;<a class="code" href="a00650.html#a14a8fa4736d57b643471c48291e23bfb">GetBlobsGap</a>(col - 1) / normalizing_height;
 
201
<a name="l00100"></a>00100       <a class="code" href="a00533.html">SEAM</a> *left_seam = word_res-&gt;<a class="code" href="a00650.html#a3d0de828a382a88581dafb5a304141f1">seam_array</a>[col - 1];
 
202
<a name="l00101"></a>00101       <span class="keywordflow">if</span> ((!end_row &amp;&amp; left_gap &lt; <a class="code" href="a00262.html#aa6ed9abceac9a721db5d174ff0e7c119">kMinGap</a>) || left_seam-&gt;<a class="code" href="a00533.html#a69d4a1583be12fbd22f1232d6ed0403f">priority</a> &gt; 0.0f) {
 
203
<a name="l00102"></a>00102         stats-&gt;<a class="code" href="a00261.html#a477458043cffc5f8f1387b53616e1148">bad_shape</a> = <span class="keyword">true</span>;
 
204
<a name="l00103"></a>00103       }
 
205
<a name="l00104"></a>00104       <span class="keywordflow">if</span> (debug) {
 
206
<a name="l00105"></a>00105         <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;left_gap %g, left_seam %g %s\n&quot;</span>, left_gap, left_seam-&gt;<a class="code" href="a00533.html#a69d4a1583be12fbd22f1232d6ed0403f">priority</a>,
 
207
<a name="l00106"></a>00106                 stats-&gt;<a class="code" href="a00261.html#a477458043cffc5f8f1387b53616e1148">bad_shape</a> ? <span class="stringliteral">&quot;bad_shape&quot;</span> : <span class="stringliteral">&quot;&quot;</span>);
 
208
<a name="l00107"></a>00107       }
 
209
<a name="l00108"></a>00108     }
 
210
<a name="l00109"></a>00109     <span class="keywordtype">float</span> right_gap = 0.0f;
 
211
<a name="l00110"></a>00110     <span class="keywordflow">if</span> (!end_row) {
 
212
<a name="l00111"></a>00111       right_gap = word_res-&gt;<a class="code" href="a00650.html#a14a8fa4736d57b643471c48291e23bfb">GetBlobsGap</a>(row) / normalizing_height;
 
213
<a name="l00112"></a>00112       <a class="code" href="a00533.html">SEAM</a> *right_seam = word_res-&gt;<a class="code" href="a00650.html#a3d0de828a382a88581dafb5a304141f1">seam_array</a>[row];
 
214
<a name="l00113"></a>00113       <span class="keywordflow">if</span> (right_gap &lt; kMinGap || right_seam-&gt;priority &gt; 0.0f) {
 
215
<a name="l00114"></a>00114         stats-&gt;<a class="code" href="a00261.html#a477458043cffc5f8f1387b53616e1148">bad_shape</a> = <span class="keyword">true</span>;
 
216
<a name="l00115"></a>00115         <span class="keywordflow">if</span> (right_gap &lt; <a class="code" href="a00262.html#aa6ed9abceac9a721db5d174ff0e7c119">kMinGap</a>) stats-&gt;<a class="code" href="a00261.html#aef322d855f9233bee2fc73f5420c054f">bad_fixed_pitch_right_gap</a> = <span class="keyword">true</span>;
 
217
<a name="l00116"></a>00116       }
 
218
<a name="l00117"></a>00117       <span class="keywordflow">if</span> (debug) {
 
219
<a name="l00118"></a>00118         <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;right_gap %g right_seam %g %s\n&quot;</span>,
 
220
<a name="l00119"></a>00119                 right_gap, right_seam-&gt;<a class="code" href="a00533.html#a69d4a1583be12fbd22f1232d6ed0403f">priority</a>,
 
221
<a name="l00120"></a>00120                 stats-&gt;<a class="code" href="a00261.html#a477458043cffc5f8f1387b53616e1148">bad_shape</a> ? <span class="stringliteral">&quot;bad_shape&quot;</span> : <span class="stringliteral">&quot;&quot;</span>);
 
222
<a name="l00121"></a>00121       }
 
223
<a name="l00122"></a>00122     }
 
224
<a name="l00123"></a>00123 
 
225
<a name="l00124"></a>00124     <span class="comment">// Impose additional segmentation penalties if blob widths or gaps</span>
 
226
<a name="l00125"></a>00125     <span class="comment">// distribution don&#39;t fit a fixed-pitch model.</span>
 
227
<a name="l00126"></a>00126     <span class="comment">// Since we only know the widths and gaps of the path explored so far,</span>
 
228
<a name="l00127"></a>00127     <span class="comment">// the means and variances are computed for the path so far (not</span>
 
229
<a name="l00128"></a>00128     <span class="comment">// considering characters to the right of the last character on the path).</span>
 
230
<a name="l00129"></a>00129     stats-&gt;<a class="code" href="a00261.html#aedfc7bb8a188b3d07506787d1c873120">full_wh_ratio</a> = wh_ratio + right_gap;
 
231
<a name="l00130"></a>00130     <span class="keywordflow">if</span> (parent_stats != NULL) {
 
232
<a name="l00131"></a>00131       stats-&gt;<a class="code" href="a00261.html#a6ecdf1e1853a6a488ce7b6c997355fde">full_wh_ratio_total</a> =
 
233
<a name="l00132"></a>00132         (parent_stats-&gt;<a class="code" href="a00261.html#a6ecdf1e1853a6a488ce7b6c997355fde">full_wh_ratio_total</a> + stats-&gt;<a class="code" href="a00261.html#aedfc7bb8a188b3d07506787d1c873120">full_wh_ratio</a>);
 
234
<a name="l00133"></a>00133       <span class="keywordtype">float</span> mean =
 
235
<a name="l00134"></a>00134         stats-&gt;<a class="code" href="a00261.html#a6ecdf1e1853a6a488ce7b6c997355fde">full_wh_ratio_total</a> / <span class="keyword">static_cast&lt;</span><span class="keywordtype">float</span><span class="keyword">&gt;</span>(parent_path_length+1);
 
236
<a name="l00135"></a>00135       stats-&gt;<a class="code" href="a00261.html#a898cad6cb2de906d3d179efe2411c7a6">full_wh_ratio_var</a> =
 
237
<a name="l00136"></a>00136         parent_stats-&gt;<a class="code" href="a00261.html#a898cad6cb2de906d3d179efe2411c7a6">full_wh_ratio_var</a> + pow(mean-stats-&gt;<a class="code" href="a00261.html#aedfc7bb8a188b3d07506787d1c873120">full_wh_ratio</a>, 2);
 
238
<a name="l00137"></a>00137     } <span class="keywordflow">else</span> {
 
239
<a name="l00138"></a>00138       stats-&gt;<a class="code" href="a00261.html#a6ecdf1e1853a6a488ce7b6c997355fde">full_wh_ratio_total</a> = stats-&gt;<a class="code" href="a00261.html#aedfc7bb8a188b3d07506787d1c873120">full_wh_ratio</a>;
 
240
<a name="l00139"></a>00139     }
 
241
<a name="l00140"></a>00140     <span class="keywordflow">if</span> (debug) {
 
242
<a name="l00141"></a>00141       <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;full_wh_ratio %g full_wh_ratio_total %g full_wh_ratio_var %g\n&quot;</span>,
 
243
<a name="l00142"></a>00142               stats-&gt;<a class="code" href="a00261.html#aedfc7bb8a188b3d07506787d1c873120">full_wh_ratio</a>, stats-&gt;<a class="code" href="a00261.html#a6ecdf1e1853a6a488ce7b6c997355fde">full_wh_ratio_total</a>,
 
244
<a name="l00143"></a>00143               stats-&gt;<a class="code" href="a00261.html#a898cad6cb2de906d3d179efe2411c7a6">full_wh_ratio_var</a>);
 
245
<a name="l00144"></a>00144     }
 
246
<a name="l00145"></a>00145 
 
247
<a name="l00146"></a>00146     stats-&gt;<a class="code" href="a00261.html#a0185040dea9a2fadac41feb45729e444">shape_cost</a> =
 
248
<a name="l00147"></a>00147       <a class="code" href="a00262.html#ad70d4139f63f9d5048faa8407058523f">FixedPitchWidthCost</a>(wh_ratio, right_gap, end_row, max_char_wh_ratio);
 
249
<a name="l00148"></a>00148 
 
250
<a name="l00149"></a>00149     <span class="comment">// For some reason Tesseract prefers to treat the whole CJ words</span>
 
251
<a name="l00150"></a>00150     <span class="comment">// as one blob when the initial segmentation is particularly bad.</span>
 
252
<a name="l00151"></a>00151     <span class="comment">// This hack is to avoid favoring such states.</span>
 
253
<a name="l00152"></a>00152     <span class="keywordflow">if</span> (col == 0 &amp;&amp; end_row &amp;&amp; wh_ratio &gt; max_char_wh_ratio) {
 
254
<a name="l00153"></a>00153       stats-&gt;<a class="code" href="a00261.html#a0185040dea9a2fadac41feb45729e444">shape_cost</a> += 10;
 
255
<a name="l00154"></a>00154     }
 
256
<a name="l00155"></a>00155     stats-&gt;<a class="code" href="a00261.html#a0185040dea9a2fadac41feb45729e444">shape_cost</a> += stats-&gt;<a class="code" href="a00261.html#a898cad6cb2de906d3d179efe2411c7a6">full_wh_ratio_var</a>;
 
257
<a name="l00156"></a>00156     <span class="keywordflow">if</span> (debug) <a class="code" href="a00860.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">&quot;shape_cost %g\n&quot;</span>, stats-&gt;<a class="code" href="a00261.html#a0185040dea9a2fadac41feb45729e444">shape_cost</a>);
 
258
<a name="l00157"></a>00157   }
 
259
<a name="l00158"></a>00158 }
 
260
<a name="l00159"></a>00159 
 
261
<a name="l00160"></a><a class="code" href="a00262.html#ad70d4139f63f9d5048faa8407058523f">00160</a> <span class="keywordtype">float</span> <a class="code" href="a00262.html#ad70d4139f63f9d5048faa8407058523f">AssociateUtils::FixedPitchWidthCost</a>(<span class="keywordtype">float</span> norm_width,
 
262
<a name="l00161"></a>00161                                           <span class="keywordtype">float</span> right_gap,
 
263
<a name="l00162"></a>00162                                           <span class="keywordtype">bool</span> end_pos,
 
264
<a name="l00163"></a>00163                                           <span class="keywordtype">float</span> max_char_wh_ratio) {
 
265
<a name="l00164"></a>00164   <span class="keywordtype">float</span> cost = 0.0f;
 
266
<a name="l00165"></a>00165   <span class="keywordflow">if</span> (norm_width &gt; max_char_wh_ratio) cost += norm_width;
 
267
<a name="l00166"></a>00166   <span class="keywordflow">if</span> (norm_width &gt; <a class="code" href="a00262.html#a3bbebfa62ab6a7838649af61e9ef965f">kMaxFixedPitchCharAspectRatio</a>)
 
268
<a name="l00167"></a>00167     cost += norm_width * norm_width;  <span class="comment">// extra penalty for merging CJK chars</span>
 
269
<a name="l00168"></a>00168   <span class="comment">// Penalize skinny blobs, except for punctuation in the last position.</span>
 
270
<a name="l00169"></a>00169   <span class="keywordflow">if</span> (norm_width+right_gap &lt; 0.5f &amp;&amp; !end_pos) {
 
271
<a name="l00170"></a>00170     cost += 1.0f - (norm_width + right_gap);
 
272
<a name="l00171"></a>00171   }
 
273
<a name="l00172"></a>00172   <span class="keywordflow">return</span> cost;
 
274
<a name="l00173"></a>00173 }
 
275
<a name="l00174"></a>00174 
 
276
<a name="l00175"></a>00175 }  <span class="comment">// namespace tesseract</span>
 
277
</pre></div></div><!-- contents -->
 
278
</div>
 
279
<!-- window showing the filter options -->
 
280
<div id="MSearchSelectWindow"
 
281
     onmouseover="return searchBox.OnSearchSelectShow()"
 
282
     onmouseout="return searchBox.OnSearchSelectHide()"
 
283
     onkeydown="return searchBox.OnSearchSelectKey(event)">
 
284
<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>
 
285
 
 
286
<!-- iframe showing the search results (closed by default) -->
 
287
<div id="MSearchResultsWindow">
 
288
<iframe src="javascript:void(0)" frameborder="0" 
 
289
        name="MSearchResults" id="MSearchResults">
 
290
</iframe>
 
291
</div>
 
292
 
 
293
  <div id="nav-path" class="navpath">
 
294
    <ul>
 
295
      <li class="navelem"><a class="el" href="a01219.html">associate.cpp</a>      </li>
 
296
 
 
297
    <li class="footer">Generated on Mon Feb 3 2014 10:59:10 for tesseract by
 
298
    <a href="http://www.doxygen.org/index.html">
 
299
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
 
300
   </ul>
 
301
 </div>
 
302
 
 
303
 
 
304
</body>
 
305
</html>