
* toolchain/internal/toolchain_functor.hh: Here. * toolchain/internal/content_in_doc_functor.hh, * toolchain/internal/content_in_hdoc_functor.hh, * toolchain/internal/text_in_doc_functor.hh, * toolchain/internal/text_in_doc_preprocess_functor.hh: Make use of them. --- scribo/ChangeLog | 12 +++++ .../toolchain/internal/content_in_doc_functor.hh | 4 ++ .../toolchain/internal/content_in_hdoc_functor.hh | 53 ++++++++++++++++++++ .../toolchain/internal/text_in_doc_functor.hh | 4 ++ .../internal/text_in_doc_preprocess_functor.hh | 53 ++++++++++++++++++- .../scribo/toolchain/internal/toolchain_functor.hh | 28 ++++++++++- 6 files changed, 149 insertions(+), 5 deletions(-) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 13b8e95..87364fc 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,17 @@ 2011-05-26 Guillaume Lazzara <z@lrde.epita.fr> + Add new hooks in toolchain functors. + + * toolchain/internal/toolchain_functor.hh: Here. + + * toolchain/internal/content_in_doc_functor.hh, + * toolchain/internal/content_in_hdoc_functor.hh, + * toolchain/internal/text_in_doc_functor.hh, + * toolchain/internal/text_in_doc_preprocess_functor.hh: Make use + of them. + +2011-05-26 Guillaume Lazzara <z@lrde.epita.fr> + * scribo/util/component_precise_outline.hh: New. Precise component outline extraction. diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh index d60f3cc..4308056 100644 --- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh +++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh @@ -162,6 +162,8 @@ namespace scribo mln_precondition(exact(original_image).is_valid()); mln_precondition(exact(processed_image).is_valid()); + on_start(); + doc.set_image(exact(original_image)); doc.set_binary_image(exact(processed_image)); @@ -568,6 +570,8 @@ namespace scribo on_progress(); } + on_end(); + return doc; } diff --git a/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh b/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh index e7d14ff..ef33b31 100644 --- a/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh +++ b/scribo/scribo/toolchain/internal/content_in_hdoc_functor.hh @@ -132,6 +132,20 @@ namespace scribo // Results //========= document<L> doc; + + + +# ifndef SCRIBO_NDEBUG + //============= + // DEBUG TOOLS + //============= + virtual void on_start(); + virtual void on_end(); + virtual void on_progress(); + + mln::util::timer t; + mln::util::timer gt; +# endif // ! SCRIBO_NDEBUG }; @@ -165,6 +179,8 @@ namespace scribo mln_precondition(exact(original_image).is_valid()); mln_precondition(exact(processed_image).is_valid()); + on_start(); + doc.set_image(exact(original_image)); doc.set_binary_image(exact(processed_image)); @@ -353,6 +369,8 @@ namespace scribo line_set<L> lines = scribo::make::line_set(groups); + on_progress(); + // Extract whitespace to improve text merging results afterwards. mln_ch_value(L,bool) whitespaces; @@ -594,6 +612,8 @@ namespace scribo on_progress(); } + on_end(); + return doc; } @@ -615,6 +635,39 @@ namespace scribo // Nothing } +# ifndef SCRIBO_NDEBUG + + template <typename I> + void + content_in_hdoc_functor<I>::on_start() + { + gt.start(); + t.start(); + } + + template <typename I> + void + content_in_hdoc_functor<I>::on_end() + { + gt.stop(); + if (verbose) + std::cout << "Total time: " << gt << std::endl; + } + + template <typename I> + void + content_in_hdoc_functor<I>::on_progress() + { + t.stop(); + if (verbose) + std::cout << t << std::endl; + t.restart(); + } + + +# endif // ! SCRIBO_NDEBUG + + # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/scribo/toolchain/internal/text_in_doc_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_functor.hh index 62074f0..f5b94cf 100644 --- a/scribo/scribo/toolchain/internal/text_in_doc_functor.hh +++ b/scribo/scribo/toolchain/internal/text_in_doc_functor.hh @@ -130,6 +130,8 @@ namespace scribo line_set<typename text_in_doc_functor<I>::L> text_in_doc_functor<I>::operator()(const Image<I>& input) { + on_start(); + // Remove separators mln_ch_value(I,bool) separators, @@ -387,6 +389,8 @@ namespace scribo on_progress(); + on_end(); + output = lines; return output; } diff --git a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh index 6c0dd5a..484e28e 100644 --- a/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh +++ b/scribo/scribo/toolchain/internal/text_in_doc_preprocess_functor.hh @@ -132,6 +132,18 @@ namespace scribo mln_concrete(I) bg; image2d<bool> output; +# ifndef SCRIBO_NDEBUG + //============= + // DEBUG TOOLS + //============= + virtual void on_start(); + virtual void on_end(); + virtual void on_progress(); + + mln::util::timer t; + mln::util::timer gt; +# endif // ! SCRIBO_NDEBUG + private: // Methods unsigned find_best_scale(const Image<I>& ima_); @@ -169,6 +181,8 @@ namespace scribo mln_concrete(I) input_rgb = input; + on_start(); + // Subsample //---------- if (enable_subsample) @@ -227,8 +241,6 @@ namespace scribo // Binarization (always happens) //------------------------------ - on_new_progress_label("Binarization"); - if (binarization_algo == Sauvola) { on_new_progress_label("Binarization (Sauvola)"); @@ -242,7 +254,7 @@ namespace scribo } else // binarization_algo == Convert { - on_new_progress_label("Binary conversion"); + on_new_progress_label("Binarization (Binary conversion)"); output = mln::data::convert(bool(), intensity_ima); } @@ -260,6 +272,8 @@ namespace scribo on_progress(); } + on_end(); + return output; } @@ -293,6 +307,39 @@ namespace scribo } +# ifndef SCRIBO_NDEBUG + + template <typename I> + void + text_in_doc_preprocess_functor<I>::on_start() + { + gt.start(); + t.start(); + } + + template <typename I> + void + text_in_doc_preprocess_functor<I>::on_end() + { + gt.stop(); + if (verbose) + std::cout << "Total time: " << gt << std::endl; + } + + template <typename I> + void + text_in_doc_preprocess_functor<I>::on_progress() + { + t.stop(); + if (verbose) + std::cout << t << std::endl; + t.restart(); + } + + +# endif // ! SCRIBO_NDEBUG + + # endif // ! MLN_INCLUDE_ONLY diff --git a/scribo/scribo/toolchain/internal/toolchain_functor.hh b/scribo/scribo/toolchain/internal/toolchain_functor.hh index a29dafa..5621c7c 100644 --- a/scribo/scribo/toolchain/internal/toolchain_functor.hh +++ b/scribo/scribo/toolchain/internal/toolchain_functor.hh @@ -1,4 +1,5 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory +// (LRDE) // // This file is part of Olena. // @@ -26,6 +27,7 @@ #ifndef SCRIBO_TOOLCHAIN_INTERNAL_TOOLCHAIN_FUNCTOR_HH # define SCRIBO_TOOLCHAIN_INTERNAL_TOOLCHAIN_FUNCTOR_HH +# include <unistd.h> # include <iostream> namespace scribo @@ -50,6 +52,8 @@ namespace scribo // Triggers //========== + virtual void on_start(); + virtual void on_end(); virtual void on_progress(); virtual void on_new_progress_label(const char *label); @@ -71,17 +75,37 @@ namespace scribo // Triggers //========== + + inline + void Toolchain_Functor::on_start() + { + // Nothing + } + + inline + void Toolchain_Functor::on_end() + { + // Nothing + } + inline void Toolchain_Functor::on_progress() { // Nothing + if (verbose) + std::cout << std::endl; } inline void Toolchain_Functor::on_new_progress_label(const char *label) { if (verbose) - std::cout << label << std::endl; + { + if (isatty(1)) + std::cout << "> \e[0;32m " << label << " \e[m - "; + else + std::cout << "> " << label << " - "; + } } # endif // ! MLN_INCLUDE_ONLY -- 1.5.6.5
participants (1)
-
Guillaume Lazzara