32 #include <mln/core/image/image2d.hh>
34 #include <mln/io/magick/load.hh>
36 #include <scribo/toolchain/content_in_hdoc.hh>
37 #include <scribo/toolchain/text_in_doc_preprocess.hh>
39 #include <scribo/core/document.hh>
41 #include <scribo/debug/usage.hh>
42 #include <scribo/debug/logger.hh>
44 #include <scribo/preprocessing/crop_without_localization.hh>
45 #include <scribo/preprocessing/crop.hh>
47 #include <scribo/io/xml/save.hh>
48 #include <scribo/io/img/save.hh>
51 #include <mln/core/alias/neighb2d.hh>
52 #include <mln/labeling/compute.hh>
53 #include <mln/labeling/foreground.hh>
54 #include <mln/util/timer.hh>
58 const char *args_desc[][2] =
60 {
"input.*",
"An image." },
61 {
"out.xml",
"Result of the document analysis." },
62 {
"denoise_enabled",
"1 enables denoising, 0 disables it. (enabled by default)" },
63 {
"pmin_row",
"Row index of the top left corner of the Region of interest." },
64 {
"pmin_col",
"Col index of the top left corner of the Region of interest." },
65 {
"pmax_row",
"Row index of the bottom right corner of the Region of interest." },
66 {
"pmax_col",
"Col index of the bottom right corner of the Region of interest." },
67 {
"language",
"Language to be used for the text recognition. [eng|fra] (Default: eng)."
68 "An empty language will disable OCR." },
69 {
"find_lines",
"Find vertical lines. (Default 1)" },
70 {
"find_whitespaces",
"Find whitespaces separators. (Default 1)" },
71 {
"K",
"Sauvola's binarization threshold parameter. (Default: 0.34)" },
72 {
"debug_dir",
"Output directory for debug image" },
78 int main(
int argc,
char* argv[])
80 using namespace scribo;
83 if (argc < 3 || argc > 14)
85 "Find text lines and elements in a document",
86 "input.* out.xml <denoise_enabled> [<pmin_row> <pmin_col> <pmax_row> <pmax_col>] [language] [find_lines] [find_whitespaces] [K] [debug_dir]",
90 if (argc == 9 || argc == 13)
94 scribo::make::internal::debug_filename_prefix = argv[argc - 1];
110 if (argc == 8 || argc >= 12)
115 K = atof(argv[argc - 2]);
116 std::cout <<
"Using K = " << K << std::endl;
130 const box2d& b = input.domain();
131 for_all_ncomponents(e, nlabels)
132 if (bbox(e).pmin().row() == b.pmin().row()
133 || bbox(e).pmax().row() == b.pmax().row()
134 || bbox(e).pmin().col() == b.pmin().col()
135 || bbox(e).pmax().col() == b.pmax().col())
136 data::
fill(((input_preproc | bbox(e)).rw() | (pw::
value(lbl) == pw::cst(e))).rw(), false);
141 point2d crop_shift = literal::origin;
145 minr = atoi(argv[4]),
146 minc = atoi(argv[5]),
147 maxr = atoi(argv[6]),
148 maxc = atoi(argv[7]);
150 std::cout <<
"> Image cropped from (" << minr <<
"," << minc <<
")"
151 <<
" to (" << maxr <<
"," << maxc <<
")" << std::endl;
155 crop_shift =
point2d(minr, minc);
158 "input_preproc_cropped.pbm");
161 bool denoise = (argc > 3 && atoi(argv[3]) != 0);
163 std::string language =
"eng";
164 if (argc >= 5 && argc < 13)
169 bool find_line_seps =
true;
170 if (argc >= 6 && argc < 13)
171 find_line_seps = (atoi(argv[5]) != 0);
173 find_line_seps = (atoi(argv[9]) != 0);
175 bool find_whitespace_seps =
true;
176 if (argc >= 7 && argc < 13)
177 find_whitespace_seps = (atoi(argv[6]) != 0);
179 find_whitespace_seps = (atoi(argv[10]) != 0);
181 std::cout <<
"Running with the following options :"
182 <<
" ocr_language = " << language
183 <<
" | find_lines_seps = " << find_line_seps
184 <<
" | find_whitespace_seps = " << find_whitespace_seps
191 std::cout <<
"Analysing document..." << std::endl;
194 find_line_seps, find_whitespace_seps,
195 !language.empty(), language);
197 doc.set_filename(basename(argv[1]));
200 std::cout <<
"Saving results..." << std::endl;
203 std::cout <<
"End of process - " << t << std::endl;