$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
repair_lines.cc
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/core/image/image2d.hh>
28 #include <mln/core/alias/box2d.hh>
29 #include <mln/make/box2d.hh>
30 #include <mln/util/array.hh>
31 #include <mln/util/couple.hh>
32 #include <mln/io/pbm/load.hh>
33 #include <mln/value/label_16.hh>
34 #include <mln/win/vline2d.hh>
35 #include <mln/win/hline2d.hh>
36 
37 #include <scribo/table/repair_vertical_lines.hh>
38 #include <scribo/table/repair_horizontal_lines.hh>
39 #include <scribo/debug/save_table_image.hh>
40 
41 #include "tests/data.hh"
42 
43 int main(int argc, char *argv[])
44 {
45  using namespace mln;
46 
47  std::string img;
48  if (argc < 2)
49  img = SCRIBO_IMG_DIR "/table_to_be_repaired.pbm";
50  else
51  img = argv[1];
52 
53  image2d<bool> input;
54  io::pbm::load(input, img.c_str());
55 
56  typedef util::couple<util::array<box2d>,
57  util::array<box2d> > tblboxes_t;
58 
59  tblboxes_t lineboxes;
60  lineboxes.first().append(make::box2d(0,0, 1,1)); // Dummy value for component 0.
61  lineboxes.first().append(make::box2d(0,28, 27, 32));
62  lineboxes.first().append(make::box2d(31,28, 59,32));
63  lineboxes.second().append(make::box2d(0,0, 1,1)); // Dummy value for component 0.
64  lineboxes.second().append(make::box2d(27,0, 31, 26));
65  lineboxes.second().append(make::box2d(27,34, 31,59));
66 
67  scribo::table::repair_vertical_lines(input, lineboxes, 31);
68  scribo::table::repair_horizontal_lines(input, lineboxes, 31);
69 
70  mln_assertion(lineboxes.first().nelements() == 2);
71  mln_assertion(lineboxes.second().nelements() == 2);
72  mln_assertion(lineboxes.first()[1] == make::box2d(0,28, 59,32));
73  mln_assertion(lineboxes.second()[1] == make::box2d(27,0, 31,59));
74 }