$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
text_in_picture.cc
1 // Copyright (C) 2009, 2010, 2011, 2013 EPITA Research and Development
2 // Laboratory (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 <libgen.h>
28 #include <iostream>
29 
30 #include <mln/io/magick/all.hh>
31 
32 #include <scribo/toolchain/text_in_picture.hh>
33 #include <scribo/debug/option_parser.hh>
34 #include <scribo/debug/logger.hh>
35 
36 
37 static const scribo::debug::arg_data arg_desc[] =
38 {
39  { "input.*", "An image." },
40  { "output.ppm", "A color image where the text is highlighted." },
41  {0, 0}
42 };
43 
44 // --enable/disable-<name>
45 static const scribo::debug::toggle_data toggle_desc[] =
46 {
47  // name, description, default value
48  { "fg-extraction", "Detect and slit foreground/background components. (default: disabled)", false },
49  { "ms-bin", "Use a multi-scale binarization. (default: enabled)", true },
50  { "alternate-results", "Save debug images with all the text bboxes. (default: disabled)", false },
51  { "debug", "Enable debug outputs (default: disabled).", false },
52  {0, 0, false}
53 };
54 
55 
56 // --<name> <args>
57 static const scribo::debug::opt_data opt_desc[] =
58 {
59  // name, description, arguments, check args function, number of args, default arg
60  { "debug-prefix", "Enable debug image outputs. Prefix image name with that "
61  "given prefix.", "<prefix>", 0, 1, 0 },
62  { "max-dim-size", "Set the maximum size of the largest image dimension.", "<size>", 0, 1, "1024" },
63  { "lambda", "Set the maximum area of the background objects. It is only useful if fg-extraction is enabled.", "<size>",
64  0, 1, "0" },
65  { "verbose", "Enable verbose mode", 0, 0, 0, 0 },
66  {0, 0, 0, 0, 0, 0}
67 };
68 
69 
70 
71 int main(int argc, char* argv[])
72 {
73  using namespace scribo;
74  using namespace mln;
75 
76  scribo::debug::option_parser options(arg_desc, toggle_desc, opt_desc);
77 
78  if (!options.parse(argc, argv))
79  return 1;
80 
81  if (options.is_set("debug-prefix"))
82  scribo::debug::logger().set_filename_prefix(options.opt_value("debug-prefix").c_str());
83 
84  if (options.is_enabled("debug"))
85  scribo::debug::logger().set_level(scribo::debug::All);
86 
87  mln_trace("main");
88 
89  image2d<value::rgb8> input_rgb;
90  io::magick::load(input_rgb, options.arg("input.*"));
91 
92  bool verbose = options.is_set("verbose");
93  unsigned max_dim_size = atoi(options.opt_value("max-dim-size").c_str());
94  bool fg_extraction = options.is_enabled("fg-extraction");
95  bool multi_scale_bin = options.is_enabled("ms-bin");
96  unsigned lambda = atoi(options.opt_value("lambda").c_str());
97 
98  if (options.is_enabled("alternate-results"))
99  scribo::debug::logger().set_level(scribo::debug::Results);
100 
101  if (verbose)
102  std::cout << "Using max_dim_size = " << max_dim_size
103  << " - fg_extraction = " << fg_extraction
104  << " - multi_scale_bin = " << multi_scale_bin
105  << " - lambda = " << lambda << std::endl;
106 
108  comps = toolchain::text_in_picture(input_rgb,
109  fg_extraction, multi_scale_bin,
110  max_dim_size, lambda, verbose);
111 
112 
114  comps.labeled_image(),
115  comps.nelements()),
116  options.arg("output.ppm"));
117 }