$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
look_like_text_lines.hh
1 // Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef SCRIBO_TEXT_LOOK_LIKE_TEXT_LINES_HH
27 # define SCRIBO_TEXT_LOOK_LIKE_TEXT_LINES_HH
28 
32 
33 # include <scribo/core/line_info.hh>
34 
35 namespace scribo
36 {
37 
38  namespace text
39  {
40 
41  using namespace mln;
42 
44  //
45  template <typename L>
46  line_set<L>
48 
51  //
52  template <typename L>
53  void
55 
56 
57 # ifndef MLN_INCLUDE_ONLY
58 
59 
60  namespace internal
61  {
62 
63  template <typename L>
64  inline
65  bool looks_like_a_text_line(const scribo::line_info<L>& l)
66  {
67  // Special case for two-letter words
68  if (l.card() == 2)
69  {
70  const float ratio = (float) l.bbox().width() / l.bbox().height();
71 
72  if (// Minimal width / height ratio
73  ratio > 0.4f && ratio < 2.0f
74  // Minimal height
75  && l.bbox().height() >= 15
76  // Characters must have approximately the same width
77  && l.chars_same_width())
78  {
79  return true;
80  }
81  }
82 
83  return
84  l.card() >= 3 // at least 3 components
85  && l.bbox().height() > 10 // and minimal height
86  && l.bbox().width() > l.bbox().height(); // and more horizontal-like than vertical
87  // FIXME: Later on, add a criterion based on the number
88  // of alignments (on top and bot).
89  }
90 
91  } // end of namespace scribo::text::namespace
92 
93 
94 
95  // Facades
96 
97  template <typename L>
98  inline
99  void
101  {
102  mln_trace("scribo::text::look_like_text_lines_inplace");
103 
104  for_all_lines(l, line)
105  if (internal::looks_like_a_text_line(line(l)))
106  line(l).update_type(line::Text);
107 
108  }
109 
110  template <typename L>
111  inline
112  line_set<L>
113  look_like_text_lines(const scribo::line_set<L>& l)
114  {
115  mln_trace("scribo::text::look_like_text_lines");
116  line_set<L> output = l.duplicate();
117 
119 
120  return output;
121  }
122 
123 
124 # endif // ! MLN_INCLUDE_ONLY
125 
126  } // end of namespace scribo::text
127 
128 } // end of namespace scribo
129 
130 #endif // ! SCRIBO_TEXT_LOOK_LIKE_TEXT_LINES_HH