last-svn-commit-783-g38639f4 Add new debug tools.

* scribo/src/debug/Makefile.am: New targets. * scribo/src/debug/show_separators.cc, * scribo/src/debug/show_stoppers.cc, * scribo/src/debug/show_text_lines.cc: New. --- scribo/ChangeLog | 10 ++ scribo/src/debug/Makefile.am | 12 ++- .../lines_pattern.cc => debug/show_separators.cc} | 74 +++++++++----- scribo/src/debug/show_stoppers.cc | 104 ++++++++++++++++++++ .../show_text_lines.cc} | 100 +++++++++++-------- 5 files changed, 225 insertions(+), 75 deletions(-) copy scribo/src/{primitive/extract/lines_pattern.cc => debug/show_separators.cc} (50%) create mode 100644 scribo/src/debug/show_stoppers.cc copy scribo/src/{text/pbm_lines_recognition.cc => debug/show_text_lines.cc} (52%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 74c7a03..4a9dcbf 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,15 @@ 2011-03-01 Guillaume Lazzara <z@lrde.epita.fr> + Add new debug tools. + + * scribo/src/debug/Makefile.am: New targets. + + * scribo/src/debug/show_separators.cc, + * scribo/src/debug/show_stoppers.cc, + * scribo/src/debug/show_text_lines.cc: New. + +2011-03-01 Guillaume Lazzara <z@lrde.epita.fr> + * scribo/text/extract_lines.hh: Update code. 2011-03-01 Guillaume Lazzara <z@lrde.epita.fr> diff --git a/scribo/src/debug/Makefile.am b/scribo/src/debug/Makefile.am index d203f5c..cdb1f30 100644 --- a/scribo/src/debug/Makefile.am +++ b/scribo/src/debug/Makefile.am @@ -1,5 +1,5 @@ -# Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -# (LRDE). +# Copyright (C) 2009, 2010, 2011 EPITA Research and Development +# Laboratory (LRDE). # # This file is part of Olena. # @@ -20,6 +20,7 @@ include $(top_srcdir)/scribo/scribo.mk noinst_PROGRAMS = \ show_info_x_height \ show_info_median_inter_characters \ + show_separators \ show_links_left_right_links_validation \ show_links_bbox_h_ratio \ show_links_bbox_overlap \ @@ -43,11 +44,14 @@ noinst_PROGRAMS = \ show_objects_large_small \ show_objects_small \ show_objects_thick \ - show_objects_thin + show_objects_thin \ + show_stoppers \ + show_text_lines show_info_x_height_SOURCES = show_info_x_height.cc show_info_median_inter_characters_SOURCES = show_info_median_inter_characters.cc +show_separators_SOURCES = show_separators.cc show_links_left_right_links_validation_SOURCES = show_links_left_right_links_validation.cc show_links_bbox_h_ratio_SOURCES = show_links_bbox_h_ratio.cc show_links_bbox_overlap_SOURCES = show_links_bbox_overlap.cc @@ -72,6 +76,8 @@ show_objects_large_small_SOURCES = show_objects_large_small.cc show_objects_small_SOURCES = show_objects_small.cc show_objects_thick_SOURCES = show_objects_thick.cc show_objects_thin_SOURCES = show_objects_thin.cc +show_stoppers_SOURCES = show_stoppers.cc +show_text_lines_SOURCES = show_text_lines.cc if HAVE_MAGICKXX diff --git a/scribo/src/primitive/extract/lines_pattern.cc b/scribo/src/debug/show_separators.cc similarity index 50% copy from scribo/src/primitive/extract/lines_pattern.cc copy to scribo/src/debug/show_separators.cc index cb56b36..ef80da6 100644 --- a/scribo/src/primitive/extract/lines_pattern.cc +++ b/scribo/src/debug/show_separators.cc @@ -1,5 +1,4 @@ -// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -// (LRDE) +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -14,33 +13,25 @@ // // 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. #include <mln/core/image/image2d.hh> +#include <mln/core/alias/box2d.hh> +#include <mln/core/alias/neighb2d.hh> #include <mln/io/pbm/all.hh> -#include <mln/pw/all.hh> -#include <mln/data/fill.hh> -#include <mln/core/image/dmorph/image_if.hh> +#include <mln/arith/plus.hh> +#include <mln/labeling/foreground.hh> #include <scribo/primitive/extract/lines_h_pattern.hh> #include <scribo/primitive/extract/lines_v_pattern.hh> #include <scribo/debug/usage.hh> +#include <scribo/debug/save_bboxes_image.hh> const char *args_desc[][2] = { - { "input.pbm", "A binary image." }, - { "length", " Minimum line length. (Common value : 51)" }, + { "length", " Minimum line length. (default: 101)" }, { "delta", " Distance between the object pixel and the background pixel" - "(Common value : 4)" }, + "(default: 4)" }, {0, 0} }; @@ -49,10 +40,10 @@ int main(int argc, char *argv[]) { using namespace mln; - if (argc != 5) + if (argc != 7 && argc != 5) return scribo::debug::usage(argv, - "Extract horizontal lines patterns", - "input.pbm length delta output.pbm", + "Extract horizontal and vertical lines patterns", + "input.pbm output.pbm input_wo_seps.pbm output.ppm length delta", args_desc); trace::entering("main"); @@ -60,19 +51,46 @@ int main(int argc, char *argv[]) image2d<bool> input; io::pbm::load(input, argv[1]); + // Set default option value + unsigned + length = 101, + delta = 4; + if (argc > 5) + { + length = atoi(argv[5]); + delta = atoi(argv[6]); + } + + util::timer t; + t.start(); + image2d<bool> - h_lines = scribo::primitive::extract::lines_h_pattern(input, - atoi(argv[2]), - atoi(argv[3])); + h_lines = scribo::primitive::extract::lines_h_pattern(input, length, delta); image2d<bool> - v_lines = scribo::primitive::extract::lines_v_pattern(input, - atoi(argv[2]), - atoi(argv[3])); + v_lines = scribo::primitive::extract::lines_v_pattern(input, length, delta); + + v_lines += h_lines; + + t.stop(); + std::cout << t << "s" << std::endl; + + // Save binary image. + io::pbm::save(v_lines, argv[2]); - data::fill((v_lines | pw::value(h_lines)).rw(), true); + // Save input without separators + { + image2d<bool> in_wo_seps = duplicate(input); + data::fill((in_wo_seps | pw::value(v_lines)).rw(), false); + io::pbm::save(in_wo_seps, argv[3]); + } - io::pbm::save(v_lines, argv[4]); + // Save bbox image + value::int_u8 nlabels; + image2d<value::int_u8> lbl = labeling::foreground(v_lines, c4(), nlabels); + mln::util::array<box2d> + bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels); + scribo::debug::save_bboxes_image(input, bbox, argv[4], literal::red); trace::exiting("main"); } diff --git a/scribo/src/debug/show_stoppers.cc b/scribo/src/debug/show_stoppers.cc new file mode 100644 index 0000000..a108da1 --- /dev/null +++ b/scribo/src/debug/show_stoppers.cc @@ -0,0 +1,104 @@ +// Copyright (C) 2011 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/>. + +#include <mln/core/image/image2d.hh> +#include <mln/core/alias/box2d.hh> +#include <mln/core/alias/neighb2d.hh> +#include <mln/io/pbm/all.hh> +#include <mln/arith/plus.hh> +#include <mln/labeling/foreground.hh> + +#include <scribo/primitive/extract/lines_h_pattern.hh> +#include <scribo/primitive/extract/lines_v_pattern.hh> +#include <scribo/primitive/extract/separators_nonvisible.hh> +#include <scribo/debug/usage.hh> +#include <scribo/debug/save_bboxes_image.hh> + + +const char *args_desc[][2] = +{ + { "length", " Minimum line length. (default: 101)" }, + { "delta", " Distance between the object pixel and the background pixel" + "(default: 4)" }, + {0, 0} +}; + + +int main(int argc, char *argv[]) +{ + using namespace mln; + + if (argc != 7 && argc != 5) + return scribo::debug::usage(argv, + "Extract horizontal, vertical lines and stoppers", + "input.pbm output.pbm input_wo_seps.pbm output.ppm length delta", + args_desc); + + trace::entering("main"); + + image2d<bool> input; + io::pbm::load(input, argv[1]); + + // Set default option value + unsigned + length = 101, + delta = 4; + if (argc > 5) + { + length = atoi(argv[5]); + delta = atoi(argv[6]); + } + + util::timer t; + + t.start(); + image2d<bool> + h_lines = scribo::primitive::extract::lines_h_pattern(input, length, delta); + + image2d<bool> + v_lines = scribo::primitive::extract::lines_v_pattern(input, length, delta); + + v_lines += h_lines; + + t.stop(); + + // Save input without separators + { + image2d<bool> in_wo_seps = duplicate(input); + data::fill((in_wo_seps | pw::value(v_lines)).rw(), false); + io::pbm::save(in_wo_seps, argv[3]); + } + + // Save bbox image + value::int_u8 nlabels; + image2d<value::int_u8> lbl = labeling::foreground(v_lines, c4(), nlabels); + mln::util::array<box2d> + bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels); + scribo::debug::save_bboxes_image(input, bbox, argv[4], literal::red); + + t.resume(); + + // Non visible separators + v_lines += scribo::primitive::extract::separators_nonvisible(input); + + t.stop(); + std::cout << t << "s" << std::endl; + + // Save binary image. + io::pbm::save(v_lines, argv[2]); + + trace::exiting("main"); +} diff --git a/scribo/src/text/pbm_lines_recognition.cc b/scribo/src/debug/show_text_lines.cc similarity index 52% copy from scribo/src/text/pbm_lines_recognition.cc copy to scribo/src/debug/show_text_lines.cc index 3451449..a031072 100644 --- a/scribo/src/text/pbm_lines_recognition.cc +++ b/scribo/src/debug/show_text_lines.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE) +// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE) // // This file is part of Olena. // @@ -23,15 +23,15 @@ // exception does not however invalidate any other reasons why the // executable file might be covered by the GNU General Public License. -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - #include <iostream> #include <mln/core/image/image2d.hh> #include <mln/io/pbm/load.hh> #include <mln/value/int_u16.hh> +#include <mln/draw/box_plain.hh> +#include <mln/pw/all.hh> +#include <mln/core/image/dmorph/image_if.hh> +#include <mln/data/convert.hh> #include <scribo/text/recognition.hh> @@ -41,19 +41,15 @@ #include <scribo/core/object_links.hh> #include <scribo/core/object_groups.hh> -#include <scribo/text/merging.hh> -#include <scribo/primitive/extract/components.hh> -#include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh> -#include <scribo/primitive/group/from_single_link.hh> +#include <scribo/text/extract_lines.hh> #include <scribo/io/text_boxes/save.hh> +#include <scribo/debug/save_bboxes_image.hh> + const char *args_desc[][2] = { - { "input.pbm", "A binary image. 'True' for objects, 'False'\ -for the background." }, - { "lang", "Must be set to \"eng\", \"fra\", \"deu\", \"spa\", \"ita\" (Default \"fra\")" }, {0, 0} }; @@ -64,10 +60,10 @@ int main(int argc, char* argv[]) using namespace scribo; using namespace mln; - if (argc != 2 && argc != 3 && argc != 4) + if (argc != 6) return scribo::debug::usage(argv, - "Text recognition", - "input.pbm [lang] [file]", + "Show text lines", + "input.pbm input_seps.pbm out.ppm out.pbm comps.pbm", args_desc); trace::entering("main"); @@ -75,37 +71,53 @@ int main(int argc, char* argv[]) image2d<bool> input; mln::io::pbm::load(input, argv[1]); - typedef image2d<value::int_u16> L; - value::int_u16 ncomps; - component_set<L> - comps = scribo::primitive::extract::components(input, c8(), ncomps); - std::cout << "ncomps = " << ncomps << std::endl; - - object_links<L> - links = scribo::primitive::link::with_single_left_link_dmax_ratio(comps, 2); - - object_groups<L> - groups = scribo::primitive::group::from_single_link(links); + image2d<bool> input_seps; + mln::io::pbm::load(input_seps, argv[2]); - line_set<L> lines(groups); - lines = text::merging(lines); + util::timer t; + t.start(); - std::string str = argv[2]; - const char *lang; - if (argc < 3 || (str != "eng" && str != "fra" - && str != "deu" && str != "spa" - && str != "ita")) - lang = "fra"; - else - lang = argv[2]; - - char *output = 0; - if (argc >= 4) - output = argv[3]; - - scribo::text::recognition(lines, lang); - - scribo::io::text_boxes::save(lines, output); + typedef image2d<value::int_u16> L; + line_set<L> lines = text::extract_lines(input, c8(), input_seps); + + t.stop(); + std::cout << t << "s" << std::endl; + + // Color image with line bboxes. + { + image2d<value::rgb8> output = data::convert(value::rgb8(), input); + for_all_lines(l, lines) + if (lines(l).is_textline()) + mln::draw::box(output, lines(l).bbox(), literal::red); + mln::io::ppm::save(output, argv[3]); + } + + // Binary image with line bboxes. + { + image2d<bool> output; + initialize(output, input); + data::fill(output, false); + for_all_lines(l, lines) + if (lines(l).is_textline()) + mln::draw::box_plain(output, lines(l).bbox(), true); + mln::io::pbm::save(output, argv[4]); + } + + { + image2d<bool> output; + initialize(output, input); + data::fill(output, false); + for_all_lines(l, lines) + if (lines(l).is_textline()) + { + const util::array<component_id_t>& comps = lines(l).components(); + const L& lbl = lines.components().labeled_image(); + for_all_elements(c, comps) + data::fill((output | lines.components()(comps(c)).bbox()).rw(), + ((input | lines.components()(comps(c)).bbox()) | (pw::value(lbl) == comps(c)))); + } + mln::io::pbm::save(output, argv[5]); + } trace::exiting("main"); } -- 1.5.6.5
participants (1)
-
Guillaume Lazzara