<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.14"/> <meta name="viewport" content="width=device-width, initial-scale=1"/> <title>tesseract: textord/baselinedetect.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="navtree.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="resize.js"></script> <script type="text/javascript" src="navtreedata.js"></script> <script type="text/javascript" src="navtree.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(document).ready(initResizable); /* @license-end */</script> <link href="search/search.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="search/searchdata.js"></script> <script type="text/javascript" src="search/search.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td id="projectalign" style="padding-left: 0.5em;"> <div id="projectname">tesseract  <span id="projectnumber">3.05.02</span> </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.14 --> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ var searchBox = new SearchBox("searchBox", "search",false,'Search'); /* @license-end */ </script> <script type="text/javascript" src="menudata.js"></script> <script type="text/javascript" src="menu.js"></script> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(function() { initMenu('',true,false,'search.php','Search'); $(document).ready(function() { init_search(); }); }); /* @license-end */</script> <div id="main-nav"></div> </div><!-- top --> <div id="side-nav" class="ui-resizable side-nav-resizable"> <div id="nav-tree"> <div id="nav-tree-contents"> <div id="nav-sync" class="sync"></div> </div> </div> <div id="splitbar" style="-moz-user-select:none;" class="ui-resizable-handle"> </div> </div> <script type="text/javascript"> /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */ $(document).ready(function(){initNavTree('a01253_source.html','');}); /* @license-end */ </script> <div id="doc-content"> <!-- window showing the filter options --> <div id="MSearchSelectWindow" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()" onkeydown="return searchBox.OnSearchSelectKey(event)"> </div> <!-- iframe showing the search results (closed by default) --> <div id="MSearchResultsWindow"> <iframe src="javascript:void(0)" frameborder="0" name="MSearchResults" id="MSearchResults"> </iframe> </div> <div class="header"> <div class="headertitle"> <div class="title">baselinedetect.cpp</div> </div> </div><!--header--> <div class="contents"> <a href="a01253.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span> <span class="comment">// File: baselinedetect.cpp</span></div><div class="line"><a name="l00003"></a><span class="lineno"> 3</span> <span class="comment">// Description: Initial Baseline Determination.</span></div><div class="line"><a name="l00004"></a><span class="lineno"> 4</span> <span class="comment">// Copyright 2012 Google Inc. All Rights Reserved.</span></div><div class="line"><a name="l00005"></a><span class="lineno"> 5</span> <span class="comment">// Author: rays@google.com (Ray Smith)</span></div><div class="line"><a name="l00006"></a><span class="lineno"> 6</span> <span class="comment">// Created: Mon Apr 30 10:15:31 PDT 2012</span></div><div class="line"><a name="l00007"></a><span class="lineno"> 7</span> <span class="comment">//</span></div><div class="line"><a name="l00008"></a><span class="lineno"> 8</span> <span class="comment">// Licensed under the Apache License, Version 2.0 (the "License");</span></div><div class="line"><a name="l00009"></a><span class="lineno"> 9</span> <span class="comment">// you may not use this file except in compliance with the License.</span></div><div class="line"><a name="l00010"></a><span class="lineno"> 10</span> <span class="comment">// You may obtain a copy of the License at</span></div><div class="line"><a name="l00011"></a><span class="lineno"> 11</span> <span class="comment">// http://www.apache.org/licenses/LICENSE-2.0</span></div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span> <span class="comment">// Unless required by applicable law or agreed to in writing, software</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span> <span class="comment">// distributed under the License is distributed on an "AS IS" BASIS,</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span> <span class="comment">// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span></div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span> <span class="comment">// See the License for the specific language governing permissions and</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span> <span class="comment">// limitations under the License.</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span> <span class="comment">//</span></div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span> <span class="comment"></span></div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span> <span class="preprocessor">#ifdef _MSC_VER</span></div><div class="line"><a name="l00021"></a><span class="lineno"> 21</span> <span class="preprocessor">#define _USE_MATH_DEFINES</span></div><div class="line"><a name="l00022"></a><span class="lineno"> 22</span> <span class="preprocessor">#endif // _MSC_VER</span></div><div class="line"><a name="l00023"></a><span class="lineno"> 23</span> </div><div class="line"><a name="l00024"></a><span class="lineno"> 24</span> <span class="preprocessor">#ifdef HAVE_CONFIG_H</span></div><div class="line"><a name="l00025"></a><span class="lineno"> 25</span> <span class="preprocessor">#include "<a class="code" href="a00851.html">config_auto.h</a>"</span></div><div class="line"><a name="l00026"></a><span class="lineno"> 26</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00027"></a><span class="lineno"> 27</span> </div><div class="line"><a name="l00028"></a><span class="lineno"> 28</span> <span class="preprocessor">#include "<a class="code" href="a01256.html">baselinedetect.h</a>"</span></div><div class="line"><a name="l00029"></a><span class="lineno"> 29</span> </div><div class="line"><a name="l00030"></a><span class="lineno"> 30</span> <span class="preprocessor">#include <math.h></span></div><div class="line"><a name="l00031"></a><span class="lineno"> 31</span> <span class="preprocessor">#include "allheaders.h"</span></div><div class="line"><a name="l00032"></a><span class="lineno"> 32</span> <span class="preprocessor">#include "<a class="code" href="a00209.html">blobbox.h</a>"</span></div><div class="line"><a name="l00033"></a><span class="lineno"> 33</span> <span class="preprocessor">#include "<a class="code" href="a00254.html">detlinefit.h</a>"</span></div><div class="line"><a name="l00034"></a><span class="lineno"> 34</span> <span class="preprocessor">#include "<a class="code" href="a01328.html">drawtord.h</a>"</span></div><div class="line"><a name="l00035"></a><span class="lineno"> 35</span> <span class="preprocessor">#include "<a class="code" href="a00521.html">helpers.h</a>"</span></div><div class="line"><a name="l00036"></a><span class="lineno"> 36</span> <span class="preprocessor">#include "<a class="code" href="a00290.html">linlsq.h</a>"</span></div><div class="line"><a name="l00037"></a><span class="lineno"> 37</span> <span class="preprocessor">#include "<a class="code" href="a01376.html">makerow.h</a>"</span></div><div class="line"><a name="l00038"></a><span class="lineno"> 38</span> <span class="preprocessor">#include "<a class="code" href="a01448.html">textord.h</a>"</span></div><div class="line"><a name="l00039"></a><span class="lineno"> 39</span> <span class="preprocessor">#include "<a class="code" href="a00608.html">tprintf.h</a>"</span></div><div class="line"><a name="l00040"></a><span class="lineno"> 40</span> <span class="preprocessor">#include "<a class="code" href="a01475.html">underlin.h</a>"</span></div><div class="line"><a name="l00041"></a><span class="lineno"> 41</span> </div><div class="line"><a name="l00042"></a><span class="lineno"> 42</span> <span class="comment">// Number of displacement modes kept in displacement_modes_;</span></div><div class="line"><a name="l00043"></a><span class="lineno"><a class="line" href="a01253.html#a764108909ac86000da00e33ae249ff17"> 43</a></span> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="a01253.html#a764108909ac86000da00e33ae249ff17">kMaxDisplacementsModes</a> = 3;</div><div class="line"><a name="l00044"></a><span class="lineno"> 44</span> <span class="comment">// Number of points to skip when retrying initial fit.</span></div><div class="line"><a name="l00045"></a><span class="lineno"><a class="line" href="a01253.html#adaf423fe42f3ca4b3343020dc41c376b"> 45</a></span> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="a01253.html#adaf423fe42f3ca4b3343020dc41c376b">kNumSkipPoints</a> = 3;</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span> <span class="comment">// Max angle deviation (in radians) allowed to keep the independent baseline.</span></div><div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="a01253.html#aa447e3d51461981e8e7c5450e57d9300"> 47</a></span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="a01253.html#aa447e3d51461981e8e7c5450e57d9300">kMaxSkewDeviation</a> = 1.0 / 64;</div><div class="line"><a name="l00048"></a><span class="lineno"> 48</span> <span class="comment">// Fraction of line spacing estimate for quantization of blob displacements.</span></div><div class="line"><a name="l00049"></a><span class="lineno"><a class="line" href="a01253.html#a5c9c93517d2f2243b2b265cb1e3b03db"> 49</a></span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="a01253.html#a5c9c93517d2f2243b2b265cb1e3b03db">kOffsetQuantizationFactor</a> = 3.0 / 64;</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span> <span class="comment">// Fraction of line spacing estimate for computing blob fit error.</span></div><div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="a01253.html#a5acb8f8490c1a3b68684d10c460e1e96"> 51</a></span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="a01253.html#a5acb8f8490c1a3b68684d10c460e1e96">kFitHalfrangeFactor</a> = 6.0 / 64;</div><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> <span class="comment">// Max fraction of line spacing allowed before a baseline counts as badly fitting.</span></div><div class="line"><a name="l00053"></a><span class="lineno"><a class="line" href="a01253.html#a31cf284314686a893cae2fc26c503f0c"> 53</a></span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="a01253.html#a31cf284314686a893cae2fc26c503f0c">kMaxBaselineError</a> = 3.0 / 64;</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span> <span class="comment">// Multiple of linespacing that sets max_blob_size in TO_BLOCK.</span></div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span> <span class="comment">// Copied from textord_excess_blobsize.</span></div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="a01253.html#a46b90f606788891fac29c14f20f39b27"> 56</a></span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="a01253.html#a46b90f606788891fac29c14f20f39b27">kMaxBlobSizeMultiple</a> = 1.3;</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span> <span class="comment">// Min fraction of linespacing gaps that should be close to the model before</span></div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span> <span class="comment">// we will force the linespacing model on all the lines.</span></div><div class="line"><a name="l00059"></a><span class="lineno"><a class="line" href="a01253.html#aa61dc7df62ef6cd14f8f4a9e6b3003c9"> 59</a></span> <span class="keyword">const</span> <span class="keywordtype">double</span> <a class="code" href="a01253.html#aa61dc7df62ef6cd14f8f4a9e6b3003c9">kMinFittingLinespacings</a> = 0.25;</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span> <span class="comment">// A y-coordinate within a textline that is to be debugged.</span></div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span> <span class="comment">//#define kDebugYCoord 1525</span></div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span> </div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span> <span class="keyword">namespace </span><a class="code" href="a01738.html">tesseract</a> {</div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span> </div><div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="a04657.html#a9f18eec108377775507d2715186593cd"> 65</a></span> <a class="code" href="a04657.html#a9f18eec108377775507d2715186593cd">BaselineRow::BaselineRow</a>(<span class="keywordtype">double</span> line_spacing, <a class="code" href="a02485.html">TO_ROW</a>* to_row)</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  : blobs_(to_row->blob_list()),</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  baseline_pt1_(0.0f, 0.0f), baseline_pt2_(0.0f, 0.0f),</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  baseline_error_(0.0), good_baseline_(false) {</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  ComputeBoundingBox();</div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>  <span class="comment">// Compute a scale factor for rounding to ints.</span></div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>  disp_quant_factor_ = <a class="code" href="a01253.html#a5c9c93517d2f2243b2b265cb1e3b03db">kOffsetQuantizationFactor</a> * line_spacing;</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>  fit_halfrange_ = <a class="code" href="a01253.html#a5acb8f8490c1a3b68684d10c460e1e96">kFitHalfrangeFactor</a> * line_spacing;</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>  max_baseline_error_ = <a class="code" href="a01738.html#a8043339cb79428cd76d41f5432de9712">kMaxBaselineError</a> * line_spacing;</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span> }</div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span> </div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span> <span class="comment">// Sets the TO_ROW with the output straight line.</span></div><div class="line"><a name="l00077"></a><span class="lineno"><a class="line" href="a04657.html#adb63829f17ab14cfea6215b64ecf589e"> 77</a></span> <span class="keywordtype">void</span> <a class="code" href="a04657.html#adb63829f17ab14cfea6215b64ecf589e">BaselineRow::SetupOldLineParameters</a>(<a class="code" href="a02485.html">TO_ROW</a>* row)<span class="keyword"> const </span>{</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>  <span class="comment">// TODO(rays) get rid of this when m and c are no longer used.</span></div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>  <span class="keywordtype">double</span> gradient = tan(<a class="code" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">BaselineAngle</a>());</div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>  <span class="comment">// para_c is the actual intercept of the baseline on the y-axis.</span></div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <span class="keywordtype">float</span> para_c = <a class="code" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">StraightYAtX</a>(0.0);</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  row-><a class="code" href="a02485.html#a10818e7d801044a4d569466fa1d5f841">set_line</a>(gradient, para_c, baseline_error_);</div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  row-><a class="code" href="a02485.html#a448dbcbfc8d6c3c9c5e8c2fb127fd9d9">set_parallel_line</a>(gradient, para_c, baseline_error_);</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span> }</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span> </div><div class="line"><a name="l00086"></a><span class="lineno"> 86</span> <span class="comment">// Outputs diagnostic information.</span></div><div class="line"><a name="l00087"></a><span class="lineno"><a class="line" href="a04657.html#a1b1af2359af16a1a44ec5dcf74114142"> 87</a></span> <span class="keywordtype">void</span> <a class="code" href="a04657.html#a1b1af2359af16a1a44ec5dcf74114142">BaselineRow::Print</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Baseline (%g,%g)->(%g,%g), angle=%g, intercept=%g\n"</span>,</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  baseline_pt1_.<a class="code" href="a02681.html#aecd85311c159bcd52b485a97a8dcc901">x</a>(), baseline_pt1_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>(),</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  baseline_pt2_.<a class="code" href="a02681.html#aecd85311c159bcd52b485a97a8dcc901">x</a>(), baseline_pt2_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>(),</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <a class="code" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">BaselineAngle</a>(), <a class="code" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">StraightYAtX</a>(0.0));</div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Quant factor=%g, error=%g, good=%d, box:"</span>,</div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  disp_quant_factor_, baseline_error_, good_baseline_);</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  bounding_box_.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00095"></a><span class="lineno"> 95</span> }</div><div class="line"><a name="l00096"></a><span class="lineno"> 96</span> </div><div class="line"><a name="l00097"></a><span class="lineno"> 97</span> <span class="comment">// Returns the skew angle (in radians) of the current baseline in [-pi,pi].</span></div><div class="line"><a name="l00098"></a><span class="lineno"><a class="line" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17"> 98</a></span> <span class="keywordtype">double</span> <a class="code" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">BaselineRow::BaselineAngle</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00099"></a><span class="lineno"> 99</span>  <a class="code" href="a02681.html">FCOORD</a> baseline_dir(baseline_pt2_ - baseline_pt1_);</div><div class="line"><a name="l00100"></a><span class="lineno"> 100</span>  <span class="keywordtype">double</span> angle = baseline_dir.<a class="code" href="a02681.html#aab5b14bc328998adc252ffe7476d7f22">angle</a>();</div><div class="line"><a name="l00101"></a><span class="lineno"> 101</span>  <span class="comment">// Baseline directions are only unique in a range of pi so constrain to</span></div><div class="line"><a name="l00102"></a><span class="lineno"> 102</span>  <span class="comment">// [-pi/2, pi/2].</span></div><div class="line"><a name="l00103"></a><span class="lineno"> 103</span>  <span class="keywordflow">return</span> fmod(angle + M_PI * 1.5, M_PI) - M_PI * 0.5;</div><div class="line"><a name="l00104"></a><span class="lineno"> 104</span> }</div><div class="line"><a name="l00105"></a><span class="lineno"> 105</span> </div><div class="line"><a name="l00106"></a><span class="lineno"> 106</span> <span class="comment">// Computes and returns the linespacing at the middle of the overlap</span></div><div class="line"><a name="l00107"></a><span class="lineno"> 107</span> <span class="comment">// between this and other.</span></div><div class="line"><a name="l00108"></a><span class="lineno"><a class="line" href="a04657.html#a9089618e6511471f74427da4d9a2eb22"> 108</a></span> <span class="keywordtype">double</span> <a class="code" href="a04657.html#a9089618e6511471f74427da4d9a2eb22">BaselineRow::SpaceBetween</a>(<span class="keyword">const</span> <a class="code" href="a04657.html">BaselineRow</a>& other)<span class="keyword"> const </span>{</div><div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="comment">// Find the x-centre of overlap of the lines.</span></div><div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <span class="keywordtype">float</span> x = (<a class="code" href="a00548.html#aacc3ee1a7f283f8ef65cea31f4436a95">MAX</a>(bounding_box_.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>(), other.bounding_box_.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>()) +</div><div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  <a class="code" href="a00548.html#a74e75242132eaabbc1c512488a135926">MIN</a>(bounding_box_.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>(), other.bounding_box_.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>())) / 2.0f;</div><div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <span class="comment">// Find the vertical centre between them.</span></div><div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  <span class="keywordtype">float</span> y = (<a class="code" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">StraightYAtX</a>(x) + other.<a class="code" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">StraightYAtX</a>(x)) / 2.0f;</div><div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  <span class="comment">// Find the perpendicular distance of (x,y) from each line.</span></div><div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  <a class="code" href="a02681.html">FCOORD</a> pt(x, y);</div><div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  <span class="keywordflow">return</span> PerpDistanceFromBaseline(pt) + other.PerpDistanceFromBaseline(pt);</div><div class="line"><a name="l00117"></a><span class="lineno"> 117</span> }</div><div class="line"><a name="l00118"></a><span class="lineno"> 118</span> </div><div class="line"><a name="l00119"></a><span class="lineno"> 119</span> <span class="comment">// Computes and returns the displacement of the center of the line</span></div><div class="line"><a name="l00120"></a><span class="lineno"> 120</span> <span class="comment">// perpendicular to the given direction.</span></div><div class="line"><a name="l00121"></a><span class="lineno"><a class="line" href="a04657.html#a31f1ab3eb5a4d39c7956b9ad7fba07b0"> 121</a></span> <span class="keywordtype">double</span> <a class="code" href="a04657.html#a31f1ab3eb5a4d39c7956b9ad7fba07b0">BaselineRow::PerpDisp</a>(<span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>)<span class="keyword"> const </span>{</div><div class="line"><a name="l00122"></a><span class="lineno"> 122</span>  <span class="keywordtype">float</span> middle_x = (bounding_box_.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>() + bounding_box_.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>()) / 2.0f;</div><div class="line"><a name="l00123"></a><span class="lineno"> 123</span>  <a class="code" href="a02681.html">FCOORD</a> middle_pos(middle_x, <a class="code" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">StraightYAtX</a>(middle_x));</div><div class="line"><a name="l00124"></a><span class="lineno"> 124</span>  <span class="keywordflow">return</span> <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a> * middle_pos / <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>.length();</div><div class="line"><a name="l00125"></a><span class="lineno"> 125</span> }</div><div class="line"><a name="l00126"></a><span class="lineno"> 126</span> </div><div class="line"><a name="l00127"></a><span class="lineno"> 127</span> <span class="comment">// Computes the y coordinate at the given x using the straight baseline</span></div><div class="line"><a name="l00128"></a><span class="lineno"> 128</span> <span class="comment">// defined by baseline_pt1_ and baseline_pt2__.</span></div><div class="line"><a name="l00129"></a><span class="lineno"><a class="line" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f"> 129</a></span> <span class="keywordtype">double</span> <a class="code" href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">BaselineRow::StraightYAtX</a>(<span class="keywordtype">double</span> x)<span class="keyword"> const </span>{</div><div class="line"><a name="l00130"></a><span class="lineno"> 130</span>  <span class="keywordtype">double</span> denominator = baseline_pt2_.<a class="code" href="a02681.html#aecd85311c159bcd52b485a97a8dcc901">x</a>() - baseline_pt1_.<a class="code" href="a02681.html#aecd85311c159bcd52b485a97a8dcc901">x</a>();</div><div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="keywordflow">if</span> (denominator == 0.0)</div><div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keywordflow">return</span> (baseline_pt1_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>() + baseline_pt2_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>()) / 2.0;</div><div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordflow">return</span> baseline_pt1_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>() +</div><div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  (x - baseline_pt1_.<a class="code" href="a02681.html#aecd85311c159bcd52b485a97a8dcc901">x</a>()) * (baseline_pt2_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>() - baseline_pt1_.<a class="code" href="a02681.html#abb9516f874133b689b0e62ac70874385">y</a>()) /</div><div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  denominator;</div><div class="line"><a name="l00136"></a><span class="lineno"> 136</span> }</div><div class="line"><a name="l00137"></a><span class="lineno"> 137</span> </div><div class="line"><a name="l00138"></a><span class="lineno"> 138</span> <span class="comment">// Fits a straight baseline to the points. Returns true if it had enough</span></div><div class="line"><a name="l00139"></a><span class="lineno"> 139</span> <span class="comment">// points to be reasonably sure of the fitted baseline.</span></div><div class="line"><a name="l00140"></a><span class="lineno"> 140</span> <span class="comment">// If use_box_bottoms is false, baselines positions are formed by</span></div><div class="line"><a name="l00141"></a><span class="lineno"> 141</span> <span class="comment">// considering the outlines of the blobs.</span></div><div class="line"><a name="l00142"></a><span class="lineno"><a class="line" href="a04657.html#a0abf3f82fd5ab3b3a79a23a2c030547e"> 142</a></span> <span class="keywordtype">bool</span> <a class="code" href="a04657.html#a0abf3f82fd5ab3b3a79a23a2c030547e">BaselineRow::FitBaseline</a>(<span class="keywordtype">bool</span> use_box_bottoms) {</div><div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  <span class="comment">// Deterministic fitting is used wherever possible.</span></div><div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  fitter_.<a class="code" href="a02533.html#a97c074bfc1d7106ddda618ea8cf45ff7">Clear</a>();</div><div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  <span class="comment">// Linear least squares is a backup if the DetLineFit produces a bad line.</span></div><div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <a class="code" href="a02589.html">LLSQ</a> llsq;</div><div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  BLOBNBOX_IT blob_it(blobs_);</div><div class="line"><a name="l00148"></a><span class="lineno"> 148</span> </div><div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <span class="keywordflow">for</span> (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {</div><div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  <a class="code" href="a02481.html">BLOBNBOX</a>* blob = blob_it.data();</div><div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  <span class="keywordflow">if</span> (!use_box_bottoms) blob-><a class="code" href="a02481.html#a4ed2225c09f0ffbf08cb45ef6dbb40b4">EstimateBaselinePosition</a>();</div><div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <span class="keyword">const</span> <a class="code" href="a02713.html">TBOX</a>& box = blob-><a class="code" href="a02481.html#acc27a54c9735f05e9152ba5f1c1a8261">bounding_box</a>();</div><div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="keywordtype">int</span> x_middle = (box.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>() + box.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>()) / 2;</div><div class="line"><a name="l00154"></a><span class="lineno"> 154</span> <span class="preprocessor">#ifdef kDebugYCoord</span></div><div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  <span class="keywordflow">if</span> (box.<a class="code" href="a02713.html#ae20440e936439218b9dfe267b8a37b4a">bottom</a>() < kDebugYCoord && box.<a class="code" href="a02713.html#ac5ecdfbd33963eac601ccb67ac63dd2a">top</a>() > kDebugYCoord) {</div><div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Box bottom = %d, baseline pos=%d for box at:"</span>,</div><div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  box.<a class="code" href="a02713.html#ae20440e936439218b9dfe267b8a37b4a">bottom</a>(), blob-><a class="code" href="a02481.html#af5dd7efebd6cc0e393086d7eda8eb446">baseline_position</a>());</div><div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  box.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  }</div><div class="line"><a name="l00160"></a><span class="lineno"> 160</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00161"></a><span class="lineno"> 161</span>  fitter_.<a class="code" href="a02533.html#a4eba2b6e761080e5d1a48c9c797257b2">Add</a>(<a class="code" href="a02673.html">ICOORD</a>(x_middle, blob-><a class="code" href="a02481.html#af5dd7efebd6cc0e393086d7eda8eb446">baseline_position</a>()), box.<a class="code" href="a02713.html#aa51d4de109edfcba0508ce301da67031">width</a>() / 2);</div><div class="line"><a name="l00162"></a><span class="lineno"> 162</span>  llsq.<a class="code" href="a02589.html#aa439294be0539828cf042f8941125b3c">add</a>(x_middle, blob-><a class="code" href="a02481.html#af5dd7efebd6cc0e393086d7eda8eb446">baseline_position</a>());</div><div class="line"><a name="l00163"></a><span class="lineno"> 163</span>  }</div><div class="line"><a name="l00164"></a><span class="lineno"> 164</span>  <span class="comment">// Fit the line.</span></div><div class="line"><a name="l00165"></a><span class="lineno"> 165</span>  <a class="code" href="a02673.html">ICOORD</a> pt1, pt2;</div><div class="line"><a name="l00166"></a><span class="lineno"> 166</span>  baseline_error_ = fitter_.<a class="code" href="a02533.html#a768ec4a8f90593d8d679981c873f7a56">Fit</a>(&pt1, &pt2);</div><div class="line"><a name="l00167"></a><span class="lineno"> 167</span>  baseline_pt1_ = pt1;</div><div class="line"><a name="l00168"></a><span class="lineno"> 168</span>  baseline_pt2_ = pt2;</div><div class="line"><a name="l00169"></a><span class="lineno"> 169</span>  <span class="keywordflow">if</span> (baseline_error_ > max_baseline_error_ &&</div><div class="line"><a name="l00170"></a><span class="lineno"> 170</span>  fitter_.<a class="code" href="a02533.html#ac3f1ddb7945dc8b37ed69e64357276f6">SufficientPointsForIndependentFit</a>()) {</div><div class="line"><a name="l00171"></a><span class="lineno"> 171</span>  <span class="comment">// The fit was bad but there were plenty of points, so try skipping</span></div><div class="line"><a name="l00172"></a><span class="lineno"> 172</span>  <span class="comment">// the first and last few, and use the new line if it dramatically improves</span></div><div class="line"><a name="l00173"></a><span class="lineno"> 173</span>  <span class="comment">// the error of fit.</span></div><div class="line"><a name="l00174"></a><span class="lineno"> 174</span>  <span class="keywordtype">double</span> error = fitter_.<a class="code" href="a02533.html#a768ec4a8f90593d8d679981c873f7a56">Fit</a>(<a class="code" href="a01253.html#adaf423fe42f3ca4b3343020dc41c376b">kNumSkipPoints</a>, <a class="code" href="a01253.html#adaf423fe42f3ca4b3343020dc41c376b">kNumSkipPoints</a>, &pt1, &pt2);</div><div class="line"><a name="l00175"></a><span class="lineno"> 175</span>  <span class="keywordflow">if</span> (error < baseline_error_ / 2.0) {</div><div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  baseline_error_ = error;</div><div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  baseline_pt1_ = pt1;</div><div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  baseline_pt2_ = pt2;</div><div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  }</div><div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  }</div><div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  <span class="keywordtype">int</span> debug = 0;</div><div class="line"><a name="l00182"></a><span class="lineno"> 182</span> <span class="preprocessor">#ifdef kDebugYCoord</span></div><div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  <a class="code" href="a04657.html#a1b1af2359af16a1a44ec5dcf74114142">Print</a>();</div><div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  debug = bounding_box_.<a class="code" href="a02713.html#ae20440e936439218b9dfe267b8a37b4a">bottom</a>() < kDebugYCoord &&</div><div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  bounding_box_.<a class="code" href="a02713.html#ac5ecdfbd33963eac601ccb67ac63dd2a">top</a>() > kDebugYCoord</div><div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  ? 3 : 2;</div><div class="line"><a name="l00187"></a><span class="lineno"> 187</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  <span class="comment">// Now we obtained a direction from that fit, see if we can improve the</span></div><div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="comment">// fit using the same direction and some other start point.</span></div><div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <a class="code" href="a02681.html">FCOORD</a> <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>(pt2 - pt1);</div><div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  <span class="keywordtype">double</span> target_offset = <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a> * pt1;</div><div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  good_baseline_ = <span class="keyword">false</span>;</div><div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  FitConstrainedIfBetter(debug, <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>, 0.0, target_offset);</div><div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  <span class="comment">// Wild lines can be produced because DetLineFit allows vertical lines, but</span></div><div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  <span class="comment">// vertical text has been rotated so angles over pi/4 should be disallowed.</span></div><div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  <span class="comment">// Near vertical lines can still be produced by vertically aligned components</span></div><div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  <span class="comment">// on very short lines.</span></div><div class="line"><a name="l00198"></a><span class="lineno"> 198</span>  <span class="keywordtype">double</span> angle = <a class="code" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">BaselineAngle</a>();</div><div class="line"><a name="l00199"></a><span class="lineno"> 199</span>  <span class="keywordflow">if</span> (fabs(angle) > M_PI * 0.25) {</div><div class="line"><a name="l00200"></a><span class="lineno"> 200</span>  <span class="comment">// Use the llsq fit as a backup.</span></div><div class="line"><a name="l00201"></a><span class="lineno"> 201</span>  baseline_pt1_ = llsq.<a class="code" href="a02589.html#ae34cc080c9c8ee487b4a02f97b94d9f5">mean_point</a>();</div><div class="line"><a name="l00202"></a><span class="lineno"> 202</span>  baseline_pt2_ = baseline_pt1_ + <a class="code" href="a02681.html">FCOORD</a>(1.0f, llsq.<a class="code" href="a02589.html#a14be1135a936c540eea93455c19c70f1">m</a>());</div><div class="line"><a name="l00203"></a><span class="lineno"> 203</span>  <span class="comment">// TODO(rays) get rid of this when m and c are no longer used.</span></div><div class="line"><a name="l00204"></a><span class="lineno"> 204</span>  <span class="keywordtype">double</span> m = llsq.<a class="code" href="a02589.html#a14be1135a936c540eea93455c19c70f1">m</a>();</div><div class="line"><a name="l00205"></a><span class="lineno"> 205</span>  <span class="keywordtype">double</span> c = llsq.<a class="code" href="a02589.html#a4146a9ebd0a85858cec1df3a218ffada">c</a>(m);</div><div class="line"><a name="l00206"></a><span class="lineno"> 206</span>  baseline_error_ = llsq.<a class="code" href="a02589.html#a6139b78394a33f9447d84a575a10f471">rms</a>(m, c);</div><div class="line"><a name="l00207"></a><span class="lineno"> 207</span>  good_baseline_ = <span class="keyword">false</span>;</div><div class="line"><a name="l00208"></a><span class="lineno"> 208</span>  }</div><div class="line"><a name="l00209"></a><span class="lineno"> 209</span>  <span class="keywordflow">return</span> good_baseline_;</div><div class="line"><a name="l00210"></a><span class="lineno"> 210</span> }</div><div class="line"><a name="l00211"></a><span class="lineno"> 211</span> </div><div class="line"><a name="l00212"></a><span class="lineno"> 212</span> <span class="comment">// Modifies an existing result of FitBaseline to be parallel to the given</span></div><div class="line"><a name="l00213"></a><span class="lineno"> 213</span> <span class="comment">// direction vector if that produces a better result.</span></div><div class="line"><a name="l00214"></a><span class="lineno"><a class="line" href="a04657.html#a6907a2bb647448ef6ed5b6789b7e1440"> 214</a></span> <span class="keywordtype">void</span> <a class="code" href="a04657.html#a6907a2bb647448ef6ed5b6789b7e1440">BaselineRow::AdjustBaselineToParallel</a>(<span class="keywordtype">int</span> debug,</div><div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>) {</div><div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  SetupBlobDisplacements(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>);</div><div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  <span class="keywordflow">if</span> (displacement_modes_.<a class="code" href="a02297.html#a172c4aa23ba397e24319ae095281cbcc">empty</a>())</div><div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00219"></a><span class="lineno"> 219</span> <span class="preprocessor">#ifdef kDebugYCoord</span></div><div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  <span class="keywordflow">if</span> (bounding_box_.<a class="code" href="a02713.html#ae20440e936439218b9dfe267b8a37b4a">bottom</a>() < kDebugYCoord &&</div><div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  bounding_box_.<a class="code" href="a02713.html#ac5ecdfbd33963eac601ccb67ac63dd2a">top</a>() > kDebugYCoord && debug < 3)</div><div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  debug = 3;</div><div class="line"><a name="l00223"></a><span class="lineno"> 223</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  FitConstrainedIfBetter(debug, <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>, 0.0, displacement_modes_[0]);</div><div class="line"><a name="l00225"></a><span class="lineno"> 225</span> }</div><div class="line"><a name="l00226"></a><span class="lineno"> 226</span> </div><div class="line"><a name="l00227"></a><span class="lineno"> 227</span> <span class="comment">// Modifies the baseline to snap to the textline grid if the existing</span></div><div class="line"><a name="l00228"></a><span class="lineno"> 228</span> <span class="comment">// result is not good enough.</span></div><div class="line"><a name="l00229"></a><span class="lineno"><a class="line" href="a04657.html#ac81135eb24c3d936f7c1d9e81567cae8"> 229</a></span> <span class="keywordtype">double</span> <a class="code" href="a04657.html#ac81135eb24c3d936f7c1d9e81567cae8">BaselineRow::AdjustBaselineToGrid</a>(<span class="keywordtype">int</span> debug,</div><div class="line"><a name="l00230"></a><span class="lineno"> 230</span>  <span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>,</div><div class="line"><a name="l00231"></a><span class="lineno"> 231</span>  <span class="keywordtype">double</span> line_spacing,</div><div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  <span class="keywordtype">double</span> line_offset) {</div><div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  <span class="keywordflow">if</span> (blobs_->empty()) {</div><div class="line"><a name="l00234"></a><span class="lineno"> 234</span>  <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Row empty at:"</span>);</div><div class="line"><a name="l00236"></a><span class="lineno"> 236</span>  bounding_box_.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  }</div><div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  <span class="keywordflow">return</span> line_offset;</div><div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  }</div><div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  <span class="comment">// Find the displacement_modes_ entry nearest to the grid.</span></div><div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  <span class="keywordtype">double</span> best_error = 0.0;</div><div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  <span class="keywordtype">int</span> best_index = -1;</div><div class="line"><a name="l00243"></a><span class="lineno"> 243</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < displacement_modes_.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i) {</div><div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  <span class="keywordtype">double</span> blob_y = displacement_modes_[i];</div><div class="line"><a name="l00245"></a><span class="lineno"> 245</span>  <span class="keywordtype">double</span> error = <a class="code" href="a04661.html#ac12d056a2cc07b32b381d836126c4fa8">BaselineBlock::SpacingModelError</a>(blob_y, line_spacing,</div><div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  line_offset);</div><div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00248"></a><span class="lineno"> 248</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Mode at %g has error %g from model \n"</span>, blob_y, error);</div><div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  }</div><div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  <span class="keywordflow">if</span> (best_index < 0 || error < best_error) {</div><div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  best_error = error;</div><div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  best_index = i;</div><div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  }</div><div class="line"><a name="l00254"></a><span class="lineno"> 254</span>  }</div><div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  <span class="comment">// We will move the baseline only if the chosen mode is close enough to the</span></div><div class="line"><a name="l00256"></a><span class="lineno"> 256</span>  <span class="comment">// model.</span></div><div class="line"><a name="l00257"></a><span class="lineno"> 257</span>  <span class="keywordtype">double</span> model_margin = max_baseline_error_ - best_error;</div><div class="line"><a name="l00258"></a><span class="lineno"> 258</span>  <span class="keywordflow">if</span> (best_index >= 0 && model_margin > 0.0) {</div><div class="line"><a name="l00259"></a><span class="lineno"> 259</span>  <span class="comment">// But if the current baseline is already close to the mode there is no</span></div><div class="line"><a name="l00260"></a><span class="lineno"> 260</span>  <span class="comment">// point, and only the potential to damage accuracy by changing its angle.</span></div><div class="line"><a name="l00261"></a><span class="lineno"> 261</span>  <span class="keywordtype">double</span> perp_disp = <a class="code" href="a04657.html#a31f1ab3eb5a4d39c7956b9ad7fba07b0">PerpDisp</a>(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>);</div><div class="line"><a name="l00262"></a><span class="lineno"> 262</span>  <span class="keywordtype">double</span> shift = displacement_modes_[best_index] - perp_disp;</div><div class="line"><a name="l00263"></a><span class="lineno"> 263</span>  <span class="keywordflow">if</span> (fabs(shift) > max_baseline_error_) {</div><div class="line"><a name="l00264"></a><span class="lineno"> 264</span>  <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00265"></a><span class="lineno"> 265</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Attempting linespacing model fit with mode %g to row at:"</span>,</div><div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  displacement_modes_[best_index]);</div><div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  bounding_box_.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  }</div><div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  FitConstrainedIfBetter(debug, <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>, model_margin,</div><div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  displacement_modes_[best_index]);</div><div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Linespacing model only moves current line by %g for row at:"</span>,</div><div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  shift);</div><div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  bounding_box_.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  }</div><div class="line"><a name="l00276"></a><span class="lineno"> 276</span>  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Linespacing model not close enough to any mode for row at:"</span>);</div><div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  bounding_box_.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  }</div><div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  <span class="keywordflow">return</span> fmod(<a class="code" href="a04657.html#a31f1ab3eb5a4d39c7956b9ad7fba07b0">PerpDisp</a>(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>), line_spacing);</div><div class="line"><a name="l00281"></a><span class="lineno"> 281</span> }</div><div class="line"><a name="l00282"></a><span class="lineno"> 282</span> </div><div class="line"><a name="l00283"></a><span class="lineno"> 283</span> <span class="comment">// Sets up displacement_modes_ with the top few modes of the perpendicular</span></div><div class="line"><a name="l00284"></a><span class="lineno"> 284</span> <span class="comment">// distance of each blob from the given direction vector, after rounding.</span></div><div class="line"><a name="l00285"></a><span class="lineno"> 285</span> <span class="keywordtype">void</span> BaselineRow::SetupBlobDisplacements(<span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>) {</div><div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  <span class="comment">// Set of perpendicular displacements of the blob bottoms from the required</span></div><div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  <span class="comment">// baseline direction.</span></div><div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  <a class="code" href="a02297.html">GenericVector<double></a> perp_blob_dists;</div><div class="line"><a name="l00289"></a><span class="lineno"> 289</span>  displacement_modes_.<a class="code" href="a02297.html#a980882b5ebc3e72fdedbdbe345196f21">truncate</a>(0);</div><div class="line"><a name="l00290"></a><span class="lineno"> 290</span>  <span class="comment">// Gather the skew-corrected position of every blob.</span></div><div class="line"><a name="l00291"></a><span class="lineno"> 291</span>  <span class="keywordtype">double</span> min_dist = <a class="code" href="a00524.html#a9adcee815220ec9db98062213806ed04">MAX_FLOAT32</a>;</div><div class="line"><a name="l00292"></a><span class="lineno"> 292</span>  <span class="keywordtype">double</span> max_dist = -<a class="code" href="a00524.html#a9adcee815220ec9db98062213806ed04">MAX_FLOAT32</a>;</div><div class="line"><a name="l00293"></a><span class="lineno"> 293</span>  BLOBNBOX_IT blob_it(blobs_);</div><div class="line"><a name="l00294"></a><span class="lineno"> 294</span>  <span class="keywordtype">bool</span> debug = <span class="keyword">false</span>;</div><div class="line"><a name="l00295"></a><span class="lineno"> 295</span>  <span class="keywordflow">for</span> (blob_it.mark_cycle_pt(); !blob_it.cycled_list(); blob_it.forward()) {</div><div class="line"><a name="l00296"></a><span class="lineno"> 296</span>  <a class="code" href="a02481.html">BLOBNBOX</a>* blob = blob_it.data();</div><div class="line"><a name="l00297"></a><span class="lineno"> 297</span>  <span class="keyword">const</span> <a class="code" href="a02713.html">TBOX</a>& box = blob-><a class="code" href="a02481.html#acc27a54c9735f05e9152ba5f1c1a8261">bounding_box</a>();</div><div class="line"><a name="l00298"></a><span class="lineno"> 298</span> <span class="preprocessor">#ifdef kDebugYCoord</span></div><div class="line"><a name="l00299"></a><span class="lineno"> 299</span>  <span class="keywordflow">if</span> (box.<a class="code" href="a02713.html#ae20440e936439218b9dfe267b8a37b4a">bottom</a>() < kDebugYCoord && box.<a class="code" href="a02713.html#ac5ecdfbd33963eac601ccb67ac63dd2a">top</a>() > kDebugYCoord) debug = <span class="keyword">true</span>;</div><div class="line"><a name="l00300"></a><span class="lineno"> 300</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00301"></a><span class="lineno"> 301</span>  <a class="code" href="a02681.html">FCOORD</a> blob_pos((box.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>() + box.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>()) / 2.0f,</div><div class="line"><a name="l00302"></a><span class="lineno"> 302</span>  blob-><a class="code" href="a02481.html#af5dd7efebd6cc0e393086d7eda8eb446">baseline_position</a>());</div><div class="line"><a name="l00303"></a><span class="lineno"> 303</span>  <span class="keywordtype">double</span> offset = <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a> * blob_pos;</div><div class="line"><a name="l00304"></a><span class="lineno"> 304</span>  perp_blob_dists.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(offset);</div><div class="line"><a name="l00305"></a><span class="lineno"> 305</span>  <span class="keywordflow">if</span> (debug) {</div><div class="line"><a name="l00306"></a><span class="lineno"> 306</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Displacement %g for blob at:"</span>, offset);</div><div class="line"><a name="l00307"></a><span class="lineno"> 307</span>  box.<a class="code" href="a02713.html#a61af64df548c7638bf005fcd8343c435">print</a>();</div><div class="line"><a name="l00308"></a><span class="lineno"> 308</span>  }</div><div class="line"><a name="l00309"></a><span class="lineno"> 309</span>  <a class="code" href="a00521.html#a6eb00eb9bc5ed195953f334971c462ae">UpdateRange</a>(offset, &min_dist, &max_dist);</div><div class="line"><a name="l00310"></a><span class="lineno"> 310</span>  }</div><div class="line"><a name="l00311"></a><span class="lineno"> 311</span>  <span class="comment">// Set up a histogram using disp_quant_factor_ as the bucket size.</span></div><div class="line"><a name="l00312"></a><span class="lineno"> 312</span>  <a class="code" href="a02733.html">STATS</a> dist_stats(<a class="code" href="a00521.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(min_dist / disp_quant_factor_),</div><div class="line"><a name="l00313"></a><span class="lineno"> 313</span>  <a class="code" href="a00521.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(max_dist / disp_quant_factor_) + 1);</div><div class="line"><a name="l00314"></a><span class="lineno"> 314</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < perp_blob_dists.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i) {</div><div class="line"><a name="l00315"></a><span class="lineno"> 315</span>  dist_stats.add(<a class="code" href="a00521.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>(perp_blob_dists[i] / disp_quant_factor_), 1);</div><div class="line"><a name="l00316"></a><span class="lineno"> 316</span>  }</div><div class="line"><a name="l00317"></a><span class="lineno"> 317</span>  <a class="code" href="a02297.html">GenericVector<KDPairInc<float, int></a> > scaled_modes;</div><div class="line"><a name="l00318"></a><span class="lineno"> 318</span>  dist_stats.top_n_modes(<a class="code" href="a01253.html#a764108909ac86000da00e33ae249ff17">kMaxDisplacementsModes</a>, &scaled_modes);</div><div class="line"><a name="l00319"></a><span class="lineno"> 319</span>  <span class="keywordflow">if</span> (debug) {</div><div class="line"><a name="l00320"></a><span class="lineno"> 320</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < scaled_modes.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i) {</div><div class="line"><a name="l00321"></a><span class="lineno"> 321</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Top mode = %g * %d\n"</span>,</div><div class="line"><a name="l00322"></a><span class="lineno"> 322</span>  scaled_modes[i].key * disp_quant_factor_, scaled_modes[i].data);</div><div class="line"><a name="l00323"></a><span class="lineno"> 323</span>  }</div><div class="line"><a name="l00324"></a><span class="lineno"> 324</span>  }</div><div class="line"><a name="l00325"></a><span class="lineno"> 325</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < scaled_modes.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i)</div><div class="line"><a name="l00326"></a><span class="lineno"> 326</span>  displacement_modes_.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(disp_quant_factor_ * scaled_modes[i].key);</div><div class="line"><a name="l00327"></a><span class="lineno"> 327</span> }</div><div class="line"><a name="l00328"></a><span class="lineno"> 328</span> </div><div class="line"><a name="l00329"></a><span class="lineno"> 329</span> <span class="comment">// Fits a line in the given direction to blobs that are close to the given</span></div><div class="line"><a name="l00330"></a><span class="lineno"> 330</span> <span class="comment">// target_offset perpendicular displacement from the direction. The fit</span></div><div class="line"><a name="l00331"></a><span class="lineno"> 331</span> <span class="comment">// error is allowed to be cheat_allowance worse than the existing fit, and</span></div><div class="line"><a name="l00332"></a><span class="lineno"> 332</span> <span class="comment">// will still be used.</span></div><div class="line"><a name="l00333"></a><span class="lineno"> 333</span> <span class="comment">// If cheat_allowance > 0, the new fit will be good and replace the current</span></div><div class="line"><a name="l00334"></a><span class="lineno"> 334</span> <span class="comment">// fit if it has better fit (with cheat) OR its error is below</span></div><div class="line"><a name="l00335"></a><span class="lineno"> 335</span> <span class="comment">// max_baseline_error_ and the old fit is marked bad.</span></div><div class="line"><a name="l00336"></a><span class="lineno"> 336</span> <span class="comment">// Otherwise the new fit will only replace the old if it is really better,</span></div><div class="line"><a name="l00337"></a><span class="lineno"> 337</span> <span class="comment">// or the old fit is marked bad and the new fit has sufficient points, as</span></div><div class="line"><a name="l00338"></a><span class="lineno"> 338</span> <span class="comment">// well as being within the max_baseline_error_.</span></div><div class="line"><a name="l00339"></a><span class="lineno"> 339</span> <span class="keywordtype">void</span> BaselineRow::FitConstrainedIfBetter(<span class="keywordtype">int</span> debug,</div><div class="line"><a name="l00340"></a><span class="lineno"> 340</span>  <span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>,</div><div class="line"><a name="l00341"></a><span class="lineno"> 341</span>  <span class="keywordtype">double</span> cheat_allowance,</div><div class="line"><a name="l00342"></a><span class="lineno"> 342</span>  <span class="keywordtype">double</span> target_offset) {</div><div class="line"><a name="l00343"></a><span class="lineno"> 343</span>  <span class="keywordtype">double</span> halfrange = fit_halfrange_ * <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>.length();</div><div class="line"><a name="l00344"></a><span class="lineno"> 344</span>  <span class="keywordtype">double</span> min_dist = target_offset - halfrange;</div><div class="line"><a name="l00345"></a><span class="lineno"> 345</span>  <span class="keywordtype">double</span> max_dist = target_offset + halfrange;</div><div class="line"><a name="l00346"></a><span class="lineno"> 346</span>  <a class="code" href="a02673.html">ICOORD</a> line_pt;</div><div class="line"><a name="l00347"></a><span class="lineno"> 347</span>  <span class="keywordtype">double</span> new_error = fitter_.<a class="code" href="a02533.html#a6ef9f742eafdfaad81a30a3799800725">ConstrainedFit</a>(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>, min_dist, max_dist,</div><div class="line"><a name="l00348"></a><span class="lineno"> 348</span>  debug > 2, &line_pt);</div><div class="line"><a name="l00349"></a><span class="lineno"> 349</span>  <span class="comment">// Allow cheat_allowance off the new error</span></div><div class="line"><a name="l00350"></a><span class="lineno"> 350</span>  new_error -= cheat_allowance;</div><div class="line"><a name="l00351"></a><span class="lineno"> 351</span>  <span class="keywordtype">double</span> old_angle = <a class="code" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">BaselineAngle</a>();</div><div class="line"><a name="l00352"></a><span class="lineno"> 352</span>  <span class="keywordtype">double</span> new_angle = <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>.angle();</div><div class="line"><a name="l00353"></a><span class="lineno"> 353</span>  <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00354"></a><span class="lineno"> 354</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Constrained error = %g, original = %g"</span>,</div><div class="line"><a name="l00355"></a><span class="lineno"> 355</span>  new_error, baseline_error_);</div><div class="line"><a name="l00356"></a><span class="lineno"> 356</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">" angles = %g, %g, delta=%g vs threshold %g\n"</span>,</div><div class="line"><a name="l00357"></a><span class="lineno"> 357</span>  old_angle, new_angle,</div><div class="line"><a name="l00358"></a><span class="lineno"> 358</span>  new_angle - old_angle, <a class="code" href="a01253.html#aa447e3d51461981e8e7c5450e57d9300">kMaxSkewDeviation</a>);</div><div class="line"><a name="l00359"></a><span class="lineno"> 359</span>  }</div><div class="line"><a name="l00360"></a><span class="lineno"> 360</span>  <span class="keywordtype">bool</span> new_good_baseline = new_error <= max_baseline_error_ &&</div><div class="line"><a name="l00361"></a><span class="lineno"> 361</span>  (cheat_allowance > 0.0 || fitter_.<a class="code" href="a02533.html#ac3f1ddb7945dc8b37ed69e64357276f6">SufficientPointsForIndependentFit</a>());</div><div class="line"><a name="l00362"></a><span class="lineno"> 362</span>  <span class="comment">// The new will replace the old if any are true:</span></div><div class="line"><a name="l00363"></a><span class="lineno"> 363</span>  <span class="comment">// 1. the new error is better</span></div><div class="line"><a name="l00364"></a><span class="lineno"> 364</span>  <span class="comment">// 2. the old is NOT good, but the new is</span></div><div class="line"><a name="l00365"></a><span class="lineno"> 365</span>  <span class="comment">// 3. there is a wild angular difference between them (assuming that the new</span></div><div class="line"><a name="l00366"></a><span class="lineno"> 366</span>  <span class="comment">// is a better guess at the angle.)</span></div><div class="line"><a name="l00367"></a><span class="lineno"> 367</span>  <span class="keywordflow">if</span> (new_error <= baseline_error_ ||</div><div class="line"><a name="l00368"></a><span class="lineno"> 368</span>  (!good_baseline_ && new_good_baseline) ||</div><div class="line"><a name="l00369"></a><span class="lineno"> 369</span>  fabs(new_angle - old_angle) > <a class="code" href="a01253.html#aa447e3d51461981e8e7c5450e57d9300">kMaxSkewDeviation</a>) {</div><div class="line"><a name="l00370"></a><span class="lineno"> 370</span>  baseline_error_ = new_error;</div><div class="line"><a name="l00371"></a><span class="lineno"> 371</span>  baseline_pt1_ = line_pt;</div><div class="line"><a name="l00372"></a><span class="lineno"> 372</span>  baseline_pt2_ = baseline_pt1_ + <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>;</div><div class="line"><a name="l00373"></a><span class="lineno"> 373</span>  good_baseline_ = new_good_baseline;</div><div class="line"><a name="l00374"></a><span class="lineno"> 374</span>  <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00375"></a><span class="lineno"> 375</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Replacing with constrained baseline, good = %d\n"</span>,</div><div class="line"><a name="l00376"></a><span class="lineno"> 376</span>  good_baseline_);</div><div class="line"><a name="l00377"></a><span class="lineno"> 377</span>  }</div><div class="line"><a name="l00378"></a><span class="lineno"> 378</span>  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (debug > 1) {</div><div class="line"><a name="l00379"></a><span class="lineno"> 379</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Keeping old baseline\n"</span>);</div><div class="line"><a name="l00380"></a><span class="lineno"> 380</span>  }</div><div class="line"><a name="l00381"></a><span class="lineno"> 381</span> }</div><div class="line"><a name="l00382"></a><span class="lineno"> 382</span> </div><div class="line"><a name="l00383"></a><span class="lineno"> 383</span> <span class="comment">// Returns the perpendicular distance of the point from the straight</span></div><div class="line"><a name="l00384"></a><span class="lineno"> 384</span> <span class="comment">// baseline.</span></div><div class="line"><a name="l00385"></a><span class="lineno"> 385</span> <span class="keywordtype">double</span> BaselineRow::PerpDistanceFromBaseline(<span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& pt)<span class="keyword"> const </span>{</div><div class="line"><a name="l00386"></a><span class="lineno"> 386</span>  <a class="code" href="a02681.html">FCOORD</a> baseline_vector(baseline_pt2_ - baseline_pt1_);</div><div class="line"><a name="l00387"></a><span class="lineno"> 387</span>  <a class="code" href="a02681.html">FCOORD</a> offset_vector(pt - baseline_pt1_);</div><div class="line"><a name="l00388"></a><span class="lineno"> 388</span>  <span class="keywordtype">double</span> distance = baseline_vector * offset_vector;</div><div class="line"><a name="l00389"></a><span class="lineno"> 389</span>  <span class="keywordflow">return</span> sqrt(distance * distance / baseline_vector.sqlength());</div><div class="line"><a name="l00390"></a><span class="lineno"> 390</span> }</div><div class="line"><a name="l00391"></a><span class="lineno"> 391</span> </div><div class="line"><a name="l00392"></a><span class="lineno"> 392</span> <span class="comment">// Computes the bounding box of the row.</span></div><div class="line"><a name="l00393"></a><span class="lineno"> 393</span> <span class="keywordtype">void</span> BaselineRow::ComputeBoundingBox() {</div><div class="line"><a name="l00394"></a><span class="lineno"> 394</span>  BLOBNBOX_IT it(blobs_);</div><div class="line"><a name="l00395"></a><span class="lineno"> 395</span>  <a class="code" href="a02713.html">TBOX</a> box;</div><div class="line"><a name="l00396"></a><span class="lineno"> 396</span>  <span class="keywordflow">for</span> (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {</div><div class="line"><a name="l00397"></a><span class="lineno"> 397</span>  box += it.data()->bounding_box();</div><div class="line"><a name="l00398"></a><span class="lineno"> 398</span>  }</div><div class="line"><a name="l00399"></a><span class="lineno"> 399</span>  bounding_box_ = box;</div><div class="line"><a name="l00400"></a><span class="lineno"> 400</span> }</div><div class="line"><a name="l00401"></a><span class="lineno"> 401</span> </div><div class="line"><a name="l00402"></a><span class="lineno"> 402</span> </div><div class="line"><a name="l00403"></a><span class="lineno"><a class="line" href="a04661.html#a4866856efe373c4b48769899e38846b6"> 403</a></span> <a class="code" href="a04661.html#a4866856efe373c4b48769899e38846b6">BaselineBlock::BaselineBlock</a>(<span class="keywordtype">int</span> debug_level, <span class="keywordtype">bool</span> non_text, <a class="code" href="a02489.html">TO_BLOCK</a>* block)</div><div class="line"><a name="l00404"></a><span class="lineno"> 404</span>  : block_(block), debug_level_(debug_level), non_text_block_(non_text),</div><div class="line"><a name="l00405"></a><span class="lineno"> 405</span>  good_skew_angle_(false), skew_angle_(0.0),</div><div class="line"><a name="l00406"></a><span class="lineno"> 406</span>  line_spacing_(block->line_spacing), line_offset_(0.0), model_error_(0.0) {</div><div class="line"><a name="l00407"></a><span class="lineno"> 407</span>  TO_ROW_IT row_it(block_-><a class="code" href="a02489.html#a4846ebdcc832b4b0a762d87c0d83a056">get_rows</a>());</div><div class="line"><a name="l00408"></a><span class="lineno"> 408</span>  <span class="keywordflow">for</span> (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {</div><div class="line"><a name="l00409"></a><span class="lineno"> 409</span>  <span class="comment">// Sort the blobs on the rows.</span></div><div class="line"><a name="l00410"></a><span class="lineno"> 410</span>  row_it.data()->blob_list()->sort(<a class="code" href="a01373.html#a71e57df4cbaf6a0d8fb156f0604d1033">blob_x_order</a>);</div><div class="line"><a name="l00411"></a><span class="lineno"> 411</span>  rows_.push_back(<span class="keyword">new</span> <a class="code" href="a04657.html">BaselineRow</a>(<a class="code" href="a04661.html#a381942ef00fcff77a75d036fac9b3fa5">block</a>-><a class="code" href="a02489.html#ac17b9c95641b2eebee9d972338c2e5f6">line_spacing</a>, row_it.data()));</div><div class="line"><a name="l00412"></a><span class="lineno"> 412</span>  }</div><div class="line"><a name="l00413"></a><span class="lineno"> 413</span> }</div><div class="line"><a name="l00414"></a><span class="lineno"> 414</span> </div><div class="line"><a name="l00415"></a><span class="lineno"> 415</span> <span class="comment">// Computes and returns the absolute error of the given perp_disp from the</span></div><div class="line"><a name="l00416"></a><span class="lineno"> 416</span> <span class="comment">// given linespacing model.</span></div><div class="line"><a name="l00417"></a><span class="lineno"><a class="line" href="a04661.html#ac12d056a2cc07b32b381d836126c4fa8"> 417</a></span> <span class="keywordtype">double</span> <a class="code" href="a04661.html#ac12d056a2cc07b32b381d836126c4fa8">BaselineBlock::SpacingModelError</a>(<span class="keywordtype">double</span> perp_disp, <span class="keywordtype">double</span> line_spacing,</div><div class="line"><a name="l00418"></a><span class="lineno"> 418</span>  <span class="keywordtype">double</span> line_offset) {</div><div class="line"><a name="l00419"></a><span class="lineno"> 419</span>  <span class="comment">// Round to the nearest multiple of line_spacing + line offset.</span></div><div class="line"><a name="l00420"></a><span class="lineno"> 420</span>  <span class="keywordtype">int</span> multiple = <a class="code" href="a00521.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>((perp_disp - line_offset) / line_spacing);</div><div class="line"><a name="l00421"></a><span class="lineno"> 421</span>  <span class="keywordtype">double</span> model_y = line_spacing * multiple + line_offset;</div><div class="line"><a name="l00422"></a><span class="lineno"> 422</span>  <span class="keywordflow">return</span> fabs(perp_disp - model_y);</div><div class="line"><a name="l00423"></a><span class="lineno"> 423</span> }</div><div class="line"><a name="l00424"></a><span class="lineno"> 424</span> </div><div class="line"><a name="l00425"></a><span class="lineno"> 425</span> <span class="comment">// Fits straight line baselines and computes the skew angle from the</span></div><div class="line"><a name="l00426"></a><span class="lineno"> 426</span> <span class="comment">// median angle. Returns true if a good angle is found.</span></div><div class="line"><a name="l00427"></a><span class="lineno"> 427</span> <span class="comment">// If use_box_bottoms is false, baseline positions are formed by</span></div><div class="line"><a name="l00428"></a><span class="lineno"> 428</span> <span class="comment">// considering the outlines of the blobs.</span></div><div class="line"><a name="l00429"></a><span class="lineno"><a class="line" href="a04661.html#a1e27f4aaf66c7e7aae4062c590fd8f3f"> 429</a></span> <span class="keywordtype">bool</span> <a class="code" href="a04661.html#a1e27f4aaf66c7e7aae4062c590fd8f3f">BaselineBlock::FitBaselinesAndFindSkew</a>(<span class="keywordtype">bool</span> use_box_bottoms) {</div><div class="line"><a name="l00430"></a><span class="lineno"> 430</span>  <span class="keywordflow">if</span> (non_text_block_) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00431"></a><span class="lineno"> 431</span>  <a class="code" href="a02297.html">GenericVector<double></a> angles;</div><div class="line"><a name="l00432"></a><span class="lineno"> 432</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < rows_.size(); ++r) {</div><div class="line"><a name="l00433"></a><span class="lineno"> 433</span>  <a class="code" href="a04657.html">BaselineRow</a>* row = rows_[r];</div><div class="line"><a name="l00434"></a><span class="lineno"> 434</span>  <span class="keywordflow">if</span> (row-><a class="code" href="a04657.html#a0abf3f82fd5ab3b3a79a23a2c030547e">FitBaseline</a>(use_box_bottoms)) {</div><div class="line"><a name="l00435"></a><span class="lineno"> 435</span>  <span class="keywordtype">double</span> angle = row-><a class="code" href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">BaselineAngle</a>();</div><div class="line"><a name="l00436"></a><span class="lineno"> 436</span>  angles.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(angle);</div><div class="line"><a name="l00437"></a><span class="lineno"> 437</span>  }</div><div class="line"><a name="l00438"></a><span class="lineno"> 438</span>  <span class="keywordflow">if</span> (debug_level_ > 1)</div><div class="line"><a name="l00439"></a><span class="lineno"> 439</span>  row-><a class="code" href="a04657.html#a1b1af2359af16a1a44ec5dcf74114142">Print</a>();</div><div class="line"><a name="l00440"></a><span class="lineno"> 440</span>  }</div><div class="line"><a name="l00441"></a><span class="lineno"> 441</span> </div><div class="line"><a name="l00442"></a><span class="lineno"> 442</span>  <span class="keywordflow">if</span> (!angles.<a class="code" href="a02297.html#a172c4aa23ba397e24319ae095281cbcc">empty</a>()) {</div><div class="line"><a name="l00443"></a><span class="lineno"> 443</span>  skew_angle_ = <a class="code" href="a00290.html#abde6267e843aeeea5089d458c465dee2">MedianOfCircularValues</a>(M_PI, &angles);</div><div class="line"><a name="l00444"></a><span class="lineno"> 444</span>  good_skew_angle_ = <span class="keyword">true</span>;</div><div class="line"><a name="l00445"></a><span class="lineno"> 445</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00446"></a><span class="lineno"> 446</span>  skew_angle_ = 0.0f;</div><div class="line"><a name="l00447"></a><span class="lineno"> 447</span>  good_skew_angle_ = <span class="keyword">false</span>;</div><div class="line"><a name="l00448"></a><span class="lineno"> 448</span>  }</div><div class="line"><a name="l00449"></a><span class="lineno"> 449</span>  <span class="keywordflow">if</span> (debug_level_ > 0) {</div><div class="line"><a name="l00450"></a><span class="lineno"> 450</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Initial block skew angle = %g, good = %d\n"</span>,</div><div class="line"><a name="l00451"></a><span class="lineno"> 451</span>  skew_angle_, good_skew_angle_);</div><div class="line"><a name="l00452"></a><span class="lineno"> 452</span>  }</div><div class="line"><a name="l00453"></a><span class="lineno"> 453</span>  <span class="keywordflow">return</span> good_skew_angle_;</div><div class="line"><a name="l00454"></a><span class="lineno"> 454</span> }</div><div class="line"><a name="l00455"></a><span class="lineno"> 455</span> </div><div class="line"><a name="l00456"></a><span class="lineno"> 456</span> <span class="comment">// Refits the baseline to a constrained angle, using the stored block</span></div><div class="line"><a name="l00457"></a><span class="lineno"> 457</span> <span class="comment">// skew if good enough, otherwise the supplied default skew.</span></div><div class="line"><a name="l00458"></a><span class="lineno"><a class="line" href="a04661.html#a8a7ab56dd7abc0421cff9680b6634b85"> 458</a></span> <span class="keywordtype">void</span> <a class="code" href="a04661.html#a8a7ab56dd7abc0421cff9680b6634b85">BaselineBlock::ParallelizeBaselines</a>(<span class="keywordtype">double</span> default_block_skew) {</div><div class="line"><a name="l00459"></a><span class="lineno"> 459</span>  <span class="keywordflow">if</span> (non_text_block_) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00460"></a><span class="lineno"> 460</span>  <span class="keywordflow">if</span> (!good_skew_angle_) skew_angle_ = default_block_skew;</div><div class="line"><a name="l00461"></a><span class="lineno"> 461</span>  <span class="keywordflow">if</span> (debug_level_ > 0)</div><div class="line"><a name="l00462"></a><span class="lineno"> 462</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Adjusting block to skew angle %g\n"</span>, skew_angle_);</div><div class="line"><a name="l00463"></a><span class="lineno"> 463</span>  <a class="code" href="a02681.html">FCOORD</a> <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>(cos(skew_angle_), sin(skew_angle_));</div><div class="line"><a name="l00464"></a><span class="lineno"> 464</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < rows_.size(); ++r) {</div><div class="line"><a name="l00465"></a><span class="lineno"> 465</span>  <a class="code" href="a04657.html">BaselineRow</a>* row = rows_[r];</div><div class="line"><a name="l00466"></a><span class="lineno"> 466</span>  row-><a class="code" href="a04657.html#a6907a2bb647448ef6ed5b6789b7e1440">AdjustBaselineToParallel</a>(debug_level_, <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>);</div><div class="line"><a name="l00467"></a><span class="lineno"> 467</span>  <span class="keywordflow">if</span> (debug_level_ > 1)</div><div class="line"><a name="l00468"></a><span class="lineno"> 468</span>  row-><a class="code" href="a04657.html#a1b1af2359af16a1a44ec5dcf74114142">Print</a>();</div><div class="line"><a name="l00469"></a><span class="lineno"> 469</span>  }</div><div class="line"><a name="l00470"></a><span class="lineno"> 470</span>  <span class="keywordflow">if</span> (rows_.size() < 3 || !ComputeLineSpacing())</div><div class="line"><a name="l00471"></a><span class="lineno"> 471</span>  <span class="keywordflow">return</span>;</div><div class="line"><a name="l00472"></a><span class="lineno"> 472</span>  <span class="comment">// Enforce the line spacing model on all lines that don't yet have a good</span></div><div class="line"><a name="l00473"></a><span class="lineno"> 473</span>  <span class="comment">// baseline.</span></div><div class="line"><a name="l00474"></a><span class="lineno"> 474</span>  <span class="comment">// Start by finding the row that is best fitted to the model.</span></div><div class="line"><a name="l00475"></a><span class="lineno"> 475</span>  <span class="keywordtype">int</span> best_row = 0;</div><div class="line"><a name="l00476"></a><span class="lineno"> 476</span>  <span class="keywordtype">double</span> best_error = <a class="code" href="a04661.html#ac12d056a2cc07b32b381d836126c4fa8">SpacingModelError</a>(rows_[0]->PerpDisp(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>),</div><div class="line"><a name="l00477"></a><span class="lineno"> 477</span>  line_spacing_, line_offset_);</div><div class="line"><a name="l00478"></a><span class="lineno"> 478</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 1; r < rows_.size(); ++r) {</div><div class="line"><a name="l00479"></a><span class="lineno"> 479</span>  <span class="keywordtype">double</span> error = <a class="code" href="a04661.html#ac12d056a2cc07b32b381d836126c4fa8">SpacingModelError</a>(rows_[r]->PerpDisp(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>),</div><div class="line"><a name="l00480"></a><span class="lineno"> 480</span>  line_spacing_, line_offset_);</div><div class="line"><a name="l00481"></a><span class="lineno"> 481</span>  <span class="keywordflow">if</span> (error < best_error) {</div><div class="line"><a name="l00482"></a><span class="lineno"> 482</span>  best_error = error;</div><div class="line"><a name="l00483"></a><span class="lineno"> 483</span>  best_row = r;</div><div class="line"><a name="l00484"></a><span class="lineno"> 484</span>  }</div><div class="line"><a name="l00485"></a><span class="lineno"> 485</span>  }</div><div class="line"><a name="l00486"></a><span class="lineno"> 486</span>  <span class="comment">// Starting at the best fitting row, work outwards, syncing the offset.</span></div><div class="line"><a name="l00487"></a><span class="lineno"> 487</span>  <span class="keywordtype">double</span> offset = line_offset_;</div><div class="line"><a name="l00488"></a><span class="lineno"> 488</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = best_row + 1; r < rows_.size(); ++r) {</div><div class="line"><a name="l00489"></a><span class="lineno"> 489</span>  offset = rows_[r]->AdjustBaselineToGrid(debug_level_, <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>,</div><div class="line"><a name="l00490"></a><span class="lineno"> 490</span>  line_spacing_, offset);</div><div class="line"><a name="l00491"></a><span class="lineno"> 491</span>  }</div><div class="line"><a name="l00492"></a><span class="lineno"> 492</span>  offset = line_offset_;</div><div class="line"><a name="l00493"></a><span class="lineno"> 493</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = best_row - 1; r >= 0; --r) {</div><div class="line"><a name="l00494"></a><span class="lineno"> 494</span>  offset = rows_[r]->AdjustBaselineToGrid(debug_level_, <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>,</div><div class="line"><a name="l00495"></a><span class="lineno"> 495</span>  line_spacing_, offset);</div><div class="line"><a name="l00496"></a><span class="lineno"> 496</span>  }</div><div class="line"><a name="l00497"></a><span class="lineno"> 497</span> }</div><div class="line"><a name="l00498"></a><span class="lineno"> 498</span> </div><div class="line"><a name="l00499"></a><span class="lineno"> 499</span> <span class="comment">// Sets the parameters in TO_BLOCK that are needed by subsequent processes.</span></div><div class="line"><a name="l00500"></a><span class="lineno"><a class="line" href="a04661.html#a0619e15482a4ed11dce15bc5d8cbe0be"> 500</a></span> <span class="keywordtype">void</span> <a class="code" href="a04661.html#a0619e15482a4ed11dce15bc5d8cbe0be">BaselineBlock::SetupBlockParameters</a>()<span class="keyword"> const </span>{</div><div class="line"><a name="l00501"></a><span class="lineno"> 501</span>  <span class="keywordflow">if</span> (line_spacing_ > 0.0) {</div><div class="line"><a name="l00502"></a><span class="lineno"> 502</span>  <span class="comment">// Where was block_line_spacing set before?</span></div><div class="line"><a name="l00503"></a><span class="lineno"> 503</span>  <span class="keywordtype">float</span> min_spacing = <a class="code" href="a00548.html#a74e75242132eaabbc1c512488a135926">MIN</a>(block_-><a class="code" href="a02489.html#ac17b9c95641b2eebee9d972338c2e5f6">line_spacing</a>, line_spacing_);</div><div class="line"><a name="l00504"></a><span class="lineno"> 504</span>  <span class="keywordflow">if</span> (min_spacing < block_->line_size)</div><div class="line"><a name="l00505"></a><span class="lineno"> 505</span>  block_-><a class="code" href="a02489.html#ab106233da0599f3e1595c1c765acadec">line_size</a> = min_spacing;</div><div class="line"><a name="l00506"></a><span class="lineno"> 506</span>  block_-><a class="code" href="a02489.html#ac17b9c95641b2eebee9d972338c2e5f6">line_spacing</a> = line_spacing_;</div><div class="line"><a name="l00507"></a><span class="lineno"> 507</span>  block_-><a class="code" href="a02489.html#abb8334b4a0c2b2625516a1c4b54cbf1f">baseline_offset</a> = line_offset_;</div><div class="line"><a name="l00508"></a><span class="lineno"> 508</span>  block_-><a class="code" href="a02489.html#abda136ff240577928343ca37453aca7a">max_blob_size</a> = line_spacing_ * <a class="code" href="a01253.html#a46b90f606788891fac29c14f20f39b27">kMaxBlobSizeMultiple</a>;</div><div class="line"><a name="l00509"></a><span class="lineno"> 509</span>  }</div><div class="line"><a name="l00510"></a><span class="lineno"> 510</span>  <span class="comment">// Setup the parameters on all the rows.</span></div><div class="line"><a name="l00511"></a><span class="lineno"> 511</span>  TO_ROW_IT row_it(block_-><a class="code" href="a02489.html#a4846ebdcc832b4b0a762d87c0d83a056">get_rows</a>());</div><div class="line"><a name="l00512"></a><span class="lineno"> 512</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < rows_.size(); ++r, row_it.forward()) {</div><div class="line"><a name="l00513"></a><span class="lineno"> 513</span>  <a class="code" href="a04657.html">BaselineRow</a>* row = rows_[r];</div><div class="line"><a name="l00514"></a><span class="lineno"> 514</span>  <a class="code" href="a02485.html">TO_ROW</a>* to_row = row_it.data();</div><div class="line"><a name="l00515"></a><span class="lineno"> 515</span>  row-><a class="code" href="a04657.html#adb63829f17ab14cfea6215b64ecf589e">SetupOldLineParameters</a>(to_row);</div><div class="line"><a name="l00516"></a><span class="lineno"> 516</span>  }</div><div class="line"><a name="l00517"></a><span class="lineno"> 517</span> }</div><div class="line"><a name="l00518"></a><span class="lineno"> 518</span> </div><div class="line"><a name="l00519"></a><span class="lineno"> 519</span> <span class="comment">// Processing that is required before fitting baseline splines, but requires</span></div><div class="line"><a name="l00520"></a><span class="lineno"> 520</span> <span class="comment">// linear baselines in order to be successful:</span></div><div class="line"><a name="l00521"></a><span class="lineno"> 521</span> <span class="comment">// Removes noise if required</span></div><div class="line"><a name="l00522"></a><span class="lineno"> 522</span> <span class="comment">// Separates out underlines</span></div><div class="line"><a name="l00523"></a><span class="lineno"> 523</span> <span class="comment">// Pre-associates blob fragments.</span></div><div class="line"><a name="l00524"></a><span class="lineno"> 524</span> <span class="comment">// TODO(rays/joeliu) This entire section of code is inherited from the past</span></div><div class="line"><a name="l00525"></a><span class="lineno"> 525</span> <span class="comment">// and could be improved/eliminated.</span></div><div class="line"><a name="l00526"></a><span class="lineno"> 526</span> <span class="comment">// page_tr is used to size a debug window.</span></div><div class="line"><a name="l00527"></a><span class="lineno"><a class="line" href="a04661.html#ab6e80c4b218c94c056659659a4d5e59b"> 527</a></span> <span class="keywordtype">void</span> <a class="code" href="a04661.html#ab6e80c4b218c94c056659659a4d5e59b">BaselineBlock::PrepareForSplineFitting</a>(<a class="code" href="a02673.html">ICOORD</a> page_tr, <span class="keywordtype">bool</span> remove_noise) {</div><div class="line"><a name="l00528"></a><span class="lineno"> 528</span>  <span class="keywordflow">if</span> (non_text_block_) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00529"></a><span class="lineno"> 529</span>  <span class="keywordflow">if</span> (remove_noise) {</div><div class="line"><a name="l00530"></a><span class="lineno"> 530</span>  <a class="code" href="a01373.html#ae71e721bb9641f221b30021a5addff82">vigorous_noise_removal</a>(block_);</div><div class="line"><a name="l00531"></a><span class="lineno"> 531</span>  }</div><div class="line"><a name="l00532"></a><span class="lineno"> 532</span>  <a class="code" href="a02681.html">FCOORD</a> rotation(1.0f, 0.0f);</div><div class="line"><a name="l00533"></a><span class="lineno"> 533</span>  <span class="keywordtype">double</span> gradient = tan(skew_angle_);</div><div class="line"><a name="l00534"></a><span class="lineno"> 534</span>  <a class="code" href="a01373.html#a004e5d894712f552369ef523a09bc3ce">separate_underlines</a>(block_, gradient, rotation, <span class="keyword">true</span>);</div><div class="line"><a name="l00535"></a><span class="lineno"> 535</span>  <a class="code" href="a01373.html#a8a932e3bd44fc2fc6fbdc291cdc9b942">pre_associate_blobs</a>(page_tr, block_, rotation, <span class="keyword">true</span>);</div><div class="line"><a name="l00536"></a><span class="lineno"> 536</span> }</div><div class="line"><a name="l00537"></a><span class="lineno"> 537</span> </div><div class="line"><a name="l00538"></a><span class="lineno"> 538</span> <span class="comment">// Fits splines to the textlines, or creates fake QSPLINES from the straight</span></div><div class="line"><a name="l00539"></a><span class="lineno"> 539</span> <span class="comment">// baselines that are already on the TO_ROWs.</span></div><div class="line"><a name="l00540"></a><span class="lineno"> 540</span> <span class="comment">// As a side-effect, computes the xheights of the rows and the block.</span></div><div class="line"><a name="l00541"></a><span class="lineno"> 541</span> <span class="comment">// Although x-height estimation is conceptually separate, it is part of</span></div><div class="line"><a name="l00542"></a><span class="lineno"> 542</span> <span class="comment">// detecting perspective distortion and therefore baseline fitting.</span></div><div class="line"><a name="l00543"></a><span class="lineno"><a class="line" href="a04661.html#a198bcc873e579e4798f4a8ed82fdb543"> 543</a></span> <span class="keywordtype">void</span> <a class="code" href="a04661.html#a198bcc873e579e4798f4a8ed82fdb543">BaselineBlock::FitBaselineSplines</a>(<span class="keywordtype">bool</span> enable_splines,</div><div class="line"><a name="l00544"></a><span class="lineno"> 544</span>  <span class="keywordtype">bool</span> show_final_rows,</div><div class="line"><a name="l00545"></a><span class="lineno"> 545</span>  <a class="code" href="a04841.html">Textord</a>* textord) {</div><div class="line"><a name="l00546"></a><span class="lineno"> 546</span>  <span class="keywordtype">double</span> gradient = tan(skew_angle_);</div><div class="line"><a name="l00547"></a><span class="lineno"> 547</span>  <a class="code" href="a02681.html">FCOORD</a> rotation(1.0f, 0.0f);</div><div class="line"><a name="l00548"></a><span class="lineno"> 548</span> </div><div class="line"><a name="l00549"></a><span class="lineno"> 549</span>  <span class="keywordflow">if</span> (enable_splines) {</div><div class="line"><a name="l00550"></a><span class="lineno"> 550</span>  textord-><a class="code" href="a04841.html#a3c5b9cc1053a9abd5fad5d7eca25186b">make_spline_rows</a>(block_, gradient, show_final_rows);</div><div class="line"><a name="l00551"></a><span class="lineno"> 551</span>  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00552"></a><span class="lineno"> 552</span>  <span class="comment">// Make a fake spline from the existing line.</span></div><div class="line"><a name="l00553"></a><span class="lineno"> 553</span>  <a class="code" href="a02713.html">TBOX</a> block_box= block_-><a class="code" href="a02489.html#a16e698664028b0d6d2193db64560c16b">block</a>-><a class="code" href="a02661.html#a3f06f8e34fc5962f342daff9623463e9">bounding_box</a>();</div><div class="line"><a name="l00554"></a><span class="lineno"> 554</span>  TO_ROW_IT row_it = block_-><a class="code" href="a02489.html#a4846ebdcc832b4b0a762d87c0d83a056">get_rows</a>();</div><div class="line"><a name="l00555"></a><span class="lineno"> 555</span>  <span class="keywordflow">for</span> (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {</div><div class="line"><a name="l00556"></a><span class="lineno"> 556</span>  <a class="code" href="a02485.html">TO_ROW</a>* row = row_it.data();</div><div class="line"><a name="l00557"></a><span class="lineno"> 557</span>  <a class="code" href="a00524.html#aba1f582fd0168f3ff9225d8c90fa9eb8">inT32</a> xstarts[2] = { block_box.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>(), block_box.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>() };</div><div class="line"><a name="l00558"></a><span class="lineno"> 558</span>  <span class="keywordtype">double</span> coeffs[3] = { 0.0, row-><a class="code" href="a02485.html#aeba2135f371c89fd310f0443f79c8f43">line_m</a>(), row-><a class="code" href="a02485.html#a4db47940276e2aa20f409877aa953360">line_c</a>() };</div><div class="line"><a name="l00559"></a><span class="lineno"> 559</span>  row-><a class="code" href="a02485.html#a611050c4612df0ccd0f2d64ca0005b9b">baseline</a> = <a class="code" href="a02701.html">QSPLINE</a>(1, xstarts, coeffs);</div><div class="line"><a name="l00560"></a><span class="lineno"> 560</span>  textord-><a class="code" href="a04841.html#aa5342d14436274e648b545a522705eab">compute_row_xheight</a>(row, block_-><a class="code" href="a02489.html#a16e698664028b0d6d2193db64560c16b">block</a>-><a class="code" href="a02617.html#aa41ae9661d53570dd6365d3ac8ac4c15">classify_rotation</a>(),</div><div class="line"><a name="l00561"></a><span class="lineno"> 561</span>  row-><a class="code" href="a02485.html#aeba2135f371c89fd310f0443f79c8f43">line_m</a>(), block_-><a class="code" href="a02489.html#ab106233da0599f3e1595c1c765acadec">line_size</a>);</div><div class="line"><a name="l00562"></a><span class="lineno"> 562</span>  }</div><div class="line"><a name="l00563"></a><span class="lineno"> 563</span>  }</div><div class="line"><a name="l00564"></a><span class="lineno"> 564</span>  textord-><a class="code" href="a04841.html#ae256bbff96a055ef49a86fbba393c98a">compute_block_xheight</a>(block_, gradient);</div><div class="line"><a name="l00565"></a><span class="lineno"> 565</span>  block_-><a class="code" href="a02489.html#a16e698664028b0d6d2193db64560c16b">block</a>-><a class="code" href="a02617.html#a761f9b58bfeef6d485001b707fb9939b">set_xheight</a>(block_-><a class="code" href="a02489.html#a4d0f99a557a4950af5123a31a157749f">xheight</a>);</div><div class="line"><a name="l00566"></a><span class="lineno"> 566</span>  <span class="keywordflow">if</span> (<a class="code" href="a01472.html#a3b7ff031211912735f61bd0dc97c6f2b">textord_restore_underlines</a>) <span class="comment">// fix underlines</span></div><div class="line"><a name="l00567"></a><span class="lineno"> 567</span>  <a class="code" href="a01472.html#a2118358b0e0f62667f62a0aaf2fb2ae8">restore_underlined_blobs</a>(block_);</div><div class="line"><a name="l00568"></a><span class="lineno"> 568</span> }</div><div class="line"><a name="l00569"></a><span class="lineno"> 569</span> </div><div class="line"><a name="l00570"></a><span class="lineno"> 570</span> <span class="comment">// Draws the (straight) baselines and final blobs colored according to</span></div><div class="line"><a name="l00571"></a><span class="lineno"> 571</span> <span class="comment">// what was discarded as noise and what is associated with each row.</span></div><div class="line"><a name="l00572"></a><span class="lineno"><a class="line" href="a04661.html#a682d76ce63cdca26f2a1b33d57ffc2ab"> 572</a></span> <span class="keywordtype">void</span> <a class="code" href="a04661.html#a682d76ce63cdca26f2a1b33d57ffc2ab">BaselineBlock::DrawFinalRows</a>(<span class="keyword">const</span> <a class="code" href="a02673.html">ICOORD</a>& page_tr) {</div><div class="line"><a name="l00573"></a><span class="lineno"> 573</span> <span class="preprocessor">#ifndef GRAPHICS_DISABLED</span></div><div class="line"><a name="l00574"></a><span class="lineno"> 574</span>  <span class="keywordflow">if</span> (non_text_block_) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00575"></a><span class="lineno"> 575</span>  <span class="keywordtype">double</span> gradient = tan(skew_angle_);</div><div class="line"><a name="l00576"></a><span class="lineno"> 576</span>  <a class="code" href="a02681.html">FCOORD</a> rotation(1.0f, 0.0f);</div><div class="line"><a name="l00577"></a><span class="lineno"> 577</span>  <span class="keywordtype">int</span> left_edge = block_-><a class="code" href="a02489.html#a16e698664028b0d6d2193db64560c16b">block</a>-><a class="code" href="a02661.html#a3f06f8e34fc5962f342daff9623463e9">bounding_box</a>().left();</div><div class="line"><a name="l00578"></a><span class="lineno"> 578</span>  <a class="code" href="a04929.html">ScrollView</a>* win = <a class="code" href="a01325.html#afd5bee79bdf1ea9c211c3a3519d25251">create_to_win</a>(page_tr);</div><div class="line"><a name="l00579"></a><span class="lineno"> 579</span>  <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8">ScrollView::Color</a> colour = <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8a0959f7470b08ae1a38aa7e38fba29402">ScrollView::RED</a>;</div><div class="line"><a name="l00580"></a><span class="lineno"> 580</span>  TO_ROW_IT row_it = block_-><a class="code" href="a02489.html#a4846ebdcc832b4b0a762d87c0d83a056">get_rows</a>();</div><div class="line"><a name="l00581"></a><span class="lineno"> 581</span>  <span class="keywordflow">for</span> (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {</div><div class="line"><a name="l00582"></a><span class="lineno"> 582</span>  <a class="code" href="a01325.html#afb1c1fd2d6af3a9851ab98454356c3cf">plot_parallel_row</a>(row_it.data(), gradient, left_edge, colour, rotation);</div><div class="line"><a name="l00583"></a><span class="lineno"> 583</span>  colour = <span class="keyword">static_cast<</span><a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8">ScrollView::Color</a><span class="keyword">></span>(colour + 1);</div><div class="line"><a name="l00584"></a><span class="lineno"> 584</span>  <span class="keywordflow">if</span> (colour > <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8aebeaaeee353c6f04b4498b1fef94bbb3">ScrollView::MAGENTA</a>)</div><div class="line"><a name="l00585"></a><span class="lineno"> 585</span>  colour = <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8a0959f7470b08ae1a38aa7e38fba29402">ScrollView::RED</a>;</div><div class="line"><a name="l00586"></a><span class="lineno"> 586</span>  }</div><div class="line"><a name="l00587"></a><span class="lineno"> 587</span>  <a class="code" href="a00206.html#a331e6744e04cb0a2fb23c1465c82196c">plot_blob_list</a>(win, &block_-><a class="code" href="a02489.html#a5dd67c54162a6b60b0fd11500d4a3025">blobs</a>, <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8aebeaaeee353c6f04b4498b1fef94bbb3">ScrollView::MAGENTA</a>, <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8a0eab2b208fc9a5e2774f92cf3e768982">ScrollView::WHITE</a>);</div><div class="line"><a name="l00588"></a><span class="lineno"> 588</span>  <span class="comment">// Show discarded blobs.</span></div><div class="line"><a name="l00589"></a><span class="lineno"> 589</span>  <a class="code" href="a00206.html#a331e6744e04cb0a2fb23c1465c82196c">plot_blob_list</a>(win, &block_-><a class="code" href="a02489.html#abe8092e46729fbddf38f16ad7ca07318">underlines</a>,</div><div class="line"><a name="l00590"></a><span class="lineno"> 590</span>  <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8a61dec9bc0aaf1d527a731b2a6ce055c8">ScrollView::YELLOW</a>, <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8a9a954d0f0149ee883cbcc5e0a379b460">ScrollView::CORAL</a>);</div><div class="line"><a name="l00591"></a><span class="lineno"> 591</span>  <span class="keywordflow">if</span> (block_-><a class="code" href="a02489.html#a5dd67c54162a6b60b0fd11500d4a3025">blobs</a>.length() > 0)</div><div class="line"><a name="l00592"></a><span class="lineno"> 592</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"%d blobs discarded as noise\n"</span>, block_-><a class="code" href="a02489.html#a5dd67c54162a6b60b0fd11500d4a3025">blobs</a>.length());</div><div class="line"><a name="l00593"></a><span class="lineno"> 593</span>  <a class="code" href="a01325.html#af8aae7bd42a61b839e724a34c07b42ab">draw_meanlines</a>(block_, gradient, left_edge, <a class="code" href="a04929.html#a100504544a5423a94222149ee9ed0fe8a0eab2b208fc9a5e2774f92cf3e768982">ScrollView::WHITE</a>, rotation);</div><div class="line"><a name="l00594"></a><span class="lineno"> 594</span> <span class="preprocessor">#endif</span></div><div class="line"><a name="l00595"></a><span class="lineno"> 595</span> }</div><div class="line"><a name="l00596"></a><span class="lineno"> 596</span> </div><div class="line"><a name="l00597"></a><span class="lineno"><a class="line" href="a04661.html#a858165c88e4c695fa2136bac7ed97b7f"> 597</a></span> <span class="keywordtype">void</span> <a class="code" href="a04661.html#a858165c88e4c695fa2136bac7ed97b7f">BaselineBlock::DrawPixSpline</a>(Pix* pix_in) {</div><div class="line"><a name="l00598"></a><span class="lineno"> 598</span>  <span class="keywordflow">if</span> (non_text_block_) <span class="keywordflow">return</span>;</div><div class="line"><a name="l00599"></a><span class="lineno"> 599</span>  TO_ROW_IT row_it = block_-><a class="code" href="a02489.html#a4846ebdcc832b4b0a762d87c0d83a056">get_rows</a>();</div><div class="line"><a name="l00600"></a><span class="lineno"> 600</span>  <span class="keywordflow">for</span> (row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward()) {</div><div class="line"><a name="l00601"></a><span class="lineno"> 601</span>  row_it.data()->baseline.plot(pix_in);</div><div class="line"><a name="l00602"></a><span class="lineno"> 602</span>  }</div><div class="line"><a name="l00603"></a><span class="lineno"> 603</span> }</div><div class="line"><a name="l00604"></a><span class="lineno"> 604</span> </div><div class="line"><a name="l00605"></a><span class="lineno"> 605</span> <span class="comment">// Top-level line-spacing calculation. Computes an estimate of the line-</span></div><div class="line"><a name="l00606"></a><span class="lineno"> 606</span> <span class="comment">// spacing, using the current baselines in the TO_ROWS of the block, and</span></div><div class="line"><a name="l00607"></a><span class="lineno"> 607</span> <span class="comment">// then refines it by fitting a regression line to the baseline positions</span></div><div class="line"><a name="l00608"></a><span class="lineno"> 608</span> <span class="comment">// as a function of their integer index.</span></div><div class="line"><a name="l00609"></a><span class="lineno"> 609</span> <span class="comment">// Returns true if it seems that the model is a reasonable fit to the</span></div><div class="line"><a name="l00610"></a><span class="lineno"> 610</span> <span class="comment">// observations.</span></div><div class="line"><a name="l00611"></a><span class="lineno"> 611</span> <span class="keywordtype">bool</span> BaselineBlock::ComputeLineSpacing() {</div><div class="line"><a name="l00612"></a><span class="lineno"> 612</span>  <a class="code" href="a02681.html">FCOORD</a> <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>(cos(skew_angle_), sin(skew_angle_));</div><div class="line"><a name="l00613"></a><span class="lineno"> 613</span>  <a class="code" href="a02297.html">GenericVector<double></a> row_positions;</div><div class="line"><a name="l00614"></a><span class="lineno"> 614</span>  ComputeBaselinePositions(<a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>, &row_positions);</div><div class="line"><a name="l00615"></a><span class="lineno"> 615</span>  <span class="keywordflow">if</span> (row_positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>() < 2) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"><a name="l00616"></a><span class="lineno"> 616</span>  EstimateLineSpacing();</div><div class="line"><a name="l00617"></a><span class="lineno"> 617</span>  RefineLineSpacing(row_positions);</div><div class="line"><a name="l00618"></a><span class="lineno"> 618</span>  <span class="comment">// Verify that the model is reasonable.</span></div><div class="line"><a name="l00619"></a><span class="lineno"> 619</span>  <span class="keywordtype">double</span> max_baseline_error = <a class="code" href="a01738.html#a8043339cb79428cd76d41f5432de9712">kMaxBaselineError</a> * line_spacing_;</div><div class="line"><a name="l00620"></a><span class="lineno"> 620</span>  <span class="keywordtype">int</span> non_trivial_gaps = 0;</div><div class="line"><a name="l00621"></a><span class="lineno"> 621</span>  <span class="keywordtype">int</span> fitting_gaps = 0;</div><div class="line"><a name="l00622"></a><span class="lineno"> 622</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i < row_positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i) {</div><div class="line"><a name="l00623"></a><span class="lineno"> 623</span>  <span class="keywordtype">double</span> row_gap = fabs(row_positions[i - 1] - row_positions[i]);</div><div class="line"><a name="l00624"></a><span class="lineno"> 624</span>  <span class="keywordflow">if</span> (row_gap > max_baseline_error) {</div><div class="line"><a name="l00625"></a><span class="lineno"> 625</span>  ++non_trivial_gaps;</div><div class="line"><a name="l00626"></a><span class="lineno"> 626</span>  <span class="keywordflow">if</span> (fabs(row_gap - line_spacing_) <= max_baseline_error)</div><div class="line"><a name="l00627"></a><span class="lineno"> 627</span>  ++fitting_gaps;</div><div class="line"><a name="l00628"></a><span class="lineno"> 628</span>  }</div><div class="line"><a name="l00629"></a><span class="lineno"> 629</span>  }</div><div class="line"><a name="l00630"></a><span class="lineno"> 630</span>  <span class="keywordflow">if</span> (debug_level_ > 0) {</div><div class="line"><a name="l00631"></a><span class="lineno"> 631</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Spacing %g, in %d rows, %d gaps fitted out of %d non-trivial\n"</span>,</div><div class="line"><a name="l00632"></a><span class="lineno"> 632</span>  line_spacing_, row_positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(), fitting_gaps,</div><div class="line"><a name="l00633"></a><span class="lineno"> 633</span>  non_trivial_gaps);</div><div class="line"><a name="l00634"></a><span class="lineno"> 634</span>  }</div><div class="line"><a name="l00635"></a><span class="lineno"> 635</span>  <span class="keywordflow">return</span> fitting_gaps > non_trivial_gaps * <a class="code" href="a01253.html#aa61dc7df62ef6cd14f8f4a9e6b3003c9">kMinFittingLinespacings</a>;</div><div class="line"><a name="l00636"></a><span class="lineno"> 636</span> }</div><div class="line"><a name="l00637"></a><span class="lineno"> 637</span> </div><div class="line"><a name="l00638"></a><span class="lineno"> 638</span> <span class="comment">// Computes the deskewed vertical position of each baseline in the block and</span></div><div class="line"><a name="l00639"></a><span class="lineno"> 639</span> <span class="comment">// stores them in the given vector.</span></div><div class="line"><a name="l00640"></a><span class="lineno"> 640</span> <span class="comment">// This is calculated as the perpendicular distance of the middle of each</span></div><div class="line"><a name="l00641"></a><span class="lineno"> 641</span> <span class="comment">// baseline (in case it has a different skew angle) from the line passing</span></div><div class="line"><a name="l00642"></a><span class="lineno"> 642</span> <span class="comment">// through the origin parallel to the block baseline angle.</span></div><div class="line"><a name="l00643"></a><span class="lineno"> 643</span> <span class="comment">// NOTE that "distance" above is a signed quantity so we can tell which side</span></div><div class="line"><a name="l00644"></a><span class="lineno"> 644</span> <span class="comment">// of the block baseline a line sits, hence the function and argument name</span></div><div class="line"><a name="l00645"></a><span class="lineno"> 645</span> <span class="comment">// positions not distances.</span></div><div class="line"><a name="l00646"></a><span class="lineno"> 646</span> <span class="keywordtype">void</span> BaselineBlock::ComputeBaselinePositions(<span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a>,</div><div class="line"><a name="l00647"></a><span class="lineno"> 647</span>  <a class="code" href="a02297.html">GenericVector<double></a>* positions) {</div><div class="line"><a name="l00648"></a><span class="lineno"> 648</span>  positions-><a class="code" href="a02297.html#a9cdbff49b186574b83e43afba606fdd9">clear</a>();</div><div class="line"><a name="l00649"></a><span class="lineno"> 649</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < rows_.size(); ++r) {</div><div class="line"><a name="l00650"></a><span class="lineno"> 650</span>  BaselineRow* row = rows_[r];</div><div class="line"><a name="l00651"></a><span class="lineno"> 651</span>  <span class="keyword">const</span> <a class="code" href="a02713.html">TBOX</a>& row_box = row->bounding_box();</div><div class="line"><a name="l00652"></a><span class="lineno"> 652</span>  <span class="keywordtype">float</span> x_middle = (row_box.<a class="code" href="a02713.html#affd18574697b2b707cee416f7cdccb1f">left</a>() + row_box.<a class="code" href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">right</a>()) / 2.0f;</div><div class="line"><a name="l00653"></a><span class="lineno"> 653</span>  <a class="code" href="a02681.html">FCOORD</a> row_pos(x_middle, static_cast<float>(row->StraightYAtX(x_middle)));</div><div class="line"><a name="l00654"></a><span class="lineno"> 654</span>  <span class="keywordtype">float</span> offset = <a class="code" href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a> * row_pos;</div><div class="line"><a name="l00655"></a><span class="lineno"> 655</span>  positions-><a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(offset);</div><div class="line"><a name="l00656"></a><span class="lineno"> 656</span>  }</div><div class="line"><a name="l00657"></a><span class="lineno"> 657</span> }</div><div class="line"><a name="l00658"></a><span class="lineno"> 658</span> </div><div class="line"><a name="l00659"></a><span class="lineno"> 659</span> <span class="comment">// Computes an estimate of the line spacing of the block from the median</span></div><div class="line"><a name="l00660"></a><span class="lineno"> 660</span> <span class="comment">// of the spacings between adjacent overlapping textlines.</span></div><div class="line"><a name="l00661"></a><span class="lineno"> 661</span> <span class="keywordtype">void</span> BaselineBlock::EstimateLineSpacing() {</div><div class="line"><a name="l00662"></a><span class="lineno"> 662</span>  <a class="code" href="a02297.html">GenericVector<float></a> spacings;</div><div class="line"><a name="l00663"></a><span class="lineno"> 663</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> r = 0; r < rows_.size(); ++r) {</div><div class="line"><a name="l00664"></a><span class="lineno"> 664</span>  BaselineRow* row = rows_[r];</div><div class="line"><a name="l00665"></a><span class="lineno"> 665</span>  <span class="comment">// Exclude silly lines.</span></div><div class="line"><a name="l00666"></a><span class="lineno"> 666</span>  <span class="keywordflow">if</span> (fabs(row->BaselineAngle()) > M_PI * 0.25) <span class="keywordflow">continue</span>;</div><div class="line"><a name="l00667"></a><span class="lineno"> 667</span>  <span class="comment">// Find the first row after row that overlaps it significantly.</span></div><div class="line"><a name="l00668"></a><span class="lineno"> 668</span>  <span class="keyword">const</span> <a class="code" href="a02713.html">TBOX</a>& row_box = row->bounding_box();</div><div class="line"><a name="l00669"></a><span class="lineno"> 669</span>  <span class="keywordtype">int</span> r2;</div><div class="line"><a name="l00670"></a><span class="lineno"> 670</span>  <span class="keywordflow">for</span> (r2 = r + 1; r2 < rows_.size() &&</div><div class="line"><a name="l00671"></a><span class="lineno"> 671</span>  !row_box.<a class="code" href="a02713.html#ade947e3871fa316e3e0b0864905c2997">major_x_overlap</a>(rows_[r2]->bounding_box());</div><div class="line"><a name="l00672"></a><span class="lineno"> 672</span>  ++r2);</div><div class="line"><a name="l00673"></a><span class="lineno"> 673</span>  <span class="keywordflow">if</span> (r2 < rows_.size()) {</div><div class="line"><a name="l00674"></a><span class="lineno"> 674</span>  BaselineRow* row2 = rows_[r2];</div><div class="line"><a name="l00675"></a><span class="lineno"> 675</span>  <span class="comment">// Exclude silly lines.</span></div><div class="line"><a name="l00676"></a><span class="lineno"> 676</span>  <span class="keywordflow">if</span> (fabs(row2->BaselineAngle()) > M_PI * 0.25) <span class="keywordflow">continue</span>;</div><div class="line"><a name="l00677"></a><span class="lineno"> 677</span>  <span class="keywordtype">float</span> spacing = row->SpaceBetween(*row2);</div><div class="line"><a name="l00678"></a><span class="lineno"> 678</span>  spacings.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(spacing);</div><div class="line"><a name="l00679"></a><span class="lineno"> 679</span>  }</div><div class="line"><a name="l00680"></a><span class="lineno"> 680</span>  }</div><div class="line"><a name="l00681"></a><span class="lineno"> 681</span>  <span class="comment">// If we have at least one value, use it, otherwise leave the previous</span></div><div class="line"><a name="l00682"></a><span class="lineno"> 682</span>  <span class="comment">// value unchanged.</span></div><div class="line"><a name="l00683"></a><span class="lineno"> 683</span>  <span class="keywordflow">if</span> (!spacings.<a class="code" href="a02297.html#a172c4aa23ba397e24319ae095281cbcc">empty</a>()) {</div><div class="line"><a name="l00684"></a><span class="lineno"> 684</span>  line_spacing_ = spacings[spacings.<a class="code" href="a02297.html#a5c4218ef833d0fe5db9b9749abd81ea5">choose_nth_item</a>(spacings.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>() / 2)];</div><div class="line"><a name="l00685"></a><span class="lineno"> 685</span>  <span class="keywordflow">if</span> (debug_level_ > 1)</div><div class="line"><a name="l00686"></a><span class="lineno"> 686</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Estimate of linespacing = %g\n"</span>, line_spacing_);</div><div class="line"><a name="l00687"></a><span class="lineno"> 687</span>  }</div><div class="line"><a name="l00688"></a><span class="lineno"> 688</span> }</div><div class="line"><a name="l00689"></a><span class="lineno"> 689</span> </div><div class="line"><a name="l00690"></a><span class="lineno"> 690</span> <span class="comment">// Refines the line spacing of the block by fitting a regression</span></div><div class="line"><a name="l00691"></a><span class="lineno"> 691</span> <span class="comment">// line to the deskewed y-position of each baseline as a function of its</span></div><div class="line"><a name="l00692"></a><span class="lineno"> 692</span> <span class="comment">// estimated line index, allowing for a small error in the initial linespacing</span></div><div class="line"><a name="l00693"></a><span class="lineno"> 693</span> <span class="comment">// and choosing the best available model.</span></div><div class="line"><a name="l00694"></a><span class="lineno"> 694</span> <span class="keywordtype">void</span> BaselineBlock::RefineLineSpacing(<span class="keyword">const</span> <a class="code" href="a02297.html">GenericVector<double></a>& positions) {</div><div class="line"><a name="l00695"></a><span class="lineno"> 695</span>  <span class="keywordtype">double</span> spacings[3], offsets[3], errors[3];</div><div class="line"><a name="l00696"></a><span class="lineno"> 696</span>  <span class="keywordtype">int</span> index_range;</div><div class="line"><a name="l00697"></a><span class="lineno"> 697</span>  errors[0] = FitLineSpacingModel(positions, line_spacing_,</div><div class="line"><a name="l00698"></a><span class="lineno"> 698</span>  &spacings[0], &offsets[0], &index_range);</div><div class="line"><a name="l00699"></a><span class="lineno"> 699</span>  <span class="keywordflow">if</span> (index_range > 1) {</div><div class="line"><a name="l00700"></a><span class="lineno"> 700</span>  <span class="keywordtype">double</span> spacing_plus = line_spacing_ / (1.0 + 1.0 / index_range);</div><div class="line"><a name="l00701"></a><span class="lineno"> 701</span>  <span class="comment">// Try the hypotheses that there might be index_range +/- 1 line spaces.</span></div><div class="line"><a name="l00702"></a><span class="lineno"> 702</span>  errors[1] = FitLineSpacingModel(positions, spacing_plus,</div><div class="line"><a name="l00703"></a><span class="lineno"> 703</span>  &spacings[1], &offsets[1], NULL);</div><div class="line"><a name="l00704"></a><span class="lineno"> 704</span>  <span class="keywordtype">double</span> spacing_minus = line_spacing_ / (1.0 - 1.0 / index_range);</div><div class="line"><a name="l00705"></a><span class="lineno"> 705</span>  errors[2] = FitLineSpacingModel(positions, spacing_minus,</div><div class="line"><a name="l00706"></a><span class="lineno"> 706</span>  &spacings[2], &offsets[2], NULL);</div><div class="line"><a name="l00707"></a><span class="lineno"> 707</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 1; i <= 2; ++i) {</div><div class="line"><a name="l00708"></a><span class="lineno"> 708</span>  <span class="keywordflow">if</span> (errors[i] < errors[0]) {</div><div class="line"><a name="l00709"></a><span class="lineno"> 709</span>  spacings[0] = spacings[i];</div><div class="line"><a name="l00710"></a><span class="lineno"> 710</span>  offsets[0] = offsets[i];</div><div class="line"><a name="l00711"></a><span class="lineno"> 711</span>  errors[0] = errors[i];</div><div class="line"><a name="l00712"></a><span class="lineno"> 712</span>  }</div><div class="line"><a name="l00713"></a><span class="lineno"> 713</span>  }</div><div class="line"><a name="l00714"></a><span class="lineno"> 714</span>  }</div><div class="line"><a name="l00715"></a><span class="lineno"> 715</span>  <span class="keywordflow">if</span> (spacings[0] > 0.0) {</div><div class="line"><a name="l00716"></a><span class="lineno"> 716</span>  line_spacing_ = spacings[0];</div><div class="line"><a name="l00717"></a><span class="lineno"> 717</span>  line_offset_ = offsets[0];</div><div class="line"><a name="l00718"></a><span class="lineno"> 718</span>  model_error_ = errors[0];</div><div class="line"><a name="l00719"></a><span class="lineno"> 719</span>  <span class="keywordflow">if</span> (debug_level_ > 0) {</div><div class="line"><a name="l00720"></a><span class="lineno"> 720</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Final linespacing model = %g + offset %g, error %g\n"</span>,</div><div class="line"><a name="l00721"></a><span class="lineno"> 721</span>  line_spacing_, line_offset_, model_error_);</div><div class="line"><a name="l00722"></a><span class="lineno"> 722</span>  }</div><div class="line"><a name="l00723"></a><span class="lineno"> 723</span>  }</div><div class="line"><a name="l00724"></a><span class="lineno"> 724</span> }</div><div class="line"><a name="l00725"></a><span class="lineno"> 725</span> </div><div class="line"><a name="l00726"></a><span class="lineno"> 726</span> <span class="comment">// Given an initial estimate of line spacing (m_in) and the positions of each</span></div><div class="line"><a name="l00727"></a><span class="lineno"> 727</span> <span class="comment">// baseline, computes the line spacing of the block more accurately in m_out,</span></div><div class="line"><a name="l00728"></a><span class="lineno"> 728</span> <span class="comment">// and the corresponding intercept in c_out, and the number of spacings seen</span></div><div class="line"><a name="l00729"></a><span class="lineno"> 729</span> <span class="comment">// in index_delta. Returns the error of fit to the line spacing model.</span></div><div class="line"><a name="l00730"></a><span class="lineno"> 730</span> <span class="comment">// Uses a simple linear regression, but optimized the offset using the median.</span></div><div class="line"><a name="l00731"></a><span class="lineno"> 731</span> <span class="keywordtype">double</span> BaselineBlock::FitLineSpacingModel(</div><div class="line"><a name="l00732"></a><span class="lineno"> 732</span>  <span class="keyword">const</span> <a class="code" href="a02297.html">GenericVector<double></a>& positions, <span class="keywordtype">double</span> m_in,</div><div class="line"><a name="l00733"></a><span class="lineno"> 733</span>  <span class="keywordtype">double</span>* m_out, <span class="keywordtype">double</span>* c_out, <span class="keywordtype">int</span>* index_delta) {</div><div class="line"><a name="l00734"></a><span class="lineno"> 734</span>  <span class="keywordflow">if</span> (m_in == 0.0f || positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>() < 2) {</div><div class="line"><a name="l00735"></a><span class="lineno"> 735</span>  *m_out = m_in;</div><div class="line"><a name="l00736"></a><span class="lineno"> 736</span>  *c_out = 0.0;</div><div class="line"><a name="l00737"></a><span class="lineno"> 737</span>  <span class="keywordflow">if</span> (index_delta != NULL) *index_delta = 0;</div><div class="line"><a name="l00738"></a><span class="lineno"> 738</span>  <span class="keywordflow">return</span> 0.0;</div><div class="line"><a name="l00739"></a><span class="lineno"> 739</span>  }</div><div class="line"><a name="l00740"></a><span class="lineno"> 740</span>  <a class="code" href="a02297.html">GenericVector<double></a> offsets;</div><div class="line"><a name="l00741"></a><span class="lineno"> 741</span>  <span class="comment">// Get the offset (remainder) linespacing for each line and choose the median.</span></div><div class="line"><a name="l00742"></a><span class="lineno"> 742</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i)</div><div class="line"><a name="l00743"></a><span class="lineno"> 743</span>  offsets.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(fmod(positions[i], m_in));</div><div class="line"><a name="l00744"></a><span class="lineno"> 744</span>  <span class="comment">// Get the median offset.</span></div><div class="line"><a name="l00745"></a><span class="lineno"> 745</span>  <span class="keywordtype">double</span> median_offset = <a class="code" href="a00290.html#abde6267e843aeeea5089d458c465dee2">MedianOfCircularValues</a>(m_in, &offsets);</div><div class="line"><a name="l00746"></a><span class="lineno"> 746</span>  <span class="comment">// Now fit a line to quantized line number and offset.</span></div><div class="line"><a name="l00747"></a><span class="lineno"> 747</span>  <a class="code" href="a02589.html">LLSQ</a> llsq;</div><div class="line"><a name="l00748"></a><span class="lineno"> 748</span>  <span class="keywordtype">int</span> min_index = <a class="code" href="a00524.html#aac62d87844689a18b6f5339a89ed6e7f">MAX_INT32</a>;</div><div class="line"><a name="l00749"></a><span class="lineno"> 749</span>  <span class="keywordtype">int</span> max_index = -<a class="code" href="a00524.html#aac62d87844689a18b6f5339a89ed6e7f">MAX_INT32</a>;</div><div class="line"><a name="l00750"></a><span class="lineno"> 750</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i) {</div><div class="line"><a name="l00751"></a><span class="lineno"> 751</span>  <span class="keywordtype">double</span> y_pos = positions[i];</div><div class="line"><a name="l00752"></a><span class="lineno"> 752</span>  <span class="keywordtype">int</span> row_index = <a class="code" href="a00521.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a>((y_pos - median_offset) / m_in);</div><div class="line"><a name="l00753"></a><span class="lineno"> 753</span>  <a class="code" href="a00521.html#a6eb00eb9bc5ed195953f334971c462ae">UpdateRange</a>(row_index, &min_index, &max_index);</div><div class="line"><a name="l00754"></a><span class="lineno"> 754</span>  llsq.<a class="code" href="a02589.html#aa439294be0539828cf042f8941125b3c">add</a>(row_index, y_pos);</div><div class="line"><a name="l00755"></a><span class="lineno"> 755</span>  }</div><div class="line"><a name="l00756"></a><span class="lineno"> 756</span>  <span class="comment">// Get the refined line spacing.</span></div><div class="line"><a name="l00757"></a><span class="lineno"> 757</span>  *m_out = llsq.<a class="code" href="a02589.html#a14be1135a936c540eea93455c19c70f1">m</a>();</div><div class="line"><a name="l00758"></a><span class="lineno"> 758</span>  <span class="comment">// Use the median offset rather than the mean.</span></div><div class="line"><a name="l00759"></a><span class="lineno"> 759</span>  offsets.<a class="code" href="a02297.html#a980882b5ebc3e72fdedbdbe345196f21">truncate</a>(0);</div><div class="line"><a name="l00760"></a><span class="lineno"> 760</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < positions.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i)</div><div class="line"><a name="l00761"></a><span class="lineno"> 761</span>  offsets.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(fmod(positions[i], *m_out));</div><div class="line"><a name="l00762"></a><span class="lineno"> 762</span>  <span class="comment">// Get the median offset.</span></div><div class="line"><a name="l00763"></a><span class="lineno"> 763</span>  <span class="keywordflow">if</span> (debug_level_ > 2) {</div><div class="line"><a name="l00764"></a><span class="lineno"> 764</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < offsets.<a class="code" href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">size</a>(); ++i)</div><div class="line"><a name="l00765"></a><span class="lineno"> 765</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"%d: %g\n"</span>, i, offsets[i]);</div><div class="line"><a name="l00766"></a><span class="lineno"> 766</span>  }</div><div class="line"><a name="l00767"></a><span class="lineno"> 767</span>  *c_out = <a class="code" href="a00290.html#abde6267e843aeeea5089d458c465dee2">MedianOfCircularValues</a>(*m_out, &offsets);</div><div class="line"><a name="l00768"></a><span class="lineno"> 768</span>  <span class="keywordflow">if</span> (debug_level_ > 1) {</div><div class="line"><a name="l00769"></a><span class="lineno"> 769</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Median offset = %g, compared to mean of %g.\n"</span>,</div><div class="line"><a name="l00770"></a><span class="lineno"> 770</span>  *c_out, llsq.<a class="code" href="a02589.html#a4146a9ebd0a85858cec1df3a218ffada">c</a>(*m_out));</div><div class="line"><a name="l00771"></a><span class="lineno"> 771</span>  }</div><div class="line"><a name="l00772"></a><span class="lineno"> 772</span>  <span class="comment">// Index_delta is the number of hypothesized line gaps present.</span></div><div class="line"><a name="l00773"></a><span class="lineno"> 773</span>  <span class="keywordflow">if</span> (index_delta != NULL)</div><div class="line"><a name="l00774"></a><span class="lineno"> 774</span>  *index_delta = max_index - min_index;</div><div class="line"><a name="l00775"></a><span class="lineno"> 775</span>  <span class="comment">// Use the regression model's intercept to compute the error, as it may be</span></div><div class="line"><a name="l00776"></a><span class="lineno"> 776</span>  <span class="comment">// a full line-spacing in disagreement with the median.</span></div><div class="line"><a name="l00777"></a><span class="lineno"> 777</span>  <span class="keywordtype">double</span> rms_error = llsq.<a class="code" href="a02589.html#a6139b78394a33f9447d84a575a10f471">rms</a>(*m_out, llsq.<a class="code" href="a02589.html#a4146a9ebd0a85858cec1df3a218ffada">c</a>(*m_out));</div><div class="line"><a name="l00778"></a><span class="lineno"> 778</span>  <span class="keywordflow">if</span> (debug_level_ > 1) {</div><div class="line"><a name="l00779"></a><span class="lineno"> 779</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Linespacing of y=%g x + %g improved to %g x + %g, rms=%g\n"</span>,</div><div class="line"><a name="l00780"></a><span class="lineno"> 780</span>  m_in, median_offset, *m_out, *c_out, rms_error);</div><div class="line"><a name="l00781"></a><span class="lineno"> 781</span>  }</div><div class="line"><a name="l00782"></a><span class="lineno"> 782</span>  <span class="keywordflow">return</span> rms_error;</div><div class="line"><a name="l00783"></a><span class="lineno"> 783</span> }</div><div class="line"><a name="l00784"></a><span class="lineno"> 784</span> </div><div class="line"><a name="l00785"></a><span class="lineno"> 785</span> </div><div class="line"><a name="l00786"></a><span class="lineno"><a class="line" href="a04665.html#a358fd732758ac23b5a20413344204087"> 786</a></span> <a class="code" href="a04665.html#a358fd732758ac23b5a20413344204087">BaselineDetect::BaselineDetect</a>(<span class="keywordtype">int</span> debug_level, <span class="keyword">const</span> <a class="code" href="a02681.html">FCOORD</a>& page_skew,</div><div class="line"><a name="l00787"></a><span class="lineno"> 787</span>  TO_BLOCK_LIST* blocks)</div><div class="line"><a name="l00788"></a><span class="lineno"> 788</span>  : page_skew_(page_skew), debug_level_(debug_level), pix_debug_(NULL),</div><div class="line"><a name="l00789"></a><span class="lineno"> 789</span>  debug_file_prefix_(<span class="stringliteral">""</span>) {</div><div class="line"><a name="l00790"></a><span class="lineno"> 790</span>  TO_BLOCK_IT it(blocks);</div><div class="line"><a name="l00791"></a><span class="lineno"> 791</span>  <span class="keywordflow">for</span> (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) {</div><div class="line"><a name="l00792"></a><span class="lineno"> 792</span>  <a class="code" href="a02489.html">TO_BLOCK</a>* to_block = it.data();</div><div class="line"><a name="l00793"></a><span class="lineno"> 793</span>  <a class="code" href="a02617.html">BLOCK</a>* block = to_block-><a class="code" href="a02489.html#a16e698664028b0d6d2193db64560c16b">block</a>;</div><div class="line"><a name="l00794"></a><span class="lineno"> 794</span>  <a class="code" href="a02685.html">POLY_BLOCK</a>* pb = block-><a class="code" href="a02661.html#a87856f8400f0629dc761fec0f7a17b57">poly_block</a>();</div><div class="line"><a name="l00795"></a><span class="lineno"> 795</span>  <span class="comment">// A note about non-text blocks.</span></div><div class="line"><a name="l00796"></a><span class="lineno"> 796</span>  <span class="comment">// On output, non-text blocks are supposed to contain a single empty word</span></div><div class="line"><a name="l00797"></a><span class="lineno"> 797</span>  <span class="comment">// in each incoming text line. These mark out the polygonal bounds of the</span></div><div class="line"><a name="l00798"></a><span class="lineno"> 798</span>  <span class="comment">// block. Ideally no baselines should be required, but currently</span></div><div class="line"><a name="l00799"></a><span class="lineno"> 799</span>  <span class="comment">// make_words crashes if a baseline and xheight are not provided, so we</span></div><div class="line"><a name="l00800"></a><span class="lineno"> 800</span>  <span class="comment">// include non-text blocks here, but flag them for special treatment.</span></div><div class="line"><a name="l00801"></a><span class="lineno"> 801</span>  <span class="keywordtype">bool</span> non_text = pb != NULL && !pb-><a class="code" href="a02685.html#a4eb55be5fc2ed33312e4410f5ee2cf88">IsText</a>();</div><div class="line"><a name="l00802"></a><span class="lineno"> 802</span>  blocks_.push_back(<span class="keyword">new</span> <a class="code" href="a04661.html">BaselineBlock</a>(debug_level_, non_text, to_block));</div><div class="line"><a name="l00803"></a><span class="lineno"> 803</span>  }</div><div class="line"><a name="l00804"></a><span class="lineno"> 804</span> }</div><div class="line"><a name="l00805"></a><span class="lineno"> 805</span> </div><div class="line"><a name="l00806"></a><span class="lineno"><a class="line" href="a04665.html#ad8ef6bb9dd7e29cd0a465640dae1da9b"> 806</a></span> <a class="code" href="a04665.html#ad8ef6bb9dd7e29cd0a465640dae1da9b">BaselineDetect::~BaselineDetect</a>() {</div><div class="line"><a name="l00807"></a><span class="lineno"> 807</span>  pixDestroy(&pix_debug_);</div><div class="line"><a name="l00808"></a><span class="lineno"> 808</span> }</div><div class="line"><a name="l00809"></a><span class="lineno"> 809</span> </div><div class="line"><a name="l00810"></a><span class="lineno"> 810</span> <span class="comment">// Finds the initial baselines for each TO_ROW in each TO_BLOCK, gathers</span></div><div class="line"><a name="l00811"></a><span class="lineno"> 811</span> <span class="comment">// block-wise and page-wise data to smooth small blocks/rows, and applies</span></div><div class="line"><a name="l00812"></a><span class="lineno"> 812</span> <span class="comment">// smoothing based on block/page-level skew and block-level linespacing.</span></div><div class="line"><a name="l00813"></a><span class="lineno"><a class="line" href="a04665.html#a9eaa0eba10b5abb2a9813f521c9dba50"> 813</a></span> <span class="keywordtype">void</span> <a class="code" href="a04665.html#a9eaa0eba10b5abb2a9813f521c9dba50">BaselineDetect::ComputeStraightBaselines</a>(<span class="keywordtype">bool</span> use_box_bottoms) {</div><div class="line"><a name="l00814"></a><span class="lineno"> 814</span>  <a class="code" href="a02297.html">GenericVector<double></a> block_skew_angles;</div><div class="line"><a name="l00815"></a><span class="lineno"> 815</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < blocks_.size(); ++i) {</div><div class="line"><a name="l00816"></a><span class="lineno"> 816</span>  <a class="code" href="a04661.html">BaselineBlock</a>* bl_block = blocks_[i];</div><div class="line"><a name="l00817"></a><span class="lineno"> 817</span>  <span class="keywordflow">if</span> (debug_level_ > 0)</div><div class="line"><a name="l00818"></a><span class="lineno"> 818</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Fitting initial baselines...\n"</span>);</div><div class="line"><a name="l00819"></a><span class="lineno"> 819</span>  <span class="keywordflow">if</span> (bl_block-><a class="code" href="a04661.html#a1e27f4aaf66c7e7aae4062c590fd8f3f">FitBaselinesAndFindSkew</a>(use_box_bottoms)) {</div><div class="line"><a name="l00820"></a><span class="lineno"> 820</span>  block_skew_angles.<a class="code" href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">push_back</a>(bl_block-><a class="code" href="a04661.html#a1445079bbeaaf0e81ab124288cc6ecf3">skew_angle</a>());</div><div class="line"><a name="l00821"></a><span class="lineno"> 821</span>  }</div><div class="line"><a name="l00822"></a><span class="lineno"> 822</span>  }</div><div class="line"><a name="l00823"></a><span class="lineno"> 823</span>  <span class="comment">// Compute a page-wide default skew for blocks with too little information.</span></div><div class="line"><a name="l00824"></a><span class="lineno"> 824</span>  <span class="keywordtype">double</span> default_block_skew = page_skew_.<a class="code" href="a02681.html#aab5b14bc328998adc252ffe7476d7f22">angle</a>();</div><div class="line"><a name="l00825"></a><span class="lineno"> 825</span>  <span class="keywordflow">if</span> (!block_skew_angles.<a class="code" href="a02297.html#a172c4aa23ba397e24319ae095281cbcc">empty</a>()) {</div><div class="line"><a name="l00826"></a><span class="lineno"> 826</span>  default_block_skew = <a class="code" href="a00290.html#abde6267e843aeeea5089d458c465dee2">MedianOfCircularValues</a>(M_PI, &block_skew_angles);</div><div class="line"><a name="l00827"></a><span class="lineno"> 827</span>  }</div><div class="line"><a name="l00828"></a><span class="lineno"> 828</span>  <span class="keywordflow">if</span> (debug_level_ > 0) {</div><div class="line"><a name="l00829"></a><span class="lineno"> 829</span>  <a class="code" href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a>(<span class="stringliteral">"Page skew angle = %g\n"</span>, default_block_skew);</div><div class="line"><a name="l00830"></a><span class="lineno"> 830</span>  }</div><div class="line"><a name="l00831"></a><span class="lineno"> 831</span>  <span class="comment">// Set bad lines in each block to the default block skew and then force fit</span></div><div class="line"><a name="l00832"></a><span class="lineno"> 832</span>  <span class="comment">// a linespacing model where it makes sense to do so.</span></div><div class="line"><a name="l00833"></a><span class="lineno"> 833</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < blocks_.size(); ++i) {</div><div class="line"><a name="l00834"></a><span class="lineno"> 834</span>  <a class="code" href="a04661.html">BaselineBlock</a>* bl_block = blocks_[i];</div><div class="line"><a name="l00835"></a><span class="lineno"> 835</span>  bl_block-><a class="code" href="a04661.html#a8a7ab56dd7abc0421cff9680b6634b85">ParallelizeBaselines</a>(default_block_skew);</div><div class="line"><a name="l00836"></a><span class="lineno"> 836</span>  bl_block-><a class="code" href="a04661.html#a0619e15482a4ed11dce15bc5d8cbe0be">SetupBlockParameters</a>(); <span class="comment">// This replaced compute_row_stats.</span></div><div class="line"><a name="l00837"></a><span class="lineno"> 837</span>  }</div><div class="line"><a name="l00838"></a><span class="lineno"> 838</span> }</div><div class="line"><a name="l00839"></a><span class="lineno"> 839</span> </div><div class="line"><a name="l00840"></a><span class="lineno"> 840</span> <span class="comment">// Computes the baseline splines for each TO_ROW in each TO_BLOCK and</span></div><div class="line"><a name="l00841"></a><span class="lineno"> 841</span> <span class="comment">// other associated side-effects, including pre-associating blobs, computing</span></div><div class="line"><a name="l00842"></a><span class="lineno"> 842</span> <span class="comment">// x-heights and displaying debug information.</span></div><div class="line"><a name="l00843"></a><span class="lineno"> 843</span> <span class="comment">// NOTE that ComputeStraightBaselines must have been called first as this</span></div><div class="line"><a name="l00844"></a><span class="lineno"> 844</span> <span class="comment">// sets up data in the TO_ROWs upon which this function depends.</span></div><div class="line"><a name="l00845"></a><span class="lineno"><a class="line" href="a04665.html#a62154b468dd5af9b00a158542be42b6c"> 845</a></span> <span class="keywordtype">void</span> <a class="code" href="a04665.html#a62154b468dd5af9b00a158542be42b6c">BaselineDetect::ComputeBaselineSplinesAndXheights</a>(<span class="keyword">const</span> <a class="code" href="a02673.html">ICOORD</a>& page_tr,</div><div class="line"><a name="l00846"></a><span class="lineno"> 846</span>  <span class="keywordtype">bool</span> enable_splines,</div><div class="line"><a name="l00847"></a><span class="lineno"> 847</span>  <span class="keywordtype">bool</span> remove_noise,</div><div class="line"><a name="l00848"></a><span class="lineno"> 848</span>  <span class="keywordtype">bool</span> show_final_rows,</div><div class="line"><a name="l00849"></a><span class="lineno"> 849</span>  <a class="code" href="a04841.html">Textord</a>* textord) {</div><div class="line"><a name="l00850"></a><span class="lineno"> 850</span>  Pix* pix_spline = pix_debug_ ? pixConvertTo32(pix_debug_) : NULL;</div><div class="line"><a name="l00851"></a><span class="lineno"> 851</span>  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < blocks_.size(); ++i) {</div><div class="line"><a name="l00852"></a><span class="lineno"> 852</span>  <a class="code" href="a04661.html">BaselineBlock</a>* bl_block = blocks_[i];</div><div class="line"><a name="l00853"></a><span class="lineno"> 853</span>  <span class="keywordflow">if</span> (enable_splines)</div><div class="line"><a name="l00854"></a><span class="lineno"> 854</span>  bl_block-><a class="code" href="a04661.html#ab6e80c4b218c94c056659659a4d5e59b">PrepareForSplineFitting</a>(page_tr, remove_noise);</div><div class="line"><a name="l00855"></a><span class="lineno"> 855</span>  bl_block-><a class="code" href="a04661.html#a198bcc873e579e4798f4a8ed82fdb543">FitBaselineSplines</a>(enable_splines, show_final_rows, textord);</div><div class="line"><a name="l00856"></a><span class="lineno"> 856</span>  <span class="keywordflow">if</span> (pix_spline) {</div><div class="line"><a name="l00857"></a><span class="lineno"> 857</span>  bl_block-><a class="code" href="a04661.html#a858165c88e4c695fa2136bac7ed97b7f">DrawPixSpline</a>(pix_spline);</div><div class="line"><a name="l00858"></a><span class="lineno"> 858</span>  }</div><div class="line"><a name="l00859"></a><span class="lineno"> 859</span>  <span class="keywordflow">if</span> (show_final_rows) {</div><div class="line"><a name="l00860"></a><span class="lineno"> 860</span>  bl_block-><a class="code" href="a04661.html#a682d76ce63cdca26f2a1b33d57ffc2ab">DrawFinalRows</a>(page_tr);</div><div class="line"><a name="l00861"></a><span class="lineno"> 861</span>  }</div><div class="line"><a name="l00862"></a><span class="lineno"> 862</span>  }</div><div class="line"><a name="l00863"></a><span class="lineno"> 863</span> </div><div class="line"><a name="l00864"></a><span class="lineno"> 864</span>  <span class="keywordflow">if</span> (pix_spline) {</div><div class="line"><a name="l00865"></a><span class="lineno"> 865</span>  <a class="code" href="a02929.html">STRING</a> outfile_name = debug_file_prefix_ + <span class="stringliteral">"_spline.png"</span>;</div><div class="line"><a name="l00866"></a><span class="lineno"> 866</span>  pixWrite(outfile_name.<a class="code" href="a02929.html#abf0a7b3c6ae39a46e5441f28f61de5de">string</a>(), pix_spline, IFF_PNG);</div><div class="line"><a name="l00867"></a><span class="lineno"> 867</span>  pixDestroy(&pix_spline);</div><div class="line"><a name="l00868"></a><span class="lineno"> 868</span>  }</div><div class="line"><a name="l00869"></a><span class="lineno"> 869</span> }</div><div class="line"><a name="l00870"></a><span class="lineno"> 870</span> </div><div class="line"><a name="l00871"></a><span class="lineno"><a class="line" href="a04665.html#a65bfc0db936ca70518593788669d256a"> 871</a></span> <span class="keywordtype">void</span> <a class="code" href="a04665.html#a65bfc0db936ca70518593788669d256a">BaselineDetect::SetDebugImage</a>(Pix* pixIn, <span class="keyword">const</span> <a class="code" href="a02929.html">STRING</a>& output_path) {</div><div class="line"><a name="l00872"></a><span class="lineno"> 872</span>  pixDestroy(&pix_debug_);</div><div class="line"><a name="l00873"></a><span class="lineno"> 873</span>  pix_debug_ = pixClone(pixIn);</div><div class="line"><a name="l00874"></a><span class="lineno"> 874</span>  debug_file_prefix_ = output_path;</div><div class="line"><a name="l00875"></a><span class="lineno"> 875</span> }</div><div class="line"><a name="l00876"></a><span class="lineno"> 876</span> </div><div class="line"><a name="l00877"></a><span class="lineno"> 877</span> } <span class="comment">// namespace tesseract.</span></div><div class="ttc" id="a01328_html"><div class="ttname"><a href="a01328.html">drawtord.h</a></div></div> <div class="ttc" id="a04665_html_a9eaa0eba10b5abb2a9813f521c9dba50"><div class="ttname"><a href="a04665.html#a9eaa0eba10b5abb2a9813f521c9dba50">tesseract::BaselineDetect::ComputeStraightBaselines</a></div><div class="ttdeci">void ComputeStraightBaselines(bool use_box_bottoms)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00813">baselinedetect.cpp:813</a></div></div> <div class="ttc" id="a01325_html_af8aae7bd42a61b839e724a34c07b42ab"><div class="ttname"><a href="a01325.html#af8aae7bd42a61b839e724a34c07b42ab">draw_meanlines</a></div><div class="ttdeci">void draw_meanlines(TO_BLOCK *block, float gradient, inT32 left, ScrollView::Color colour, FCOORD rotation)</div><div class="ttdef"><b>Definition:</b> <a href="a01325_source.html#l00210">drawtord.cpp:210</a></div></div> <div class="ttc" id="a02481_html_acc27a54c9735f05e9152ba5f1c1a8261"><div class="ttname"><a href="a02481.html#acc27a54c9735f05e9152ba5f1c1a8261">BLOBNBOX::bounding_box</a></div><div class="ttdeci">const TBOX & bounding_box() const</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00215">blobbox.h:215</a></div></div> <div class="ttc" id="a04929_html_a100504544a5423a94222149ee9ed0fe8a61dec9bc0aaf1d527a731b2a6ce055c8"><div class="ttname"><a href="a04929.html#a100504544a5423a94222149ee9ed0fe8a61dec9bc0aaf1d527a731b2a6ce055c8">ScrollView::YELLOW</a></div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00110">scrollview.h:110</a></div></div> <div class="ttc" id="a01325_html_afd5bee79bdf1ea9c211c3a3519d25251"><div class="ttname"><a href="a01325.html#afd5bee79bdf1ea9c211c3a3519d25251">create_to_win</a></div><div class="ttdeci">ScrollView * create_to_win(ICOORD page_tr)</div><div class="ttdef"><b>Definition:</b> <a href="a01325_source.html#l00047">drawtord.cpp:47</a></div></div> <div class="ttc" id="a02533_html_a97c074bfc1d7106ddda618ea8cf45ff7"><div class="ttname"><a href="a02533.html#a97c074bfc1d7106ddda618ea8cf45ff7">tesseract::DetLineFit::Clear</a></div><div class="ttdeci">void Clear()</div><div class="ttdef"><b>Definition:</b> <a href="a00251_source.html#l00046">detlinefit.cpp:46</a></div></div> <div class="ttc" id="a01373_html_a004e5d894712f552369ef523a09bc3ce"><div class="ttname"><a href="a01373.html#a004e5d894712f552369ef523a09bc3ce">separate_underlines</a></div><div class="ttdeci">void separate_underlines(TO_BLOCK *block, float gradient, FCOORD rotation, BOOL8 testing_on)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l01789">makerow.cpp:1789</a></div></div> <div class="ttc" id="a02589_html_a14be1135a936c540eea93455c19c70f1"><div class="ttname"><a href="a02589.html#a14be1135a936c540eea93455c19c70f1">LLSQ::m</a></div><div class="ttdeci">double m() const</div><div class="ttdef"><b>Definition:</b> <a href="a00287_source.html#l00101">linlsq.cpp:101</a></div></div> <div class="ttc" id="a00521_html_a6eb00eb9bc5ed195953f334971c462ae"><div class="ttname"><a href="a00521.html#a6eb00eb9bc5ed195953f334971c462ae">UpdateRange</a></div><div class="ttdeci">void UpdateRange(const T1 &x, T2 *lower_bound, T2 *upper_bound)</div><div class="ttdef"><b>Definition:</b> <a href="a00521_source.html#l00125">helpers.h:125</a></div></div> <div class="ttc" id="a02297_html"><div class="ttname"><a href="a02297.html">GenericVector< double ></a></div></div> <div class="ttc" id="a00521_html_ab60e4f82956a1f5fdb54d0d8303e95b7"><div class="ttname"><a href="a00521.html#ab60e4f82956a1f5fdb54d0d8303e95b7">IntCastRounded</a></div><div class="ttdeci">int IntCastRounded(double x)</div><div class="ttdef"><b>Definition:</b> <a href="a00521_source.html#l00172">helpers.h:172</a></div></div> <div class="ttc" id="a04841_html_a3c5b9cc1053a9abd5fad5d7eca25186b"><div class="ttname"><a href="a04841.html#a3c5b9cc1053a9abd5fad5d7eca25186b">tesseract::Textord::make_spline_rows</a></div><div class="ttdeci">void make_spline_rows(TO_BLOCK *block, float gradient, BOOL8 testing_on)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l02020">makerow.cpp:2020</a></div></div> <div class="ttc" id="a01448_html"><div class="ttname"><a href="a01448.html">textord.h</a></div></div> <div class="ttc" id="a02589_html_a6139b78394a33f9447d84a575a10f471"><div class="ttname"><a href="a02589.html#a6139b78394a33f9447d84a575a10f471">LLSQ::rms</a></div><div class="ttdeci">double rms(double m, double c) const</div><div class="ttdef"><b>Definition:</b> <a href="a00287_source.html#l00131">linlsq.cpp:131</a></div></div> <div class="ttc" id="a02485_html"><div class="ttname"><a href="a02485.html">TO_ROW</a></div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00539">blobbox.h:539</a></div></div> <div class="ttc" id="a02685_html"><div class="ttname"><a href="a02685.html">POLY_BLOCK</a></div><div class="ttdef"><b>Definition:</b> <a href="a00368_source.html#l00028">polyblk.h:28</a></div></div> <div class="ttc" id="a04657_html_a0abf3f82fd5ab3b3a79a23a2c030547e"><div class="ttname"><a href="a04657.html#a0abf3f82fd5ab3b3a79a23a2c030547e">tesseract::BaselineRow::FitBaseline</a></div><div class="ttdeci">bool FitBaseline(bool use_box_bottoms)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00142">baselinedetect.cpp:142</a></div></div> <div class="ttc" id="a02673_html"><div class="ttname"><a href="a02673.html">ICOORD</a></div><div class="ttdoc">integer coordinate </div><div class="ttdef"><b>Definition:</b> <a href="a00356_source.html#l00030">points.h:30</a></div></div> <div class="ttc" id="a02617_html_a761f9b58bfeef6d485001b707fb9939b"><div class="ttname"><a href="a02617.html#a761f9b58bfeef6d485001b707fb9939b">BLOCK::set_xheight</a></div><div class="ttdeci">void set_xheight(inT32 height)</div><div class="ttdoc">set char size </div><div class="ttdef"><b>Definition:</b> <a href="a00314_source.html#l00072">ocrblock.h:72</a></div></div> <div class="ttc" id="a02297_html_a9cdbff49b186574b83e43afba606fdd9"><div class="ttname"><a href="a02297.html#a9cdbff49b186574b83e43afba606fdd9">GenericVector::clear</a></div><div class="ttdeci">void clear()</div><div class="ttdef"><b>Definition:</b> <a href="a00509_source.html#l00835">genericvector.h:835</a></div></div> <div class="ttc" id="a02489_html_ac17b9c95641b2eebee9d972338c2e5f6"><div class="ttname"><a href="a02489.html#ac17b9c95641b2eebee9d972338c2e5f6">TO_BLOCK::line_spacing</a></div><div class="ttdeci">float line_spacing</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00775">blobbox.h:775</a></div></div> <div class="ttc" id="a01738_html_a8043339cb79428cd76d41f5432de9712"><div class="ttname"><a href="a01738.html#a8043339cb79428cd76d41f5432de9712">tesseract::kMaxBaselineError</a></div><div class="ttdeci">const double kMaxBaselineError</div><div class="ttdef"><b>Definition:</b> <a href="a01295_source.html#l00072">colpartition.cpp:72</a></div></div> <div class="ttc" id="a02489_html_a5dd67c54162a6b60b0fd11500d4a3025"><div class="ttname"><a href="a02489.html#a5dd67c54162a6b60b0fd11500d4a3025">TO_BLOCK::blobs</a></div><div class="ttdeci">BLOBNBOX_LIST blobs</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00768">blobbox.h:768</a></div></div> <div class="ttc" id="a04665_html_a358fd732758ac23b5a20413344204087"><div class="ttname"><a href="a04665.html#a358fd732758ac23b5a20413344204087">tesseract::BaselineDetect::BaselineDetect</a></div><div class="ttdeci">BaselineDetect(int debug_level, const FCOORD &page_skew, TO_BLOCK_LIST *blocks)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00786">baselinedetect.cpp:786</a></div></div> <div class="ttc" id="a02489_html_a16e698664028b0d6d2193db64560c16b"><div class="ttname"><a href="a02489.html#a16e698664028b0d6d2193db64560c16b">TO_BLOCK::block</a></div><div class="ttdeci">BLOCK * block</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00773">blobbox.h:773</a></div></div> <div class="ttc" id="a01256_html"><div class="ttname"><a href="a01256.html">baselinedetect.h</a></div></div> <div class="ttc" id="a02533_html_a768ec4a8f90593d8d679981c873f7a56"><div class="ttname"><a href="a02533.html#a768ec4a8f90593d8d679981c873f7a56">tesseract::DetLineFit::Fit</a></div><div class="ttdeci">double Fit(ICOORD *pt1, ICOORD *pt2)</div><div class="ttdef"><b>Definition:</b> <a href="a00254_source.html#l00075">detlinefit.h:75</a></div></div> <div class="ttc" id="a02713_html_aa51d4de109edfcba0508ce301da67031"><div class="ttname"><a href="a02713.html#aa51d4de109edfcba0508ce301da67031">TBOX::width</a></div><div class="ttdeci">inT16 width() const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00111">rect.h:111</a></div></div> <div class="ttc" id="a02533_html_a4eba2b6e761080e5d1a48c9c797257b2"><div class="ttname"><a href="a02533.html#a4eba2b6e761080e5d1a48c9c797257b2">tesseract::DetLineFit::Add</a></div><div class="ttdeci">void Add(const ICOORD &pt)</div><div class="ttdef"><b>Definition:</b> <a href="a00251_source.html#l00052">detlinefit.cpp:52</a></div></div> <div class="ttc" id="a00548_html_a74e75242132eaabbc1c512488a135926"><div class="ttname"><a href="a00548.html#a74e75242132eaabbc1c512488a135926">MIN</a></div><div class="ttdeci">#define MIN(x, y)</div><div class="ttdef"><b>Definition:</b> <a href="a00548_source.html#l00028">ndminx.h:28</a></div></div> <div class="ttc" id="a04929_html_a100504544a5423a94222149ee9ed0fe8a0eab2b208fc9a5e2774f92cf3e768982"><div class="ttname"><a href="a04929.html#a100504544a5423a94222149ee9ed0fe8a0eab2b208fc9a5e2774f92cf3e768982">ScrollView::WHITE</a></div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00108">scrollview.h:108</a></div></div> <div class="ttc" id="a00521_html"><div class="ttname"><a href="a00521.html">helpers.h</a></div></div> <div class="ttc" id="a02489_html_ab106233da0599f3e1595c1c765acadec"><div class="ttname"><a href="a02489.html#ab106233da0599f3e1595c1c765acadec">TO_BLOCK::line_size</a></div><div class="ttdeci">float line_size</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00781">blobbox.h:781</a></div></div> <div class="ttc" id="a04661_html_a381942ef00fcff77a75d036fac9b3fa5"><div class="ttname"><a href="a04661.html#a381942ef00fcff77a75d036fac9b3fa5">tesseract::BaselineBlock::block</a></div><div class="ttdeci">TO_BLOCK * block() const</div><div class="ttdef"><b>Definition:</b> <a href="a01256_source.html#l00133">baselinedetect.h:133</a></div></div> <div class="ttc" id="a02485_html_a448dbcbfc8d6c3c9c5e8c2fb127fd9d9"><div class="ttname"><a href="a02485.html#a448dbcbfc8d6c3c9c5e8c2fb127fd9d9">TO_ROW::set_parallel_line</a></div><div class="ttdeci">void set_parallel_line(float gradient, float new_c, float new_error)</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00607">blobbox.h:607</a></div></div> <div class="ttc" id="a02533_html_a6ef9f742eafdfaad81a30a3799800725"><div class="ttname"><a href="a02533.html#a6ef9f742eafdfaad81a30a3799800725">tesseract::DetLineFit::ConstrainedFit</a></div><div class="ttdeci">double ConstrainedFit(const FCOORD &direction, double min_dist, double max_dist, bool debug, ICOORD *line_pt)</div><div class="ttdef"><b>Definition:</b> <a href="a00251_source.html#l00131">detlinefit.cpp:131</a></div></div> <div class="ttc" id="a04657_html_ac81135eb24c3d936f7c1d9e81567cae8"><div class="ttname"><a href="a04657.html#ac81135eb24c3d936f7c1d9e81567cae8">tesseract::BaselineRow::AdjustBaselineToGrid</a></div><div class="ttdeci">double AdjustBaselineToGrid(int debug, const FCOORD &direction, double line_spacing, double line_offset)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00229">baselinedetect.cpp:229</a></div></div> <div class="ttc" id="a01376_html"><div class="ttname"><a href="a01376.html">makerow.h</a></div></div> <div class="ttc" id="a02701_html"><div class="ttname"><a href="a02701.html">QSPLINE</a></div><div class="ttdef"><b>Definition:</b> <a href="a00389_source.html#l00031">quspline.h:31</a></div></div> <div class="ttc" id="a04929_html_a100504544a5423a94222149ee9ed0fe8a0959f7470b08ae1a38aa7e38fba29402"><div class="ttname"><a href="a04929.html#a100504544a5423a94222149ee9ed0fe8a0959f7470b08ae1a38aa7e38fba29402">ScrollView::RED</a></div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00109">scrollview.h:109</a></div></div> <div class="ttc" id="a01253_html_aa447e3d51461981e8e7c5450e57d9300"><div class="ttname"><a href="a01253.html#aa447e3d51461981e8e7c5450e57d9300">kMaxSkewDeviation</a></div><div class="ttdeci">const double kMaxSkewDeviation</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00047">baselinedetect.cpp:47</a></div></div> <div class="ttc" id="a04661_html_a8a7ab56dd7abc0421cff9680b6634b85"><div class="ttname"><a href="a04661.html#a8a7ab56dd7abc0421cff9680b6634b85">tesseract::BaselineBlock::ParallelizeBaselines</a></div><div class="ttdeci">void ParallelizeBaselines(double default_block_skew)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00458">baselinedetect.cpp:458</a></div></div> <div class="ttc" id="a02589_html_aa439294be0539828cf042f8941125b3c"><div class="ttname"><a href="a02589.html#aa439294be0539828cf042f8941125b3c">LLSQ::add</a></div><div class="ttdeci">void add(double x, double y)</div><div class="ttdef"><b>Definition:</b> <a href="a00287_source.html#l00049">linlsq.cpp:49</a></div></div> <div class="ttc" id="a02489_html_abb8334b4a0c2b2625516a1c4b54cbf1f"><div class="ttname"><a href="a02489.html#abb8334b4a0c2b2625516a1c4b54cbf1f">TO_BLOCK::baseline_offset</a></div><div class="ttdeci">float baseline_offset</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00783">blobbox.h:783</a></div></div> <div class="ttc" id="a04929_html_a100504544a5423a94222149ee9ed0fe8a9a954d0f0149ee883cbcc5e0a379b460"><div class="ttname"><a href="a04929.html#a100504544a5423a94222149ee9ed0fe8a9a954d0f0149ee883cbcc5e0a379b460">ScrollView::CORAL</a></div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00124">scrollview.h:124</a></div></div> <div class="ttc" id="a04661_html_ac12d056a2cc07b32b381d836126c4fa8"><div class="ttname"><a href="a04661.html#ac12d056a2cc07b32b381d836126c4fa8">tesseract::BaselineBlock::SpacingModelError</a></div><div class="ttdeci">static double SpacingModelError(double perp_disp, double line_spacing, double line_offset)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00417">baselinedetect.cpp:417</a></div></div> <div class="ttc" id="a04661_html_a198bcc873e579e4798f4a8ed82fdb543"><div class="ttname"><a href="a04661.html#a198bcc873e579e4798f4a8ed82fdb543">tesseract::BaselineBlock::FitBaselineSplines</a></div><div class="ttdeci">void FitBaselineSplines(bool enable_splines, bool show_final_rows, Textord *textord)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00543">baselinedetect.cpp:543</a></div></div> <div class="ttc" id="a02297_html_a0dc89fe2a365b04a61017f9d78c1a303"><div class="ttname"><a href="a02297.html#a0dc89fe2a365b04a61017f9d78c1a303">GenericVector::push_back</a></div><div class="ttdeci">int push_back(T object)</div><div class="ttdef"><b>Definition:</b> <a href="a00509_source.html#l00766">genericvector.h:766</a></div></div> <div class="ttc" id="a01373_html_a71e57df4cbaf6a0d8fb156f0604d1033"><div class="ttname"><a href="a01373.html#a71e57df4cbaf6a0d8fb156f0604d1033">blob_x_order</a></div><div class="ttdeci">int blob_x_order(const void *item1, const void *item2)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l02591">makerow.cpp:2591</a></div></div> <div class="ttc" id="a02661_html_a87856f8400f0629dc761fec0f7a17b57"><div class="ttname"><a href="a02661.html#a87856f8400f0629dc761fec0f7a17b57">PDBLK::poly_block</a></div><div class="ttdeci">POLY_BLOCK * poly_block() const</div><div class="ttdef"><b>Definition:</b> <a href="a00350_source.html#l00055">pdblock.h:55</a></div></div> <div class="ttc" id="a02485_html_aeba2135f371c89fd310f0443f79c8f43"><div class="ttname"><a href="a02485.html#aeba2135f371c89fd310f0443f79c8f43">TO_ROW::line_m</a></div><div class="ttdeci">float line_m() const</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00566">blobbox.h:566</a></div></div> <div class="ttc" id="a00524_html_a9adcee815220ec9db98062213806ed04"><div class="ttname"><a href="a00524.html#a9adcee815220ec9db98062213806ed04">MAX_FLOAT32</a></div><div class="ttdeci">#define MAX_FLOAT32</div><div class="ttdef"><b>Definition:</b> <a href="a00524_source.html#l00057">host.h:57</a></div></div> <div class="ttc" id="a00209_html"><div class="ttname"><a href="a00209.html">blobbox.h</a></div></div> <div class="ttc" id="a02713_html_ade947e3871fa316e3e0b0864905c2997"><div class="ttname"><a href="a02713.html#ade947e3871fa316e3e0b0864905c2997">TBOX::major_x_overlap</a></div><div class="ttdeci">bool major_x_overlap(const TBOX &box) const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00402">rect.h:402</a></div></div> <div class="ttc" id="a02485_html_a4db47940276e2aa20f409877aa953360"><div class="ttname"><a href="a02485.html#a4db47940276e2aa20f409877aa953360">TO_ROW::line_c</a></div><div class="ttdeci">float line_c() const</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00569">blobbox.h:569</a></div></div> <div class="ttc" id="a04661_html_a682d76ce63cdca26f2a1b33d57ffc2ab"><div class="ttname"><a href="a04661.html#a682d76ce63cdca26f2a1b33d57ffc2ab">tesseract::BaselineBlock::DrawFinalRows</a></div><div class="ttdeci">void DrawFinalRows(const ICOORD &page_tr)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00572">baselinedetect.cpp:572</a></div></div> <div class="ttc" id="a00290_html_abde6267e843aeeea5089d458c465dee2"><div class="ttname"><a href="a00290.html#abde6267e843aeeea5089d458c465dee2">MedianOfCircularValues</a></div><div class="ttdeci">T MedianOfCircularValues(T modulus, GenericVector< T > *v)</div><div class="ttdef"><b>Definition:</b> <a href="a00290_source.html#l00111">linlsq.h:111</a></div></div> <div class="ttc" id="a00290_html"><div class="ttname"><a href="a00290.html">linlsq.h</a></div></div> <div class="ttc" id="a02713_html_ae20440e936439218b9dfe267b8a37b4a"><div class="ttname"><a href="a02713.html#ae20440e936439218b9dfe267b8a37b4a">TBOX::bottom</a></div><div class="ttdeci">inT16 bottom() const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00061">rect.h:61</a></div></div> <div class="ttc" id="a02481_html_af5dd7efebd6cc0e393086d7eda8eb446"><div class="ttname"><a href="a02481.html#af5dd7efebd6cc0e393086d7eda8eb446">BLOBNBOX::baseline_position</a></div><div class="ttdeci">int baseline_position() const</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00374">blobbox.h:374</a></div></div> <div class="ttc" id="a02489_html_abe8092e46729fbddf38f16ad7ca07318"><div class="ttname"><a href="a02489.html#abe8092e46729fbddf38f16ad7ca07318">TO_BLOCK::underlines</a></div><div class="ttdeci">BLOBNBOX_LIST underlines</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00769">blobbox.h:769</a></div></div> <div class="ttc" id="a04841_html"><div class="ttname"><a href="a04841.html">tesseract::Textord</a></div><div class="ttdef"><b>Definition:</b> <a href="a01448_source.html#l00068">textord.h:68</a></div></div> <div class="ttc" id="a02929_html_abf0a7b3c6ae39a46e5441f28f61de5de"><div class="ttname"><a href="a02929.html#abf0a7b3c6ae39a46e5441f28f61de5de">STRING::string</a></div><div class="ttdeci">const char * string() const</div><div class="ttdef"><b>Definition:</b> <a href="a00590_source.html#l00201">strngs.cpp:201</a></div></div> <div class="ttc" id="a02533_html_ac3f1ddb7945dc8b37ed69e64357276f6"><div class="ttname"><a href="a02533.html#ac3f1ddb7945dc8b37ed69e64357276f6">tesseract::DetLineFit::SufficientPointsForIndependentFit</a></div><div class="ttdeci">bool SufficientPointsForIndependentFit() const</div><div class="ttdef"><b>Definition:</b> <a href="a00251_source.html#l00163">detlinefit.cpp:163</a></div></div> <div class="ttc" id="a04841_html_ae256bbff96a055ef49a86fbba393c98a"><div class="ttname"><a href="a04841.html#ae256bbff96a055ef49a86fbba393c98a">tesseract::Textord::compute_block_xheight</a></div><div class="ttdeci">void compute_block_xheight(TO_BLOCK *block, float gradient)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l01271">makerow.cpp:1271</a></div></div> <div class="ttc" id="a01475_html"><div class="ttname"><a href="a01475.html">underlin.h</a></div></div> <div class="ttc" id="a02489_html_a4d0f99a557a4950af5123a31a157749f"><div class="ttname"><a href="a02489.html#a4d0f99a557a4950af5123a31a157749f">TO_BLOCK::xheight</a></div><div class="ttdeci">float xheight</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00784">blobbox.h:784</a></div></div> <div class="ttc" id="a04665_html_ad8ef6bb9dd7e29cd0a465640dae1da9b"><div class="ttname"><a href="a04665.html#ad8ef6bb9dd7e29cd0a465640dae1da9b">tesseract::BaselineDetect::~BaselineDetect</a></div><div class="ttdeci">~BaselineDetect()</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00806">baselinedetect.cpp:806</a></div></div> <div class="ttc" id="a04661_html"><div class="ttname"><a href="a04661.html">tesseract::BaselineBlock</a></div><div class="ttdef"><b>Definition:</b> <a href="a01256_source.html#l00129">baselinedetect.h:129</a></div></div> <div class="ttc" id="a04661_html_ab6e80c4b218c94c056659659a4d5e59b"><div class="ttname"><a href="a04661.html#ab6e80c4b218c94c056659659a4d5e59b">tesseract::BaselineBlock::PrepareForSplineFitting</a></div><div class="ttdeci">void PrepareForSplineFitting(ICOORD page_tr, bool remove_noise)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00527">baselinedetect.cpp:527</a></div></div> <div class="ttc" id="a01738_html"><div class="ttname"><a href="a01738.html">tesseract</a></div><div class="ttdef"><b>Definition:</b> <a href="a00005_source.html#l00081">baseapi.cpp:81</a></div></div> <div class="ttc" id="a04929_html_a100504544a5423a94222149ee9ed0fe8"><div class="ttname"><a href="a04929.html#a100504544a5423a94222149ee9ed0fe8">ScrollView::Color</a></div><div class="ttdeci">Color</div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00105">scrollview.h:105</a></div></div> <div class="ttc" id="a02713_html_affd18574697b2b707cee416f7cdccb1f"><div class="ttname"><a href="a02713.html#affd18574697b2b707cee416f7cdccb1f">TBOX::left</a></div><div class="ttdeci">inT16 left() const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00068">rect.h:68</a></div></div> <div class="ttc" id="a02681_html_abb9516f874133b689b0e62ac70874385"><div class="ttname"><a href="a02681.html#abb9516f874133b689b0e62ac70874385">FCOORD::y</a></div><div class="ttdeci">float y() const</div><div class="ttdef"><b>Definition:</b> <a href="a00356_source.html#l00212">points.h:212</a></div></div> <div class="ttc" id="a00206_html_a331e6744e04cb0a2fb23c1465c82196c"><div class="ttname"><a href="a00206.html#a331e6744e04cb0a2fb23c1465c82196c">plot_blob_list</a></div><div class="ttdeci">void plot_blob_list(ScrollView *win, BLOBNBOX_LIST *list, ScrollView::Color body_colour, ScrollView::Color child_colour)</div><div class="ttdef"><b>Definition:</b> <a href="a00206_source.html#l01082">blobbox.cpp:1082</a></div></div> <div class="ttc" id="a01253_html_a46b90f606788891fac29c14f20f39b27"><div class="ttname"><a href="a01253.html#a46b90f606788891fac29c14f20f39b27">kMaxBlobSizeMultiple</a></div><div class="ttdeci">const double kMaxBlobSizeMultiple</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00056">baselinedetect.cpp:56</a></div></div> <div class="ttc" id="a02489_html_a4846ebdcc832b4b0a762d87c0d83a056"><div class="ttname"><a href="a02489.html#a4846ebdcc832b4b0a762d87c0d83a056">TO_BLOCK::get_rows</a></div><div class="ttdeci">TO_ROW_LIST * get_rows()</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00700">blobbox.h:700</a></div></div> <div class="ttc" id="a02297_html_a980882b5ebc3e72fdedbdbe345196f21"><div class="ttname"><a href="a02297.html#a980882b5ebc3e72fdedbdbe345196f21">GenericVector::truncate</a></div><div class="ttdeci">void truncate(int size)</div><div class="ttdef"><b>Definition:</b> <a href="a00509_source.html#l00130">genericvector.h:130</a></div></div> <div class="ttc" id="a02713_html_a61af64df548c7638bf005fcd8343c435"><div class="ttname"><a href="a02713.html#a61af64df548c7638bf005fcd8343c435">TBOX::print</a></div><div class="ttdeci">void print() const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00270">rect.h:270</a></div></div> <div class="ttc" id="a01253_html_a5acb8f8490c1a3b68684d10c460e1e96"><div class="ttname"><a href="a01253.html#a5acb8f8490c1a3b68684d10c460e1e96">kFitHalfrangeFactor</a></div><div class="ttdeci">const double kFitHalfrangeFactor</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00051">baselinedetect.cpp:51</a></div></div> <div class="ttc" id="a00434_html_a57d4a186a22b01e2110793bc22a5d8f0"><div class="ttname"><a href="a00434.html#a57d4a186a22b01e2110793bc22a5d8f0">direction</a></div><div class="ttdeci">int direction(EDGEPT *point)</div><div class="ttdef"><b>Definition:</b> <a href="a00434_source.html#l00043">vecfuncs.cpp:43</a></div></div> <div class="ttc" id="a04929_html"><div class="ttname"><a href="a04929.html">ScrollView</a></div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00102">scrollview.h:102</a></div></div> <div class="ttc" id="a00548_html_aacc3ee1a7f283f8ef65cea31f4436a95"><div class="ttname"><a href="a00548.html#aacc3ee1a7f283f8ef65cea31f4436a95">MAX</a></div><div class="ttdeci">#define MAX(x, y)</div><div class="ttdef"><b>Definition:</b> <a href="a00548_source.html#l00024">ndminx.h:24</a></div></div> <div class="ttc" id="a00524_html_aba1f582fd0168f3ff9225d8c90fa9eb8"><div class="ttname"><a href="a00524.html#aba1f582fd0168f3ff9225d8c90fa9eb8">inT32</a></div><div class="ttdeci">int inT32</div><div class="ttdef"><b>Definition:</b> <a href="a00524_source.html#l00035">host.h:35</a></div></div> <div class="ttc" id="a02485_html_a611050c4612df0ccd0f2d64ca0005b9b"><div class="ttname"><a href="a02485.html#a611050c4612df0ccd0f2d64ca0005b9b">TO_ROW::baseline</a></div><div class="ttdeci">QSPLINE baseline</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00666">blobbox.h:666</a></div></div> <div class="ttc" id="a00254_html"><div class="ttname"><a href="a00254.html">detlinefit.h</a></div></div> <div class="ttc" id="a01253_html_a5c9c93517d2f2243b2b265cb1e3b03db"><div class="ttname"><a href="a01253.html#a5c9c93517d2f2243b2b265cb1e3b03db">kOffsetQuantizationFactor</a></div><div class="ttdeci">const double kOffsetQuantizationFactor</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00049">baselinedetect.cpp:49</a></div></div> <div class="ttc" id="a00608_html_a02aa7cca2c3857c14716e8cca96ace6c"><div class="ttname"><a href="a00608.html#a02aa7cca2c3857c14716e8cca96ace6c">tprintf</a></div><div class="ttdeci">#define tprintf(...)</div><div class="ttdef"><b>Definition:</b> <a href="a00608_source.html#l00031">tprintf.h:31</a></div></div> <div class="ttc" id="a00524_html_aac62d87844689a18b6f5339a89ed6e7f"><div class="ttname"><a href="a00524.html#aac62d87844689a18b6f5339a89ed6e7f">MAX_INT32</a></div><div class="ttdeci">#define MAX_INT32</div><div class="ttdef"><b>Definition:</b> <a href="a00524_source.html#l00053">host.h:53</a></div></div> <div class="ttc" id="a02481_html"><div class="ttname"><a href="a02481.html">BLOBNBOX</a></div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00128">blobbox.h:128</a></div></div> <div class="ttc" id="a02929_html"><div class="ttname"><a href="a02929.html">STRING</a></div><div class="ttdef"><b>Definition:</b> <a href="a00593_source.html#l00044">strngs.h:44</a></div></div> <div class="ttc" id="a04657_html_a31f1ab3eb5a4d39c7956b9ad7fba07b0"><div class="ttname"><a href="a04657.html#a31f1ab3eb5a4d39c7956b9ad7fba07b0">tesseract::BaselineRow::PerpDisp</a></div><div class="ttdeci">double PerpDisp(const FCOORD &direction) const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00121">baselinedetect.cpp:121</a></div></div> <div class="ttc" id="a02297_html_a20cfad5c58c50cb85a9529d8ddbd96af"><div class="ttname"><a href="a02297.html#a20cfad5c58c50cb85a9529d8ddbd96af">GenericVector::size</a></div><div class="ttdeci">int size() const</div><div class="ttdef"><b>Definition:</b> <a href="a00509_source.html#l00072">genericvector.h:72</a></div></div> <div class="ttc" id="a02681_html"><div class="ttname"><a href="a02681.html">FCOORD</a></div><div class="ttdef"><b>Definition:</b> <a href="a00356_source.html#l00189">points.h:189</a></div></div> <div class="ttc" id="a02685_html_a4eb55be5fc2ed33312e4410f5ee2cf88"><div class="ttname"><a href="a02685.html#a4eb55be5fc2ed33312e4410f5ee2cf88">POLY_BLOCK::IsText</a></div><div class="ttdeci">bool IsText() const</div><div class="ttdef"><b>Definition:</b> <a href="a00368_source.html#l00052">polyblk.h:52</a></div></div> <div class="ttc" id="a02617_html"><div class="ttname"><a href="a02617.html">BLOCK</a></div><div class="ttdef"><b>Definition:</b> <a href="a00314_source.html#l00030">ocrblock.h:30</a></div></div> <div class="ttc" id="a04657_html_aa0f2797e274179798e95e7e2cafb424f"><div class="ttname"><a href="a04657.html#aa0f2797e274179798e95e7e2cafb424f">tesseract::BaselineRow::StraightYAtX</a></div><div class="ttdeci">double StraightYAtX(double x) const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00129">baselinedetect.cpp:129</a></div></div> <div class="ttc" id="a02481_html_a4ed2225c09f0ffbf08cb45ef6dbb40b4"><div class="ttname"><a href="a02481.html#a4ed2225c09f0ffbf08cb45ef6dbb40b4">BLOBNBOX::EstimateBaselinePosition</a></div><div class="ttdeci">void EstimateBaselinePosition()</div><div class="ttdef"><b>Definition:</b> <a href="a00206_source.html#l00352">blobbox.cpp:352</a></div></div> <div class="ttc" id="a01472_html_a3b7ff031211912735f61bd0dc97c6f2b"><div class="ttname"><a href="a01472.html#a3b7ff031211912735f61bd0dc97c6f2b">textord_restore_underlines</a></div><div class="ttdeci">EXTERN bool textord_restore_underlines</div><div class="ttdef"><b>Definition:</b> <a href="a01472_source.html#l00030">underlin.cpp:30</a></div></div> <div class="ttc" id="a01373_html_ae71e721bb9641f221b30021a5addff82"><div class="ttname"><a href="a01373.html#ae71e721bb9641f221b30021a5addff82">vigorous_noise_removal</a></div><div class="ttdeci">void vigorous_noise_removal(TO_BLOCK *block)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l00473">makerow.cpp:473</a></div></div> <div class="ttc" id="a04657_html_adb63829f17ab14cfea6215b64ecf589e"><div class="ttname"><a href="a04657.html#adb63829f17ab14cfea6215b64ecf589e">tesseract::BaselineRow::SetupOldLineParameters</a></div><div class="ttdeci">void SetupOldLineParameters(TO_ROW *row) const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00077">baselinedetect.cpp:77</a></div></div> <div class="ttc" id="a04657_html_a9f18eec108377775507d2715186593cd"><div class="ttname"><a href="a04657.html#a9f18eec108377775507d2715186593cd">tesseract::BaselineRow::BaselineRow</a></div><div class="ttdeci">BaselineRow(double line_size, TO_ROW *to_row)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00065">baselinedetect.cpp:65</a></div></div> <div class="ttc" id="a02713_html_ac5ecdfbd33963eac601ccb67ac63dd2a"><div class="ttname"><a href="a02713.html#ac5ecdfbd33963eac601ccb67ac63dd2a">TBOX::top</a></div><div class="ttdeci">inT16 top() const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00054">rect.h:54</a></div></div> <div class="ttc" id="a04661_html_a858165c88e4c695fa2136bac7ed97b7f"><div class="ttname"><a href="a04661.html#a858165c88e4c695fa2136bac7ed97b7f">tesseract::BaselineBlock::DrawPixSpline</a></div><div class="ttdeci">void DrawPixSpline(Pix *pix_in)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00597">baselinedetect.cpp:597</a></div></div> <div class="ttc" id="a02485_html_a10818e7d801044a4d569466fa1d5f841"><div class="ttname"><a href="a02485.html#a10818e7d801044a4d569466fa1d5f841">TO_ROW::set_line</a></div><div class="ttdeci">void set_line(float new_m, float new_c, float new_error)</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00599">blobbox.h:599</a></div></div> <div class="ttc" id="a04665_html_a62154b468dd5af9b00a158542be42b6c"><div class="ttname"><a href="a04665.html#a62154b468dd5af9b00a158542be42b6c">tesseract::BaselineDetect::ComputeBaselineSplinesAndXheights</a></div><div class="ttdeci">void ComputeBaselineSplinesAndXheights(const ICOORD &page_tr, bool enable_splines, bool remove_noise, bool show_final_rows, Textord *textord)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00845">baselinedetect.cpp:845</a></div></div> <div class="ttc" id="a01253_html_aa61dc7df62ef6cd14f8f4a9e6b3003c9"><div class="ttname"><a href="a01253.html#aa61dc7df62ef6cd14f8f4a9e6b3003c9">kMinFittingLinespacings</a></div><div class="ttdeci">const double kMinFittingLinespacings</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00059">baselinedetect.cpp:59</a></div></div> <div class="ttc" id="a04661_html_a1445079bbeaaf0e81ab124288cc6ecf3"><div class="ttname"><a href="a04661.html#a1445079bbeaaf0e81ab124288cc6ecf3">tesseract::BaselineBlock::skew_angle</a></div><div class="ttdeci">double skew_angle() const</div><div class="ttdef"><b>Definition:</b> <a href="a01256_source.html#l00136">baselinedetect.h:136</a></div></div> <div class="ttc" id="a04665_html_a65bfc0db936ca70518593788669d256a"><div class="ttname"><a href="a04665.html#a65bfc0db936ca70518593788669d256a">tesseract::BaselineDetect::SetDebugImage</a></div><div class="ttdeci">void SetDebugImage(Pix *pixIn, const STRING &output_path)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00871">baselinedetect.cpp:871</a></div></div> <div class="ttc" id="a04661_html_a4866856efe373c4b48769899e38846b6"><div class="ttname"><a href="a04661.html#a4866856efe373c4b48769899e38846b6">tesseract::BaselineBlock::BaselineBlock</a></div><div class="ttdeci">BaselineBlock(int debug_level, bool non_text, TO_BLOCK *block)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00403">baselinedetect.cpp:403</a></div></div> <div class="ttc" id="a02617_html_aa41ae9661d53570dd6365d3ac8ac4c15"><div class="ttname"><a href="a02617.html#aa41ae9661d53570dd6365d3ac8ac4c15">BLOCK::classify_rotation</a></div><div class="ttdeci">FCOORD classify_rotation() const</div><div class="ttdef"><b>Definition:</b> <a href="a00314_source.html#l00144">ocrblock.h:144</a></div></div> <div class="ttc" id="a04657_html_a9089618e6511471f74427da4d9a2eb22"><div class="ttname"><a href="a04657.html#a9089618e6511471f74427da4d9a2eb22">tesseract::BaselineRow::SpaceBetween</a></div><div class="ttdeci">double SpaceBetween(const BaselineRow &other) const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00108">baselinedetect.cpp:108</a></div></div> <div class="ttc" id="a00608_html"><div class="ttname"><a href="a00608.html">tprintf.h</a></div></div> <div class="ttc" id="a01253_html_a764108909ac86000da00e33ae249ff17"><div class="ttname"><a href="a01253.html#a764108909ac86000da00e33ae249ff17">kMaxDisplacementsModes</a></div><div class="ttdeci">const int kMaxDisplacementsModes</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00043">baselinedetect.cpp:43</a></div></div> <div class="ttc" id="a02681_html_aecd85311c159bcd52b485a97a8dcc901"><div class="ttname"><a href="a02681.html#aecd85311c159bcd52b485a97a8dcc901">FCOORD::x</a></div><div class="ttdeci">float x() const</div><div class="ttdef"><b>Definition:</b> <a href="a00356_source.html#l00209">points.h:209</a></div></div> <div class="ttc" id="a02297_html_a5c4218ef833d0fe5db9b9749abd81ea5"><div class="ttname"><a href="a02297.html#a5c4218ef833d0fe5db9b9749abd81ea5">GenericVector::choose_nth_item</a></div><div class="ttdeci">int choose_nth_item(int target_index)</div><div class="ttdef"><b>Definition:</b> <a href="a00509_source.html#l00301">genericvector.h:301</a></div></div> <div class="ttc" id="a04661_html_a1e27f4aaf66c7e7aae4062c590fd8f3f"><div class="ttname"><a href="a04661.html#a1e27f4aaf66c7e7aae4062c590fd8f3f">tesseract::BaselineBlock::FitBaselinesAndFindSkew</a></div><div class="ttdeci">bool FitBaselinesAndFindSkew(bool use_box_bottoms)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00429">baselinedetect.cpp:429</a></div></div> <div class="ttc" id="a01253_html_a31cf284314686a893cae2fc26c503f0c"><div class="ttname"><a href="a01253.html#a31cf284314686a893cae2fc26c503f0c">kMaxBaselineError</a></div><div class="ttdeci">const double kMaxBaselineError</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00053">baselinedetect.cpp:53</a></div></div> <div class="ttc" id="a02713_html"><div class="ttname"><a href="a02713.html">TBOX</a></div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00030">rect.h:30</a></div></div> <div class="ttc" id="a02713_html_a54de49d8654e35d5221c7cdc20e2662f"><div class="ttname"><a href="a02713.html#a54de49d8654e35d5221c7cdc20e2662f">TBOX::right</a></div><div class="ttdeci">inT16 right() const</div><div class="ttdef"><b>Definition:</b> <a href="a00401_source.html#l00075">rect.h:75</a></div></div> <div class="ttc" id="a04657_html"><div class="ttname"><a href="a04657.html">tesseract::BaselineRow</a></div><div class="ttdef"><b>Definition:</b> <a href="a01256_source.html#l00040">baselinedetect.h:40</a></div></div> <div class="ttc" id="a01373_html_a8a932e3bd44fc2fc6fbdc291cdc9b942"><div class="ttname"><a href="a01373.html#a8a932e3bd44fc2fc6fbdc291cdc9b942">pre_associate_blobs</a></div><div class="ttdeci">void pre_associate_blobs(ICOORD page_tr, TO_BLOCK *block, FCOORD rotation, BOOL8 testing_on)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l01862">makerow.cpp:1862</a></div></div> <div class="ttc" id="a04657_html_a1b1af2359af16a1a44ec5dcf74114142"><div class="ttname"><a href="a04657.html#a1b1af2359af16a1a44ec5dcf74114142">tesseract::BaselineRow::Print</a></div><div class="ttdeci">void Print() const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00087">baselinedetect.cpp:87</a></div></div> <div class="ttc" id="a01472_html_a2118358b0e0f62667f62a0aaf2fb2ae8"><div class="ttname"><a href="a01472.html#a2118358b0e0f62667f62a0aaf2fb2ae8">restore_underlined_blobs</a></div><div class="ttdeci">void restore_underlined_blobs(TO_BLOCK *block)</div><div class="ttdef"><b>Definition:</b> <a href="a01472_source.html#l00038">underlin.cpp:38</a></div></div> <div class="ttc" id="a04841_html_aa5342d14436274e648b545a522705eab"><div class="ttname"><a href="a04841.html#aa5342d14436274e648b545a522705eab">tesseract::Textord::compute_row_xheight</a></div><div class="ttdeci">void compute_row_xheight(TO_ROW *row, const FCOORD &rotation, float gradient, int block_line_size)</div><div class="ttdef"><b>Definition:</b> <a href="a01373_source.html#l01383">makerow.cpp:1383</a></div></div> <div class="ttc" id="a02589_html_ae34cc080c9c8ee487b4a02f97b94d9f5"><div class="ttname"><a href="a02589.html#ae34cc080c9c8ee487b4a02f97b94d9f5">LLSQ::mean_point</a></div><div class="ttdeci">FCOORD mean_point() const</div><div class="ttdef"><b>Definition:</b> <a href="a00287_source.html#l00167">linlsq.cpp:167</a></div></div> <div class="ttc" id="a00851_html"><div class="ttname"><a href="a00851.html">config_auto.h</a></div></div> <div class="ttc" id="a01253_html_adaf423fe42f3ca4b3343020dc41c376b"><div class="ttname"><a href="a01253.html#adaf423fe42f3ca4b3343020dc41c376b">kNumSkipPoints</a></div><div class="ttdeci">const int kNumSkipPoints</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00045">baselinedetect.cpp:45</a></div></div> <div class="ttc" id="a02589_html_a4146a9ebd0a85858cec1df3a218ffada"><div class="ttname"><a href="a02589.html#a4146a9ebd0a85858cec1df3a218ffada">LLSQ::c</a></div><div class="ttdeci">double c(double m) const</div><div class="ttdef"><b>Definition:</b> <a href="a00287_source.html#l00117">linlsq.cpp:117</a></div></div> <div class="ttc" id="a01325_html_afb1c1fd2d6af3a9851ab98454356c3cf"><div class="ttname"><a href="a01325.html#afb1c1fd2d6af3a9851ab98454356c3cf">plot_parallel_row</a></div><div class="ttdeci">void plot_parallel_row(TO_ROW *row, float gradient, inT32 left, ScrollView::Color colour, FCOORD rotation)</div><div class="ttdef"><b>Definition:</b> <a href="a01325_source.html#l00125">drawtord.cpp:125</a></div></div> <div class="ttc" id="a02297_html_a172c4aa23ba397e24319ae095281cbcc"><div class="ttname"><a href="a02297.html#a172c4aa23ba397e24319ae095281cbcc">GenericVector::empty</a></div><div class="ttdeci">bool empty() const</div><div class="ttdef"><b>Definition:</b> <a href="a00509_source.html#l00084">genericvector.h:84</a></div></div> <div class="ttc" id="a02681_html_aab5b14bc328998adc252ffe7476d7f22"><div class="ttname"><a href="a02681.html#aab5b14bc328998adc252ffe7476d7f22">FCOORD::angle</a></div><div class="ttdeci">float angle() const</div><div class="ttdoc">find angle </div><div class="ttdef"><b>Definition:</b> <a href="a00356_source.html#l00249">points.h:249</a></div></div> <div class="ttc" id="a02733_html"><div class="ttname"><a href="a02733.html">STATS</a></div><div class="ttdef"><b>Definition:</b> <a href="a00425_source.html#l00033">statistc.h:33</a></div></div> <div class="ttc" id="a02489_html_abda136ff240577928343ca37453aca7a"><div class="ttname"><a href="a02489.html#abda136ff240577928343ca37453aca7a">TO_BLOCK::max_blob_size</a></div><div class="ttdeci">float max_blob_size</div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00782">blobbox.h:782</a></div></div> <div class="ttc" id="a04661_html_a0619e15482a4ed11dce15bc5d8cbe0be"><div class="ttname"><a href="a04661.html#a0619e15482a4ed11dce15bc5d8cbe0be">tesseract::BaselineBlock::SetupBlockParameters</a></div><div class="ttdeci">void SetupBlockParameters() const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00500">baselinedetect.cpp:500</a></div></div> <div class="ttc" id="a04657_html_a6907a2bb647448ef6ed5b6789b7e1440"><div class="ttname"><a href="a04657.html#a6907a2bb647448ef6ed5b6789b7e1440">tesseract::BaselineRow::AdjustBaselineToParallel</a></div><div class="ttdeci">void AdjustBaselineToParallel(int debug, const FCOORD &direction)</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00214">baselinedetect.cpp:214</a></div></div> <div class="ttc" id="a04929_html_a100504544a5423a94222149ee9ed0fe8aebeaaeee353c6f04b4498b1fef94bbb3"><div class="ttname"><a href="a04929.html#a100504544a5423a94222149ee9ed0fe8aebeaaeee353c6f04b4498b1fef94bbb3">ScrollView::MAGENTA</a></div><div class="ttdef"><b>Definition:</b> <a href="a01610_source.html#l00114">scrollview.h:114</a></div></div> <div class="ttc" id="a02661_html_a3f06f8e34fc5962f342daff9623463e9"><div class="ttname"><a href="a02661.html#a3f06f8e34fc5962f342daff9623463e9">PDBLK::bounding_box</a></div><div class="ttdeci">void bounding_box(ICOORD &bottom_left, ICOORD &top_right) const</div><div class="ttdoc">get box </div><div class="ttdef"><b>Definition:</b> <a href="a00350_source.html#l00059">pdblock.h:59</a></div></div> <div class="ttc" id="a02489_html"><div class="ttname"><a href="a02489.html">TO_BLOCK</a></div><div class="ttdef"><b>Definition:</b> <a href="a00209_source.html#l00688">blobbox.h:688</a></div></div> <div class="ttc" id="a02589_html"><div class="ttname"><a href="a02589.html">LLSQ</a></div><div class="ttdef"><b>Definition:</b> <a href="a00290_source.html#l00026">linlsq.h:26</a></div></div> <div class="ttc" id="a04657_html_a4634cd0cd05e8292d80c1d396d598b17"><div class="ttname"><a href="a04657.html#a4634cd0cd05e8292d80c1d396d598b17">tesseract::BaselineRow::BaselineAngle</a></div><div class="ttdeci">double BaselineAngle() const</div><div class="ttdef"><b>Definition:</b> <a href="a01253_source.html#l00098">baselinedetect.cpp:98</a></div></div> </div><!-- fragment --></div><!-- contents --> </div><!-- doc-content --> <!-- start footer part --> <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> <ul> <li class="navelem"><a class="el" href="dir_9755ee342a92885af0731133719bff63.html">textord</a></li><li class="navelem"><a class="el" href="a01253.html">baselinedetect.cpp</a></li> <li class="footer">Generated on Mon Oct 29 2018 11:27:50 for tesseract by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.14 </li> </ul> </div> </body> </html>