last-svn-commit-56-g2773488 Improve debug routines in Scribo.
* debug/bboxes_enlarged_image.hh, * debug/looks_like_a_text_line_image.hh, * debug/mean_and_base_lines_image.hh: New routines. * debug/alignment_decision_image.hh, * debug/decision_image.hh, * debug/save_bboxes_image.hh: Update code according to last changes in core classes. * debug/usage.hh: Make the description optional. --- scribo/ChangeLog | 15 +++ scribo/debug/alignment_decision_image.hh | 37 +++---- scribo/debug/bboxes_enlarged_image.hh | 136 ++++++++++++++++++++++++ scribo/debug/decision_image.hh | 12 +- scribo/debug/looks_like_a_text_line_image.hh | 130 +++++++++++++++++++++++ scribo/debug/mean_and_base_lines_image.hh | 147 ++++++++++++++++++++++++++ scribo/debug/save_bboxes_image.hh | 60 ++++++++++- scribo/debug/usage.hh | 9 +- 8 files changed, 513 insertions(+), 33 deletions(-) create mode 100644 scribo/debug/bboxes_enlarged_image.hh create mode 100644 scribo/debug/looks_like_a_text_line_image.hh create mode 100644 scribo/debug/mean_and_base_lines_image.hh diff --git a/scribo/ChangeLog b/scribo/ChangeLog index a24406b..54d5f0d 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,20 @@ 2010-03-11 Guillaume Lazzara <z@lrde.epita.fr> + Improve debug routines in Scribo. + + * debug/bboxes_enlarged_image.hh, + * debug/looks_like_a_text_line_image.hh, + * debug/mean_and_base_lines_image.hh: New routines. + + * debug/alignment_decision_image.hh, + * debug/decision_image.hh, + * debug/save_bboxes_image.hh: Update code according to last + changes in core classes. + + * debug/usage.hh: Make the description optional. + +2010-03-11 Guillaume Lazzara <z@lrde.epita.fr> + Improve core classes in Scribo. * core/component_info.hh, diff --git a/scribo/debug/alignment_decision_image.hh b/scribo/debug/alignment_decision_image.hh index e3b6163..841bd38 100644 --- a/scribo/debug/alignment_decision_image.hh +++ b/scribo/debug/alignment_decision_image.hh @@ -36,7 +36,9 @@ # include <mln/literal/colors.hh> # include <mln/util/array.hh> # include <mln/util/couple.hh> +# include <mln/norm/l1.hh> +# include <scribo/core/component_set.hh> # include <scribo/core/object_groups.hh> # include <scribo/draw/bounding_boxes.hh> @@ -79,28 +81,28 @@ namespace scribo template <typename L> mln::util::couple<mln_site(L),mln_site(L)> - find_anchors(const object_image(L)& objects, + find_anchors(const component_set<L>& components, unsigned i, unsigned link_i, const Alignment& alignment) { mln_site(L) - a1 = objects.bbox(i).center(), - a2 = objects.bbox(link_i).center(); + a1 = components(i).bbox().pcenter(), + a2 = components(link_i).bbox().pcenter(); switch (alignment) { case top: - a1.row() = objects.bbox(i).pmin().row(); - a2.row() = objects.bbox(link_i).pmin().row(); + a1.row() = components(i).bbox().pmin().row(); + a2.row() = components(link_i).bbox().pmin().row(); break; case center: break; case bottom: - a1.row() = objects.bbox(i).pmax().row(); - a2.row() = objects.bbox(link_i).pmax().row(); + a1.row() = components(i).bbox().pmax().row(); + a2.row() = components(link_i).bbox().pmax().row(); break; } @@ -120,35 +122,32 @@ namespace scribo trace::entering("scribo::debug::alignment_decision_image"); const I& input = exact(input_); - const object_image(L)& objects = links.object_image_(); + const component_set<L>& components = links.components(); mln_precondition(input.is_valid()); mln_precondition(links.is_valid()); mln_precondition(filtered_links.is_valid()); - mln_precondition(links.size() == filtered_links.size()); - mln_precondition(links.object_image_() != filtered_links.object_image_()); - /// Fixme: check that objects has been computed from input. + /// Fixme: check that components has been computed from input. image2d<value::rgb8> decision_image = data::convert(value::rgb8(), input); - for_all_components(i, objects.bboxes()) - mln::draw::box(decision_image, objects.bbox(i), literal::blue); + for_all_comps(i, components) + mln::draw::box(decision_image, components(i).bbox(), literal::blue); typedef mln_site(L) P; - for (unsigned i = 1; i < links.size(); ++i) + for_all_links(i, links) { - - if (links[i] != i) + if (links(i) != i) { value::rgb8 value = literal::green; - if (links[i] != filtered_links[i]) + if (links(i) != filtered_links(i)) value = literal::red; mln::util::couple<P,P> - anchors = internal::find_anchors(objects, i, links[i], alignment); - if (norm::l1_distance(anchors.first(), anchors.second()) < max_link_length) + anchors = internal::find_anchors(components, i, links(i), alignment); + if (mln::norm::l1_distance(anchors.first().to_vec(), anchors.second().to_vec()) < max_link_length) mln::draw::line(decision_image, anchors.first(), anchors.second(), diff --git a/scribo/debug/bboxes_enlarged_image.hh b/scribo/debug/bboxes_enlarged_image.hh new file mode 100644 index 0000000..edd6d7a --- /dev/null +++ b/scribo/debug/bboxes_enlarged_image.hh @@ -0,0 +1,136 @@ +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_BBOXES_ENLARGED_IMAGE_HH +# define SCRIBO_DEBUG_BBOXES_ENLARGED_IMAGE_HH + +/// \file +/// +/// \brief Compute an image of enlarged component bounding boxes. + + +# include <mln/core/concept/image.hh> +# include <mln/data/convert.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/colors.hh> +# include <mln/draw/box.hh> + +# include <scribo/core/line_set.hh> + +// Declares internal::looks_like_a_text_line. +# include <scribo/text/merging.hh> + + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + + /// \brief Compute an image of enlarged component bounding boxes. + /// + /// This check whether each line looks like a text line. If it is + /// a text line, its extended bounding box is drawn, otherwise, it + /// is normal bounding box. + /// + /// This rountine uses scribo::internal::looks_like_a_text_line to + /// check if a component looks like a text line. + /// + /// + /// \param[in] input An image convertible towards a color image. + /// \param[in] lines A line set. + /// \param[in] text_value The color used to draw bounding boxes + /// of components looking like a text line. + /// \param[in] non_text_value The color used to draw bounding + /// boxes of components NOT looking like + /// a text line. + /// + /// \return A color image. + // + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + bboxes_enlarged_image(const Image<I>& input, + const line_set<L>& lines, + const value::rgb8& text_value, + const value::rgb8& non_text_value); + + /// \overload + /// text_value is set to literal::green. + /// non_text_value is set to literal::red. + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + bboxes_enlarged_image(const Image<I>& input, + const line_set<L>& lines); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + bboxes_enlarged_image(const Image<I>& input, + const line_set<L>& lines, + const value::rgb8& text_value, + const value::rgb8& non_text_value) + { + trace::entering("scribo::debug::bboxes_enlarged_image"); + mln_precondition(exact(input).is_valid()); + + image2d<value::rgb8> output = data::convert(value::rgb8(), input); + + for_all_lines(l, lines) + if (! lines(l).hidden()) + { + if (text::internal::looks_like_a_text_line(lines(l))) + mln::draw::box(output, lines(l).ebbox(), text_value); + else + mln::draw::box(output, lines(l).bbox(), non_text_value); + } + + trace::exiting("scribo::debug::bboxes_enlarged_image"); + return output; + } + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + bboxes_enlarged_image(const Image<I>& input, + const line_set<L>& lines) + { + return bboxes_enlarged_image(input, lines, + literal::green, literal::red); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::debug + +} // end of namespace scribo + + +#endif // ! SCRIBO_DEBUG_BBOXES_ENLARGED_IMAGE_HH diff --git a/scribo/debug/decision_image.hh b/scribo/debug/decision_image.hh index 011dbfa..cc3f0f0 100644 --- a/scribo/debug/decision_image.hh +++ b/scribo/debug/decision_image.hh @@ -130,7 +130,7 @@ namespace scribo trace::entering("scribo::debug::decision_image"); const I& input = exact(input_); - const component_set<L>& components = links.component_set_(); + const component_set<L>& components = links.components(); mln_precondition(input.is_valid()); mln_precondition(links.is_valid()); @@ -142,20 +142,20 @@ namespace scribo image2d<value::rgb8> decision_image = data::convert(value::rgb8(), input); - for_all_components(i, components) + for_all_comps(i, components) mln::draw::box(decision_image, components(i).bbox(), literal::blue); - for (unsigned i = 1; i < links.size(); ++i) + for (unsigned i = 1; i < links.nelements(); ++i) { - if (links[i] != i) + if (links(i) != i) { value::rgb8 value = literal::green; - if (links[i] != filtered_links[i]) + if (links(i) != filtered_links(i)) value = literal::red; mln::draw::line(decision_image, components(i).bbox().pcenter(), - components(links[i]).bbox().pcenter(), + components(links(i)).bbox().pcenter(), value); } } diff --git a/scribo/debug/looks_like_a_text_line_image.hh b/scribo/debug/looks_like_a_text_line_image.hh new file mode 100644 index 0000000..a40c7d6 --- /dev/null +++ b/scribo/debug/looks_like_a_text_line_image.hh @@ -0,0 +1,130 @@ +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_LOOKS_LIKE_A_TEXT_LINE_IMAGE_HH +# define SCRIBO_DEBUG_LOOKS_LIKE_A_TEXT_LINE_IMAGE_HH + +/// \file +/// +/// Compute an image where components are drawn differently whether +/// they look like a line or not. + + +# include <mln/core/concept/image.hh> +# include <mln/data/convert.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/colors.hh> +# include <mln/draw/box.hh> + +# include <scribo/core/line_set.hh> + +// Declares internal::looks_like_a_text_line. +# include <scribo/text/merging.hh> + + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + + /// \brief Compute an image where components are drawn differently + /// whether they look like a line or not. + /// + /// \param[in] input An image convertible towards a color image. + /// \param[in] lines A line set. + /// \param[in] text_value The color used to draw bounding boxes + /// of components looking like a text line. + /// \param[in] non_text_value The color used to draw bounding + /// boxes of components NOT looking like + /// a text line. + /// + /// \return A color image. + // + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + looks_like_a_text_line_image(const Image<I>& input, + const line_set<L>& lines, + const value::rgb8& text_value, + const value::rgb8& non_text_value); + + /// \overload + /// text_value is set to literal::green. + /// non_text_value is set to literal::red. + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + looks_like_a_text_line_image(const Image<I>& input, + const line_set<L>& lines); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + looks_like_a_text_line_image(const Image<I>& input, + const line_set<L>& lines, + const value::rgb8& text_value, + const value::rgb8& non_text_value) + { + trace::entering("scribo::debug::looks_like_a_text_line_image"); + mln_precondition(exact(input).is_valid()); + + image2d<value::rgb8> output = data::convert(value::rgb8(), input); + + for_all_lines(l, lines) + if (! lines(l).hidden()) + { + if (text::internal::looks_like_a_text_line(lines(l))) + mln::draw::box(output, lines(l).bbox(), text_value); + else + mln::draw::box(output, lines(l).bbox(), non_text_value); + } + + trace::exiting("scribo::debug::looks_like_a_text_line_image"); + return output; + } + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + looks_like_a_text_line_image(const Image<I>& input, + const line_set<L>& lines) + { + return looks_like_a_text_line_image(input, lines, + literal::green, literal::red); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::debug + +} // end of namespace scribo + + +#endif // ! SCRIBO_DEBUG_LOOKS_LIKE_A_TEXT_LINE_IMAGE_HH diff --git a/scribo/debug/mean_and_base_lines_image.hh b/scribo/debug/mean_and_base_lines_image.hh new file mode 100644 index 0000000..c4517c7 --- /dev/null +++ b/scribo/debug/mean_and_base_lines_image.hh @@ -0,0 +1,147 @@ +// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// +// This file is part of Olena. +// +// Olena is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation, version 2 of the License. +// +// Olena is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Olena. If not, see <http://www.gnu.org/licenses/>. +// +// As a special exception, you may use this file as part of a free +// software project without restriction. Specifically, if other files +// instantiate templates or use macros or inline functions from this +// file, or you compile this file and link it with other files to produce +// an executable, this file does not by itself cause the resulting +// executable to be covered by the GNU General Public License. This +// exception does not however invalidate any other reasons why the +// executable file might be covered by the GNU General Public License. + +#ifndef SCRIBO_DEBUG_MEAN_AND_BASE_LINES_IMAGE_HH +# define SCRIBO_DEBUG_MEAN_AND_BASE_LINES_IMAGE_HH + +/// \file +/// +/// \brief Compute a color image showing the mean and the base lines +/// of the text lines. + +# include <mln/core/concept/image.hh> +# include <mln/data/convert.hh> +# include <mln/value/rgb8.hh> +# include <mln/literal/colors.hh> + +# include <mln/draw/box.hh> +# include <mln/draw/dashed_line.hh> + +# include <scribo/core/line_set.hh> + + +namespace scribo +{ + + namespace debug + { + + using namespace mln; + + + /// \brief Compute a color image showing the mean and the base lines + /// of the text lines. + /// + /// The mean line is drawn with a dashed line. + /// The base line is drawn with a plain line. + /// + /// \param[in] input An image convertible towards a color image. + /// \param[in] lines A line set. + /// \param[in] bbox_value Value used to draw lines bounding boxes. + /// \param[in] meanline_value Value used to draw mean lines. + /// \param[in] baseline_value Value used to draw base lines. + /// + /// \return A color image. + // + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + mean_and_base_lines_image(const Image<I>& input, + const line_set<L>& lines, + const value::rgb8& bbox_value, + const value::rgb8& meanline_value, + const value::rgb8& baseline_value); + + /// \overload + /// text_value is set to literal::green. + /// non_text_value is set to literal::red. + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + mean_and_base_lines_image(const Image<I>& input, + const line_set<L>& lines); + + +# ifndef MLN_INCLUDE_ONLY + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + mean_and_base_lines_image(const Image<I>& input, + const line_set<L>& lines, + const value::rgb8& bbox_value, + const value::rgb8& meanline_value, + const value::rgb8& baseline_value) + { + trace::entering("scribo::debug::mean_and_base_lines_image"); + mln_precondition(exact(input).is_valid()); + + image2d<value::rgb8> output = data::convert(value::rgb8(), input); + + for_all_lines(l, lines) + { + if (! lines(l).hidden()) + { + mln::draw::box(output, lines(l).bbox(), bbox_value); + + if (! (lines(l).type() == line::Text + || (lines(l).type() == line::Undefined + && lines(l).tag() == line::None + && lines(l).card() > 2))) + continue; + + point2d + b_top(lines(l).meanline(), lines(l).bbox().pmin().col()), + e_top(lines(l).meanline(), lines(l).bbox().pmax().col()), + b_bot(lines(l).baseline(), lines(l).bbox().pmin().col()), + e_bot(lines(l).baseline(), lines(l).bbox().pmax().col()); + + mln::draw::line(output, b_bot, e_bot, baseline_value); + mln::draw::dashed_line(output, b_top, e_top, meanline_value); + + } + } + + trace::exiting("scribo::debug::mean_and_base_lines_image"); + return output; + } + + + template <typename I, typename L> + mln_ch_value(I,value::rgb8) + mean_and_base_lines_image(const Image<I>& input, + const line_set<L>& lines) + { + return mean_and_base_lines_image(input, lines, + literal::purple, literal::blue, + literal::cyan); + } + +# endif // ! MLN_INCLUDE_ONLY + + } // end of namespace scribo::debug + +} // end of namespace scribo + + +#endif // ! SCRIBO_DEBUG_MEAN_AND_BASE_LINES_IMAGE_HH diff --git a/scribo/debug/save_bboxes_image.hh b/scribo/debug/save_bboxes_image.hh index 0265ee4..60f2c8d 100644 --- a/scribo/debug/save_bboxes_image.hh +++ b/scribo/debug/save_bboxes_image.hh @@ -48,12 +48,30 @@ namespace scribo using namespace mln; - /// Draw a list of bounding boxes and their associated mass center. + /// Draw a list of bounding boxes template <typename I> void save_bboxes_image(const Image<I>& input, const mln::util::array< box<mln_site(I)> >& bboxes, - const value::rgb8& value, + const std::string& filename, + const value::rgb8& value); + + + template <typename I, typename L> + void + save_bboxes_image(const Image<I>& input, + const line_set<L>& lines, + const std::string& filename, + const value::rgb8& value); + + /// \overload + /// value is set to literal::red. + // + template <typename I, typename L> + inline + void + save_bboxes_image(const Image<I>& input, + const line_set<L>& lines, const std::string& filename); @@ -64,8 +82,8 @@ namespace scribo void save_bboxes_image(const Image<I>& input, const mln::util::array< box<mln_site(I)> >& bboxes, - const value::rgb8& value, - const std::string& filename) + const std::string& filename, + const value::rgb8& value) { trace::entering("scribo::debug::save_bboxes_image"); mln_precondition(exact(input).is_valid()); @@ -77,6 +95,40 @@ namespace scribo trace::exiting("scribo::debug::save_bboxes_image"); } + + template <typename I, typename L> + inline + void + save_bboxes_image(const Image<I>& input, + const line_set<L>& lines, + const std::string& filename, + const value::rgb8& value) + { + trace::entering("scribo::debug::save_bboxes_image"); + mln_precondition(exact(input).is_valid()); + + image2d<value::rgb8> output = data::convert(value::rgb8(), input); + + for_all_lines(l, lines) + if (! lines(l).hidden()) + mln::draw::box(output, lines(l).bbox(), value); + + io::ppm::save(output, filename); + trace::exiting("scribo::debug::save_bboxes_image"); + } + + + template <typename I, typename L> + inline + void + save_bboxes_image(const Image<I>& input, + const line_set<L>& lines, + const std::string& filename) + { + return save_bboxes_image(input, lines, filename, literal::red); + } + + # endif // ! MLN_INCLUDE_ONLY } // end of namespace scribo::debug diff --git a/scribo/debug/usage.hh b/scribo/debug/usage.hh index e3872a9..6b6c9b7 100644 --- a/scribo/debug/usage.hh +++ b/scribo/debug/usage.hh @@ -53,21 +53,22 @@ namespace scribo inline int usage(char* argv[], const char *desc, const char* args, - const char*args_desc[][2], const char *out_desc) + const char*args_desc[][2], const char *out_desc = 0) { std::cout << "Usage: " << argv[0] << " " << args << std::endl << std::endl; std::cout << "-----------" << std::endl; - std::cout << std::endl - << desc << std::endl + std::cout << desc << std::endl << std::endl; for (unsigned i = 0; args_desc[i][0] != 0; ++i) std::cout << " " << args_desc[i][0] << ": " << args_desc[i][1] << std::endl; - std::cout << std::endl << "Output: " << out_desc << std::endl; + if (out_desc) + std::cout << std::endl << "Output: " << out_desc << std::endl; + std::cout << "-----------" << std::endl; std::cout << "EPITA/LRDE - Scribo 2009" << std::endl; return 1; -- 1.5.6.5
participants (1)
-
Guillaume Lazzara