Olena-patches
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
May 2011
- 9 participants
- 171 discussions

last-svn-commit-894-g3a15c02 scribo/primitive/extract/lines_h_thick_and_thin.hh: Improve result quality.
by Guillaume Lazzara 26 May '11
by Guillaume Lazzara 26 May '11
26 May '11
---
scribo/ChangeLog | 5 +++++
.../primitive/extract/lines_h_thick_and_thin.hh | 16 ++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 87364fc..b1be73d 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/primitive/extract/lines_h_thick_and_thin.hh: Improve
+ result quality.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new hooks in toolchain functors.
* toolchain/internal/toolchain_functor.hh: Here.
diff --git a/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh b/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh
index 511da9f..53a5c32 100644
--- a/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh
+++ b/scribo/scribo/primitive/extract/lines_h_thick_and_thin.hh
@@ -83,7 +83,7 @@ namespace scribo
unsigned length, unsigned delta,
float p_few = 0.2, // very tolerant (v. severe is 0.05)
float p_enough = 0.6, // very tolerant (v. severe is 0.80)
- unsigned filter_factor = 1);
+ float ratio = 8);
# ifndef MLN_INCLUDE_ONLY
@@ -469,7 +469,7 @@ namespace scribo
lines_h_thick_and_thin(const Image<I>& binary_image_,
unsigned length, unsigned delta,
float p_few, float p_enough,
- unsigned filter_factor)
+ float ratio)
{
trace::entering("scribo::primitive::extract::lines_h_thick_and_thin");
@@ -504,9 +504,17 @@ namespace scribo
mln::util::array<box2d>
bbox = labeling::compute(accu::shape::bbox<point2d>(), lbl, nlabels);
+ image2d<value::int_u8> debug;
+ initialize(debug, binary_image);
+ data::fill(debug, 0);
for_all_ncomponents(e, nlabels)
- if (bbox(e).width() < filter_factor * length || bbox(e).width() / bbox(e).height() < 3)
- data::fill(((output | bbox(e)).rw() | (pw::value(lbl) == pw::cst(e))).rw(), false);
+ {
+ if (bbox(e).width() < length ||
+ (std::max(bbox(e).width(), bbox(e).height()) /
+ std::min(bbox(e).width(), bbox(e).height()) + 0.49999) < ratio)
+ data::fill(((output | bbox(e)).rw()
+ | (pw::value(lbl) == pw::cst(e))).rw(), false);
+ }
debug::logger().log_image(debug::Results,
output, "lines_h_thick_and_thin_output");
--
1.5.6.5
1
0

26 May '11
* 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(a)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(a)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
1
0

last-svn-commit-892-g9f7843c scribo/util/component_precise_outline.hh: New. Precise component outline extraction.
by Guillaume Lazzara 26 May '11
by Guillaume Lazzara 26 May '11
26 May '11
---
scribo/ChangeLog | 5 +
scribo/scribo/util/component_precise_outline.hh | 309 +++++++++++++++++++++++
2 files changed, 314 insertions(+), 0 deletions(-)
create mode 100644 scribo/scribo/util/component_precise_outline.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 16762ae..13b8e95 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/util/component_precise_outline.hh: New. Precise component
+ outline extraction.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new element filters.
* scribo/filter/images_in_paragraph.hh,
diff --git a/scribo/scribo/util/component_precise_outline.hh b/scribo/scribo/util/component_precise_outline.hh
new file mode 100644
index 0000000..3c6e523
--- /dev/null
+++ b/scribo/scribo/util/component_precise_outline.hh
@@ -0,0 +1,309 @@
+// 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/>.
+//
+// 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_UTIL_COMPONENT_PRECISE_OUTLINE_HH
+# define SCRIBO_UTIL_COMPONENT_PRECISE_OUTLINE_HH
+
+/*!
+ * \file
+ *
+ * \brief Define a function which finds a precise and isothetic
+ * outline.
+ *
+ */
+
+
+# include <mln/io/pbm/load.hh>
+# include <mln/literal/colors.hh>
+# include <mln/io/ppm/save.hh>
+# include <mln/data/convert.hh>
+# include <mln/opt/at.hh>
+
+# include <iostream>
+
+namespace scribo
+{
+
+ namespace util
+ {
+
+ using namespace mln;
+
+
+ template <typename I>
+ mln::p_array<point2d>
+ component_precise_outline(const Image<I>& input_);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+
+ static const int offset[4][8][2] =
+ {
+ { { -1, 0 }, { 0, -1 }, { -1, -1 }, { 1, 0 }, { 1, -1 }, { 0, 1 }, {
+ 1, 1 }, { -1, 1 } },
+ { { 0, -1 }, { 1, 0 }, { 1, -1 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, {
+ -1, 1 }, { -1, -1 } },
+ { { 1, 0 }, { 0, 1 }, { 1, 1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, {
+ -1, -1 }, { 1, -1 } },
+ { { 0, 1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { -1, -1 }, { 1, 0 }, {
+ 1, -1 }, { 1, 1 } }
+ };
+
+
+ template <typename I>
+ void
+ find_first_point(const I& input,
+ point2d& p)
+ {
+ const def::coord mid_row = geom::min_row(input) + (geom::nrows(input) >> 1);
+
+ for (def::coord i = geom::min_col(input); i <= geom::max_col(input); ++i)
+ {
+ if (opt::at(input, mid_row, i))
+ {
+ p.row() = mid_row;
+ p.col() = i;
+ break;
+ }
+ }
+ }
+
+ template <typename I>
+ void
+ left_up(int& direction,
+ const unsigned i,
+ const I& input,
+ const point2d& cur_pt)
+ {
+ if (i < 3)
+ {
+ const point2d p1(cur_pt.row() + offset[direction][0][1],
+ cur_pt.col() + offset[direction][0][0]);
+ const point2d p2(cur_pt.row() + offset[direction][5][1],
+ cur_pt.col() + offset[direction][5][0]);
+ const point2d p3(cur_pt.row() + offset[direction][7][1],
+ cur_pt.col() + offset[direction][7][0]);
+
+ if (input(p1) && !input(p2) && input(p3))
+ {
+ direction = 3;
+ return;
+ }
+ }
+
+ if (i == 3 || i == 4)
+ direction = 1;
+ else if (i == 5 || i == 6)
+ direction = 2;
+ else if (i == 7)
+ direction = 3;
+ }
+
+
+ template <typename I>
+ void
+ right_up(int& direction,
+ const unsigned i,
+ const I& input,
+ const point2d& cur_pt)
+ {
+ if (i < 3)
+ {
+ const point2d p2(cur_pt.row() + offset[direction][5][1],
+ cur_pt.col() + offset[direction][5][0]);
+ const point2d p3(cur_pt.row() + offset[direction][7][1],
+ cur_pt.col() + offset[direction][7][0]);
+
+ if (!input(p2) && input(p3))
+ {
+ direction = 0;
+ return;
+ }
+ }
+
+ if (i == 3 || i == 4)
+ direction = 2;
+ else if (i == 5 || i == 6)
+ direction = 3;
+ else if (i == 7)
+ direction = 0;
+ }
+
+
+ template <typename I>
+ void
+ right_down(int& direction,
+ const unsigned i,
+ const I& input,
+ const point2d& cur_pt)
+ {
+ if (i < 3)
+ {
+ const point2d p1(cur_pt.row() + offset[direction][0][1],
+ cur_pt.col() + offset[direction][0][0]);
+ const point2d p2(cur_pt.row() + offset[direction][5][1],
+ cur_pt.col() + offset[direction][5][0]);
+ const point2d p3(cur_pt.row() + offset[direction][7][1],
+ cur_pt.col() + offset[direction][7][0]);
+
+ if (input(p1) && !input(p2) && input(p3))
+ {
+ direction = 1;
+ return;
+ }
+ }
+
+ if (i == 3 || i == 4)
+ direction = 3;
+ else if (i == 5 || i == 6)
+ direction = 0;
+ else if (i == 7)
+ direction = 1;
+ }
+
+
+ template <typename I>
+ void
+ left_down(int& direction,
+ const unsigned i,
+ const I& input,
+ const point2d& cur_pt)
+ {
+ if (i < 3)
+ {
+ const point2d p2(cur_pt.row() + offset[direction][5][1],
+ cur_pt.col() + offset[direction][5][0]);
+ const point2d p3(cur_pt.row() + offset[direction][7][1],
+ cur_pt.col() + offset[direction][7][0]);
+
+ if (!input(p2) && input(p3))
+ {
+ direction = 2;
+ return;
+ }
+ }
+
+ if (i == 3 || i == 4)
+ direction = 0;
+ else if (i == 5 || i == 6)
+ direction = 1;
+ else if (i == 7)
+ direction = 2;
+ }
+
+ template <typename I>
+ void
+ find_next_point(const I& input,
+ point2d& cur_pt,
+ int& direction)
+ {
+ unsigned i = 0;
+ point2d tmp;
+
+ for (; i < 8; ++i)
+ {
+ tmp = point2d(cur_pt.row() + offset[direction][i][1],
+ cur_pt.col() + offset[direction][i][0]);
+
+ if (input.domain().has(tmp) && input(tmp))
+ break;
+ }
+
+ // Should not happen
+ if (i == 8)
+ return;
+
+ switch (direction)
+ {
+ case 0: left_up(direction, i, input, cur_pt); break;
+ case 1: right_up(direction , i, input, cur_pt); break;
+ case 2: right_down(direction, i, input, cur_pt); break;
+ case 3: left_down(direction, i, input, cur_pt); break;
+ }
+
+ cur_pt = tmp;
+ }
+
+ } // end of namespace scribo::util::internal
+
+
+ template <typename I>
+ mln::p_array<point2d>
+ component_precise_outline(const Image<I>& input_)
+ {
+ trace::entering("scribo::util::component_precise_outline");
+
+ const I& input = exact(input_);
+ typedef mln_site(I) P;
+
+ point2d start_pt;
+ int direction = 0;
+ mln::p_array<P> points;
+ points.reserve(std::max(geom::ncols(input), geom::nrows(input)));
+
+ internal::find_first_point(input, start_pt);
+
+ P cur_pt = start_pt;
+
+ internal::find_next_point(input, cur_pt, direction);
+ points.append(cur_pt);
+
+ while (cur_pt != start_pt)
+ {
+ internal::find_next_point(input, cur_pt, direction);
+ points.append(cur_pt);
+ }
+
+
+ internal::find_next_point(input, cur_pt, direction);
+
+ const std::vector<point2d>& vec_points = points.hook_std_vector_();
+
+ if (std::find(vec_points.begin(), vec_points.end(), cur_pt) == vec_points.end())
+ {
+ points.append(cur_pt);
+
+ while (cur_pt != start_pt)
+ {
+ internal::find_next_point(input, cur_pt, direction);
+ points.append(cur_pt);
+ }
+ }
+
+ trace::exiting("scribo::util::component_precise_outline");
+ return points;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::util
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_UTIL_COMPONENT_PRECISE_OUTLINE_HH
--
1.5.6.5
1
0
* scribo/filter/images_in_paragraph.hh,
* scribo/filter/paragraphs_bbox_overlap.hh,
* scribo/filter/paragraphs_in_image.hh,
* scribo/filter/separators_in_element.hh,
* scribo/filter/separators_in_paragraph.hh: New.
---
scribo/ChangeLog | 10 ++
scribo/scribo/filter/images_in_paragraph.hh | 119 +++++++++++++++
scribo/scribo/filter/paragraphs_bbox_overlap.hh | 176 +++++++++++++++++++++++
scribo/scribo/filter/paragraphs_in_image.hh | 129 +++++++++++++++++
scribo/scribo/filter/separators_in_element.hh | 151 +++++++++++++++++++
scribo/scribo/filter/separators_in_paragraph.hh | 151 +++++++++++++++++++
6 files changed, 736 insertions(+), 0 deletions(-)
create mode 100644 scribo/scribo/filter/images_in_paragraph.hh
create mode 100644 scribo/scribo/filter/paragraphs_bbox_overlap.hh
create mode 100644 scribo/scribo/filter/paragraphs_in_image.hh
create mode 100644 scribo/scribo/filter/separators_in_element.hh
create mode 100644 scribo/scribo/filter/separators_in_paragraph.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 959746f..16762ae 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add new element filters.
+
+ * scribo/filter/images_in_paragraph.hh,
+ * scribo/filter/paragraphs_bbox_overlap.hh,
+ * scribo/filter/paragraphs_in_image.hh,
+ * scribo/filter/separators_in_element.hh,
+ * scribo/filter/separators_in_paragraph.hh: New.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add util::box_intersection.
* scribo/util/box_intersection.hh: New.
diff --git a/scribo/scribo/filter/images_in_paragraph.hh b/scribo/scribo/filter/images_in_paragraph.hh
new file mode 100644
index 0000000..e05b202
--- /dev/null
+++ b/scribo/scribo/filter/images_in_paragraph.hh
@@ -0,0 +1,119 @@
+// 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/>.
+//
+// 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_FILTER_IMAGES_IN_PARAGRAPH_HH
+# define SCRIBO_FILTER_IMAGES_IN_PARAGRAPH_HH
+
+/// \file
+///
+/// Invalidate false positive separators.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/document.hh>
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /// Invalidate false positive separators.
+ ///
+ /// \param[in] separators A paragraph set.
+ ///
+ /// \return A doc with invalidated separators.
+ ///
+ /// Warning: it does not remove separators from separator
+ /// image. It only invalidate separator components in their
+ /// respective component_set.
+ ///
+ template <typename L>
+ void
+ images_in_paragraph(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ void
+ images_in_paragraph(document<L>& doc)
+ {
+ trace::entering("scribo::filter::images_in_paragraph");
+
+ mln_precondition(doc.is_valid());
+
+ if (! doc.has_elements())
+ return;
+
+ mln_ch_value(L,bool) billboard;
+ initialize(billboard, doc.image());
+ data::fill(billboard, false);
+
+ for_all_comps(p, doc.paragraphs())
+ if (doc.paragraphs()(p).is_valid())
+ mln::draw::box_plain(billboard, doc.paragraphs()(p).bbox(), true);
+
+
+ component_set<L> elts = doc.elements();
+ for_all_comps(c, elts)
+ if (elts(c).is_valid() && elts(c).type() == component::Image)
+ {
+ const mln_box(L)& b_ = elts(c).bbox();
+
+ const bool tl = billboard(b_.pmin());
+ const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+ const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+ const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+ const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+ const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+ const bool br = billboard(b_.pmax());
+
+ // This separator is included in an element (picture, drawing...)
+ // => Ignore it.
+ if (tl && tr && ml && mc && mr && bl && br)
+ elts(c).update_tag(component::Ignored);
+
+ // FIXME: warning this call may produce inconsistent data
+ // Ignored components are still in the separator image...
+ doc.set_elements(elts);
+ }
+
+ trace::exiting("scribo::filter::images_in_paragraph");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_IMAGES_IN_PARAGRAPH_HH
diff --git a/scribo/scribo/filter/paragraphs_bbox_overlap.hh b/scribo/scribo/filter/paragraphs_bbox_overlap.hh
new file mode 100644
index 0000000..aa1c8ac
--- /dev/null
+++ b/scribo/scribo/filter/paragraphs_bbox_overlap.hh
@@ -0,0 +1,176 @@
+// 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/>.
+//
+// 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_FILTER_PARAGRAPHS_BBOX_OVERLAP_HH
+# define SCRIBO_FILTER_PARAGRAPHS_BBOX_OVERLAP_HH
+
+/// \file
+///
+/// Remove invalid paragraphs.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+# include <mln/data/transform.hh>
+# include <mln/util/array.hh>
+
+# include <scribo/core/paragraph_set.hh>
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /// Remove invalid paragraphs.
+ ///
+ /// \param[in] paragraphs A paragraph set.
+ ///
+ /// \return A paragraph set with invalid paragraphs tag set to
+ /// Paragraph::Ignored.
+ template <typename L>
+ paragraph_set<L>
+ paragraphs_bbox_overlap(const paragraph_set<L>& paragraphs);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace internal
+ {
+
+ template <typename L>
+ struct order_paragraphs_id
+ {
+ order_paragraphs_id(const scribo::paragraph_set<L>& paragraphs)
+ : paragraphs_(paragraphs)
+ {
+ }
+
+ bool operator()(const scribo::paragraph_id_t& l1,
+ const scribo::paragraph_id_t& l2) const
+ {
+ const unsigned l1_nsites = paragraphs_(l1).bbox().nsites();
+ const unsigned l2_nsites = paragraphs_(l2).bbox().nsites();
+
+ if (l1_nsites == l2_nsites)
+ return l1 > l2;
+ return l1_nsites > l2_nsites;
+ }
+
+ scribo::paragraph_set<L> paragraphs_;
+ };
+
+ } // end of namespace scribo::filter::internal
+
+
+ template <typename L>
+ paragraph_set<L>
+ paragraphs_bbox_overlap(const paragraph_set<L>& paragraphs)
+ {
+ trace::entering("scribo::filter::paragraphs_bbox_overlap");
+
+ mln_precondition(paragraphs.is_valid());
+
+ L billboard;
+ initialize(billboard, paragraphs.lines().components().labeled_image());
+ data::fill(billboard, 0);
+
+ mln::util::array<bool> not_to_ignore(paragraphs.nelements() + 1, true);
+ not_to_ignore(0) = false;
+
+ for_all_paragraphs(cur_id, paragraphs)
+ {
+ const box2d& b_ = paragraphs(cur_id).bbox();
+
+ if (paragraphs(cur_id).nlines() > 1)
+ {
+ mln::draw::box_plain(billboard, b_, cur_id);
+ continue;
+ }
+
+ const unsigned tl = billboard(b_.pmin());
+ const unsigned tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+ const unsigned ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+ const unsigned mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+ const unsigned mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+ const unsigned bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+ const unsigned br = billboard(b_.pmax());
+
+ typedef std::set<unsigned> set_t;
+ set_t labels;
+ labels.insert(tl);
+ labels.insert(tl);
+ labels.insert(tr);
+ labels.insert(ml);
+ labels.insert(mc);
+ labels.insert(mr);
+ labels.insert(bl);
+ labels.insert(br);
+
+ for (set_t::const_iterator it = labels.begin();
+ it != labels.end();
+ ++it)
+ if (not_to_ignore(*it))
+ {
+ box2d b2 = paragraphs(*it).bbox();
+ box2d b_i = scribo::util::box_intersection(b_, b2);
+
+ // si b_ est inclus dans une boite donc le nombre de comp > 1 => invalid juste b_
+ // sinon => invalid b_ et b2
+ if ((b_i.nsites() / (float)b_.nsites() > 0.4
+ || (b_i.nsites() / (float)b2.nsites()) > 0.9))
+ {
+ not_to_ignore(cur_id) = false;
+
+ if (paragraphs(*it).nlines() < 4)
+ not_to_ignore(*it) = false;
+ }
+ }
+
+ mln::draw::box_plain(billboard, b_, cur_id);
+ }
+
+ paragraph_set<L> output = paragraphs.duplicate();
+ output.invalidate(not_to_ignore);
+
+ trace::exiting("scribo::filter::paragraphs_bbox_overlap");
+ return output;
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_PARAGRAPHS_BBOX_OVERLAP_HH
diff --git a/scribo/scribo/filter/paragraphs_in_image.hh b/scribo/scribo/filter/paragraphs_in_image.hh
new file mode 100644
index 0000000..1029430
--- /dev/null
+++ b/scribo/scribo/filter/paragraphs_in_image.hh
@@ -0,0 +1,129 @@
+// 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/>.
+//
+// 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_FILTER_PARAGRAPHS_IN_IMAGE_HH
+# define SCRIBO_FILTER_PARAGRAPHS_IN_IMAGE_HH
+
+/// \file
+///
+/// Remove invalid paragraphs.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/neighborhood.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/image/dmorph/image_if.hh>
+
+# include <mln/data/transform.hh>
+
+# include <mln/util/array.hh>
+
+# include <mln/pw/all.hh>
+
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/fun/v2b/objects_small_filter.hh>
+# include <scribo/primitive/extract/components.hh>
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /// Remove invalid paragraphs.
+ ///
+ /// \param[in] paragraphs A paragraph set.
+ ///
+ /// \return A paragraph set with invalid paragraphs tag set to
+ /// Paragraph::Ignored.
+ template <typename L>
+ void
+ paragraphs_in_image(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ void
+ paragraphs_in_image(document<L>& doc)
+ {
+ trace::entering("scribo::filter::paragraphs_in_image");
+
+ mln_precondition(doc.has_elements());
+ mln_precondition(doc.has_text());
+
+ image2d<bool> billboard;
+ initialize(billboard, doc.lines().components().labeled_image());
+ data::fill(billboard, false);
+
+ // Draw Image bboxes.
+ for_all_elements(e, doc.elements())
+ if (doc.elements()(e).is_valid()
+ && doc.elements()(e).type() == component::Image)
+ mln::draw::box_plain(billboard, doc.elements()(e).bbox(), true);
+
+ mln::io::pbm::save(billboard, "billboard_parimage.pbm");
+
+ const paragraph_set<L>& parset = doc.paragraphs();
+ mln::util::array<bool> not_to_ignore(parset.nelements() + 1, true);
+ not_to_ignore(0) = false;
+
+ for_all_paragraphs(cur_id, parset)
+ {
+ const box2d& b_ = parset(cur_id).bbox();
+ const bool
+ tl = billboard(b_.pmin()),
+ tr = billboard.at_(b_.pmin().row(), b_.pmax().col()),
+ ml = billboard.at_(b_.pcenter().row(), b_.pmin().col()),
+ mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col()),
+ mr = billboard.at_(b_.pcenter().row(), b_.pmax().col()),
+ bl = billboard.at_(b_.pmax().row(), b_.pmin().col()),
+ br = billboard(b_.pmax());
+
+ // The paragraph is fully included in an image.
+ if (tl && tr && ml && mc && mr && bl && br)
+ not_to_ignore(cur_id) = false;
+ }
+
+ paragraph_set<L> output = parset.duplicate();
+ output.invalidate(not_to_ignore);
+ doc.set_paragraphs(output);
+
+ trace::exiting("scribo::filter::paragraphs_in_image");
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_PARAGRAPHS_IN_IMAGE_HH
diff --git a/scribo/scribo/filter/separators_in_element.hh b/scribo/scribo/filter/separators_in_element.hh
new file mode 100644
index 0000000..228d82f
--- /dev/null
+++ b/scribo/scribo/filter/separators_in_element.hh
@@ -0,0 +1,151 @@
+// 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/>.
+//
+// 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_FILTER_SEPARATORS_IN_ELEMENT_HH
+# define SCRIBO_FILTER_SEPARATORS_IN_ELEMENT_HH
+
+/// \file
+///
+/// Invalidate false positive separators.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/document.hh>
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /// Invalidate false positive separators.
+ ///
+ /// \param[in] separators A paragraph set.
+ ///
+ /// \return A doc with invalidated separators.
+ ///
+ /// Warning: it does not remove separators from separator
+ /// image. It only invalidate separator components in their
+ /// respective component_set.
+ ///
+ template <typename L>
+ void
+ separators_in_element(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ void
+ separators_in_element(document<L>& doc)
+ {
+ trace::entering("scribo::filter::separators_in_element");
+
+ mln_precondition(doc.is_valid());
+ mln_precondition(doc.has_elements());
+ mln_precondition(doc.has_hline_seps() || doc.has_vline_seps());
+
+ if ((doc.has_hline_seps() && !doc.hline_seps_comps().nelements())
+ && (doc.has_vline_seps() && !doc.vline_seps_comps().nelements()))
+ return;
+
+ mln_ch_value(L,bool) billboard;
+ initialize(billboard, doc.image());
+ data::fill(billboard, false);
+
+ for_all_comps(e, doc.elements())
+ if (doc.elements()(e).is_valid())
+ mln::draw::box_plain(billboard, doc.elements()(e).bbox(), true);
+
+ // Horizontal separators
+ if (doc.has_hline_seps())
+ {
+ component_set<L> hline = doc.hline_seps_comps().duplicate();
+ for_all_comps(c, hline)
+ {
+ const mln_box(L)& b_ = hline(c).bbox();
+
+ const bool tl = billboard(b_.pmin());
+ const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+ const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+ const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+ const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+ const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+ const bool br = billboard(b_.pmax());
+
+ // This separator is included in an element (picture, drawing...)
+ // => Ignore it.
+ if (tl && tr && ml && mc && mr && bl && br)
+ hline(c).update_tag(component::Ignored);
+
+ // FIXME: warning this call may produce inconsistent data
+ // Ignored components are still in the separator image...
+ doc.set_hline_separators(doc.hline_seps(), hline);
+ }
+ }
+
+ // Vertical separators
+ if (doc.has_vline_seps())
+ {
+ component_set<L> vline = doc.vline_seps_comps().duplicate();
+ for_all_comps(c, vline)
+ {
+ const mln_box(L)& b_ = vline(c).bbox();
+
+ const bool tl = billboard(b_.pmin());
+ const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+ const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+ const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+ const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+ const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+ const bool br = billboard(b_.pmax());
+
+ // This separator is included in an element (picture, drawing...)
+ // => Ignore it.
+ if (tl && tr && ml && mc && mr && bl && br)
+ vline(c).update_tag(component::Ignored);
+
+ // FIXME: warning this call may produce inconsistent data
+ // Ignored components are still in the separator image...
+ doc.set_vline_separators(doc.vline_seps(), vline);
+ }
+
+ trace::exiting("scribo::filter::separators_in_element");
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_SEPARATORS_IN_ELEMENT_HH
diff --git a/scribo/scribo/filter/separators_in_paragraph.hh b/scribo/scribo/filter/separators_in_paragraph.hh
new file mode 100644
index 0000000..3e7a150
--- /dev/null
+++ b/scribo/scribo/filter/separators_in_paragraph.hh
@@ -0,0 +1,151 @@
+// 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/>.
+//
+// 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_FILTER_SEPARATORS_IN_PARAGRAPHS_HH
+# define SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPH_HH
+
+/// \file
+///
+/// Invalidate false positive separators.
+/// \fixme Share same test canvas as text::merging.
+
+
+# include <mln/core/concept/image.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/document.hh>
+
+
+namespace scribo
+{
+
+ namespace filter
+ {
+
+ using namespace mln;
+
+
+ /// Invalidate false positive separators.
+ ///
+ /// \param[in] separators A paragraph set.
+ ///
+ /// \return A doc with invalidated separators.
+ ///
+ /// Warning: it does not remove separators from separator
+ /// image. It only invalidate separator components in their
+ /// respective component_set.
+ ///
+ template <typename L>
+ void
+ separators_in_paragraph(document<L>& doc);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ void
+ separators_in_paragraph(document<L>& doc)
+ {
+ trace::entering("scribo::filter::separators_in_paragraph");
+
+ mln_precondition(doc.is_valid());
+ mln_precondition(doc.has_elements());
+ mln_precondition(doc.has_hline_seps() || doc.has_vline_seps());
+
+ if ((doc.has_hline_seps() && !doc.hline_seps_comps().nelements())
+ && (doc.has_vline_seps() && !doc.vline_seps_comps().nelements()))
+ return;
+
+ mln_ch_value(L,bool) billboard;
+ initialize(billboard, doc.image());
+ data::fill(billboard, false);
+
+ for_all_comps(p, doc.paragraphs())
+ if (doc.paragraphs()(p).is_valid())
+ mln::draw::box_plain(billboard, doc.paragraphs()(p).bbox(), true);
+
+ // Horizontal separators
+ if (doc.has_hline_seps())
+ {
+ component_set<L> hline = doc.hline_seps_comps().duplicate();
+ for_all_comps(c, hline)
+ {
+ const mln_box(L)& b_ = hline(c).bbox();
+
+ const bool tl = billboard(b_.pmin());
+ const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+ const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+ const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+ const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+ const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+ const bool br = billboard(b_.pmax());
+
+ // This separator is included in an element (picture, drawing...)
+ // => Ignore it.
+ if (tl && tr && ml && mc && mr && bl && br)
+ hline(c).update_tag(component::Ignored);
+
+ // FIXME: warning this call may produce inconsistent data
+ // Ignored components are still in the separator image...
+ doc.set_hline_separators(doc.hline_seps(), hline);
+ }
+ }
+
+ // Vertical separators
+ if (doc.has_vline_seps())
+ {
+ component_set<L> vline = doc.vline_seps_comps().duplicate();
+ for_all_comps(c, vline)
+ {
+ const mln_box(L)& b_ = vline(c).bbox();
+
+ const bool tl = billboard(b_.pmin());
+ const bool tr = billboard.at_(b_.pmin().row(), b_.pmax().col());
+ const bool ml = billboard.at_(b_.pcenter().row(), b_.pmin().col());
+ const bool mc = billboard.at_(b_.pcenter().row(), b_.pcenter().col());
+ const bool mr = billboard.at_(b_.pcenter().row(), b_.pmax().col());
+ const bool bl = billboard.at_(b_.pmax().row(), b_.pmin().col());
+ const bool br = billboard(b_.pmax());
+
+ // This separator is included in an element (picture, drawing...)
+ // => Ignore it.
+ if (tl && tr && ml && mc && mr && bl && br)
+ vline(c).update_tag(component::Ignored);
+
+ // FIXME: warning this call may produce inconsistent data
+ // Ignored components are still in the separator image...
+ doc.set_vline_separators(doc.vline_seps(), vline);
+ }
+
+ trace::exiting("scribo::filter::separators_in_paragraph");
+ }
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::filter
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_FILTER_SEPARATORS_IN_PARAGRAPH_HH
--
1.5.6.5
1
0
* scribo/util/box_intersection.hh: New.
* scribo/filter/object_links_bbox_overlap.hh: Make use of this new
routine.
---
scribo/ChangeLog | 9 +++
scribo/scribo/filter/object_links_bbox_overlap.hh | 25 ++--------
.../util/{color_to_hex.hh => box_intersection.hh} | 53 +++++++++++---------
3 files changed, 43 insertions(+), 44 deletions(-)
copy scribo/scribo/util/{color_to_hex.hh => box_intersection.hh} (56%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 3c70e89..959746f 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,14 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add util::box_intersection.
+
+ * scribo/util/box_intersection.hh: New.
+
+ * scribo/filter/object_links_bbox_overlap.hh: Make use of this new
+ routine.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Various small fixes in Scribo.
* scribo/core/paragraph_info.hh: Add validity information.
diff --git a/scribo/scribo/filter/object_links_bbox_overlap.hh b/scribo/scribo/filter/object_links_bbox_overlap.hh
index a93d849..29b71ba 100644
--- a/scribo/scribo/filter/object_links_bbox_overlap.hh
+++ b/scribo/scribo/filter/object_links_bbox_overlap.hh
@@ -41,6 +41,7 @@
# include <scribo/core/object_links.hh>
# include <scribo/core/component_set.hh>
# include <scribo/filter/object_links_bbox_ratio.hh>
+# include <scribo/util/box_intersection.hh>
namespace scribo
{
@@ -80,32 +81,14 @@ namespace scribo
const component_set<L>& components = links.components();
object_links<L> output = links.duplicate();
- bool has_intersection;
- mln_site(L) pmin, pmax;
float ratio_i, ratio_link_i;
for_all_links(i, links)
if (links.is_linked(i))
{
- has_intersection = true;
- for (unsigned dim = 0; dim < mln_site_(L)::dim; ++dim)
- {
- pmin[dim] = math::max(components(i).bbox().pmin()[dim],
- components(links(i)).bbox().pmin()[dim]);
- pmax[dim] = math::min(components(i).bbox().pmax()[dim],
- components(links(i)).bbox().pmax()[dim]);
-
- if (pmin[dim] > pmax[dim])
- {
- has_intersection = false;
- break;
- }
- }
-
- if (!has_intersection)
- continue;
-
- mln_box(L) interbbox(pmin, pmax);
+ mln_box(L)
+ interbbox = scribo::util::box_intersection(components(i).bbox(),
+ components(links(i)).bbox());
ratio_i = interbbox.nsites() /(float)components(i).bbox().nsites();
ratio_link_i = interbbox.nsites() /(float)components(links(i)).bbox().nsites();
diff --git a/scribo/scribo/util/color_to_hex.hh b/scribo/scribo/util/box_intersection.hh
similarity index 56%
copy from scribo/scribo/util/color_to_hex.hh
copy to scribo/scribo/util/box_intersection.hh
index e0ee33f..f090233 100644
--- a/scribo/scribo/util/color_to_hex.hh
+++ b/scribo/scribo/util/box_intersection.hh
@@ -23,18 +23,17 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_UTIL_COLOR_TO_HEX_HH
-# define SCRIBO_UTIL_COLOR_TO_HEX_HH
+#ifndef SCRIBO_UTIL_BOX_INTERSECTION_HH
+# define SCRIBO_UTIL_BOX_INTERSECTION_HH
/// \file
///
-/// Convert hexadecimal encoded colors to value::rgb8.
+/// Return the box corresponding to the intersection of two boxes.
-#include <cstdio>
-#include <iostream>
-#include <string.h>
-#include <mln/value/rgb8.hh>
+#include <mln/core/site_set/box.hh>
+#include <mln/math/min.hh>
+#include <mln/math/max.hh>
namespace scribo
{
@@ -43,30 +42,38 @@ namespace scribo
{
using namespace mln;
- std::string color_to_hex(const value::rgb8& v);
+ /// \brief Return the box corresponding to the intersection of two
+ /// boxes.
+ ///
+ /// \return An invalid box if there is no intersection. The box
+ /// corresponding to the intersection, otherwise.
+ template <typename P>
+ box<P>
+ box_intersection(const box<P>& lhs, const box<P>& rhs);
# ifndef MLN_INCLUDE_ONLY
- std::string color_to_hex(const value::rgb8& v)
+ template <typename P>
+ box<P>
+ box_intersection(const box<P>& lhs, const box<P>& rhs)
{
- std::string result = "#";
+ trace::entering("scribo::util::box_intersection");
- char buf[3];
+ P pmin, pmax;
+ for (unsigned dim = 0; dim < P::dim; ++dim)
+ {
+ pmin[dim] = math::max(lhs.pmin()[dim], rhs.pmin()[dim]);
+ pmax[dim] = math::min(lhs.pmax()[dim], rhs.pmax()[dim]);
- int c = v.red();
- sprintf(buf, "%.2X", c);
- result.append(buf);
+ if (pmin[dim] > pmax[dim]) // No intersection.
+ return box<P>();
+ }
- c = v.green();
- sprintf(buf, "%.2X", c);
- result.append(buf);
+ box<P> output(pmin, pmax);
- c = v.blue();
- sprintf(buf, "%.2X", c);
- result.append(buf);
-
- return result;
+ trace::exiting("scribo::util::box_intersection");
+ return output;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -75,4 +82,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_UTIL_COLOR_TO_HEX_HH
+#endif // ! SCRIBO_UTIL_BOX_INTERSECTION_HH
--
1.5.6.5
1
0
---
milena/ChangeLog | 4 ++
milena/mln/draw/{box_plain.hh => site_set.hh} | 58 +++++++++++-------------
2 files changed, 31 insertions(+), 31 deletions(-)
copy milena/mln/draw/{box_plain.hh => site_set.hh} (61%)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index e8430cd..8ea11b0 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,7 @@
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ * mln/draw/site_set.hh: new.
+
2011-05-17 Guillaume Lazzara <z(a)lrde.epita.fr>
Add new sample programs.
diff --git a/milena/mln/draw/box_plain.hh b/milena/mln/draw/site_set.hh
similarity index 61%
copy from milena/mln/draw/box_plain.hh
copy to milena/mln/draw/site_set.hh
index ec5b865..1738b16 100644
--- a/milena/mln/draw/box_plain.hh
+++ b/milena/mln/draw/site_set.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -23,23 +23,17 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef MLN_DRAW_BOX_PLAIN_HH
-# define MLN_DRAW_BOX_PLAIN_HH
+#ifndef MLN_DRAW_SITE_SET_HH
+# define MLN_DRAW_SITE_SET_HH
/*! \file
*
- * \brief Draw a plain box in an image.
+ * \brief Draw a site set in an image.
*
- * \fixme Rename as box.hh
*/
# include <mln/core/concept/image.hh>
-# include <mln/core/alias/box2d.hh>
-# include <mln/data/fill.hh>
-# include <mln/draw/line.hh>
-# include <mln/pw/image.hh>
-# include <mln/pw/cst.hh>
-
+# include <mln/core/concept/site_set.hh>
namespace mln
{
@@ -47,39 +41,41 @@ namespace mln
namespace draw
{
- /*! Draw a plain box at value \p v in image \p ima
+ /*! Draw a sites with value \p v in image \p ima
*
* \param[in,out] ima The image to be drawn.
- * \param[in] b the box to draw.
+ * \param[in] b the site set to draw.
* \param[in] v The value to assign to all drawn pixels.
+ * \param[in] output_ratio size ratio between output image and the
+ * image from which the bboxes were calculated.
*
- * \pre \p ima has to be initialized.
- * \pre \p ima has \p beg.
- * \pre \p ima has \p end.
+ * \pre \p s is included in \p ima domain.
*
*/
- template <typename I, typename B>
- void box_plain(Image<I>& ima,
- const Box<B>& b,
- const mln_value(I)& v);
+ template <typename I, typename S>
+ void site_set(Image<I>& ima,
+ const Site_Set<S>& s,
+ const mln_value(I)& v,
+ unsigned output_ratio = 1);
# ifndef MLN_INCLUDE_ONLY
- template <typename I, typename B>
- inline
- void box_plain(Image<I>& ima,
- const Box<B>& b,
- const mln_value(I)& v)
+ template <typename I, typename S>
+ void site_set(Image<I>& ima_,
+ const Site_Set<S>& s_,
+ const mln_value(I)& v,
+ unsigned output_ratio)
{
mln_precondition(exact(ima).is_valid());
+ mln_precondition(exact(ima).domain() >= exact(s));
- mln_psite(I) pmin = exact(b).pmin();
- mln_psite(I) pmax = exact(b).pmax();
-
- mln_precondition(exact(ima).has(pmin) && exact(ima).has(pmax));
+ I& ima = exact(ima_);
+ const S& s = exact(s_);
- data::fill((ima | b).rw(), v);
+ mln_piter(S) p(s);
+ for_all(p)
+ ima(p / output_ratio) = v;
}
# endif // ! MLN_INCLUDE_ONLY
@@ -89,4 +85,4 @@ namespace mln
} // end of namespace mln
-#endif // ! MLN_DRAW_BOX_PLAIN_HH
+#endif // ! MLN_DRAW_SITE_SET_HH
--
1.5.6.5
1
0

26 May '11
* scribo/core/paragraph_info.hh: Add validity information.
* scribo/core/tag/line.hh: Fix guard.
* scribo/debug/line_info_image.hh: Use is_textline().
* scribo/io/xml/internal/extended_page_xml_visitor.hh,
* scribo/io/xml/internal/full_xml_visitor.hh,
* scribo/io/xml/internal/page_xml_visitor.hh: Check paragraph
validity.
* scribo/primitive/extract/alignments.hh,
* scribo/primitive/extract/lines_pattern.hh,
* scribo/primitive/extract/separators_nonvisible.hh,
* scribo/primitive/group/from_double_link_any.hh,
* scribo/text/link_lines.hh,
* scribo/text/paragraphs.hh: Fix namespace ambiguity.
* scribo/text/merging.hh: Add missing SCRIBO_NDEBUG guards.
* src/primitive/extract/lines_h_thick_and_thin.cc: Add a missing
include.
* tests/primitive/extract/Makefile.am: Do not override an existing
variable.
---
scribo/ChangeLog | 30 +++++++
scribo/scribo/core/paragraph_info.hh | 15 +++-
scribo/scribo/core/tag/line.hh | 2 +-
scribo/scribo/debug/line_info_image.hh | 5 +-
.../io/xml/internal/extended_page_xml_visitor.hh | 81 ++++++++++----------
scribo/scribo/io/xml/internal/full_xml_visitor.hh | 79 ++++++++++----------
scribo/scribo/io/xml/internal/page_xml_visitor.hh | 51 ++++++------
scribo/scribo/primitive/extract/alignments.hh | 12 +---
scribo/scribo/primitive/extract/lines_pattern.hh | 2 +-
.../primitive/extract/separators_nonvisible.hh | 6 +-
.../scribo/primitive/group/from_double_link_any.hh | 7 +-
scribo/scribo/text/link_lines.hh | 2 +-
scribo/scribo/text/merging.hh | 37 +++++++--
scribo/scribo/text/paragraphs.hh | 18 ++--
.../primitive/extract/lines_h_thick_and_thin.cc | 1 +
scribo/tests/primitive/extract/Makefile.am | 2 +-
16 files changed, 204 insertions(+), 146 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index c1e1ff8..3c70e89 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,35 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Various small fixes in Scribo.
+
+ * scribo/core/paragraph_info.hh: Add validity information.
+
+ * scribo/core/tag/line.hh: Fix guard.
+
+ * scribo/debug/line_info_image.hh: Use is_textline().
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh,
+ * scribo/io/xml/internal/full_xml_visitor.hh,
+ * scribo/io/xml/internal/page_xml_visitor.hh: Check paragraph
+ validity.
+
+ * scribo/primitive/extract/alignments.hh,
+ * scribo/primitive/extract/lines_pattern.hh,
+ * scribo/primitive/extract/separators_nonvisible.hh,
+ * scribo/primitive/group/from_double_link_any.hh,
+ * scribo/text/link_lines.hh,
+ * scribo/text/paragraphs.hh: Fix namespace ambiguity.
+
+ * scribo/text/merging.hh: Add missing SCRIBO_NDEBUG guards.
+
+ * src/primitive/extract/lines_h_thick_and_thin.cc: Add a missing
+ include.
+
+ * tests/primitive/extract/Makefile.am: Do not override an existing
+ variable.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Introduce paragraph_id_t type.
* scribo/core/paragraph_set.hh: Make use of this new type.
diff --git a/scribo/scribo/core/paragraph_info.hh b/scribo/scribo/core/paragraph_info.hh
index 52068a7..af619dd 100644
--- a/scribo/scribo/core/paragraph_info.hh
+++ b/scribo/scribo/core/paragraph_info.hh
@@ -71,6 +71,7 @@ namespace scribo
void set_color_reliability_(float v);
bool is_valid() const;
+ void invalidate();
bool needs_stats_update() const;
void force_stats_update();
@@ -84,6 +85,7 @@ namespace scribo
float color_reliability_;
bool needs_stats_update_;
+ bool is_valid_;
};
template <typename L>
@@ -97,13 +99,13 @@ namespace scribo
template <typename L>
paragraph_info<L>::paragraph_info()
- : needs_stats_update_(false)
+ : needs_stats_update_(false), is_valid_(false)
{
}
template <typename L>
paragraph_info<L>::paragraph_info(const line_links<L>& llinks)
- : llinks_(llinks), needs_stats_update_(false)
+ : llinks_(llinks), needs_stats_update_(false), is_valid_(true)
{
}
@@ -186,7 +188,14 @@ namespace scribo
bool
paragraph_info<L>::is_valid() const
{
- return llinks_.is_valid();
+ return llinks_.is_valid() && is_valid_;
+ }
+
+ template <typename L>
+ void
+ paragraph_info<L>::invalidate()
+ {
+ is_valid_ = false;
}
template <typename L>
diff --git a/scribo/scribo/core/tag/line.hh b/scribo/scribo/core/tag/line.hh
index 12b3246..d8972a7 100644
--- a/scribo/scribo/core/tag/line.hh
+++ b/scribo/scribo/core/tag/line.hh
@@ -255,4 +255,4 @@ namespace scribo
} // end of namespace scribo
-#endif // ! SCRIBO_CORE_TAG_COMP_HH
+#endif // ! SCRIBO_CORE_TAG_LINE_HH
diff --git a/scribo/scribo/debug/line_info_image.hh b/scribo/scribo/debug/line_info_image.hh
index 1b6532b..f3d7ddf 100644
--- a/scribo/scribo/debug/line_info_image.hh
+++ b/scribo/scribo/debug/line_info_image.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.
//
@@ -70,7 +71,7 @@ namespace scribo
for_all_lines(l, line)
{
- if (! line(l).is_valid() || line(l).is_hidden())
+ if (! line(l).is_textline())
continue;
// Bounding box.
diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
index 2611d4a..d109827 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -255,48 +255,49 @@ namespace scribo
const line_set<L>& lines = parset.lines();
for_all_paragraphs(p, parset)
- {
- const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
- // FIXME: compute that information on the whole paragraph
- // and use them here.
- line_id_t fid = line_ids(0);
- output << " <text_region id=\"" << p
- << "\" txt_orientation=\"" << lines(fid).orientation()
- << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
- << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
- << "\" txt_text_type=\"" << lines(fid).type()
- << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
- << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
- << "\" txt_text_colour=\"" << internal::compute_text_colour(parset(p).color())
- << "\" kerning=\"" << lines(fid).char_space();
-
- // EXTENSIONS - Not officially supported
- // FIXME: add boldness?
- output << "\" color=\"" << scribo::util::color_to_hex(parset(p).color())
- << "\" color_reliability=\"" << parset(p).color_reliability()
- << "\" baseline=\"" << lines(fid).baseline()
- << "\" meanline=\"" << lines(fid).meanline()
- << "\" x_height=\"" << lines(fid).x_height()
- << "\" d_height=\"" << lines(fid).d_height()
- << "\" a_height=\"" << lines(fid).a_height()
- << "\" char_width=\"" << lines(fid).char_width();
- // End of EXTENSIONS
- output << "\">"
- << std::endl;
-
- internal::print_box_coords(output, parset(p).bbox(), " ");
-
- // EXTENSIONS - Not officially supported
- for_all_paragraph_lines(lid, line_ids)
+ if (parset(p).is_valid())
{
- line_id_t l = line_ids(lid);
- lines(l).accept(*this);
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ // FIXME: compute that information on the whole paragraph
+ // and use them here.
+ line_id_t fid = line_ids(0);
+ output << " <text_region id=\"" << p
+ << "\" txt_orientation=\"" << lines(fid).orientation()
+ << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
+ << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
+ << "\" txt_text_type=\"" << lines(fid).type()
+ << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
+ << "\" txt_text_colour=\"" << internal::compute_text_colour(parset(p).color())
+ << "\" kerning=\"" << lines(fid).char_space();
+
+ // EXTENSIONS - Not officially supported
+ // FIXME: add boldness?
+ output << "\" color=\"" << scribo::util::color_to_hex(parset(p).color())
+ << "\" color_reliability=\"" << parset(p).color_reliability()
+ << "\" baseline=\"" << lines(fid).baseline()
+ << "\" meanline=\"" << lines(fid).meanline()
+ << "\" x_height=\"" << lines(fid).x_height()
+ << "\" d_height=\"" << lines(fid).d_height()
+ << "\" a_height=\"" << lines(fid).a_height()
+ << "\" char_width=\"" << lines(fid).char_width();
+ // End of EXTENSIONS
+ output << "\">"
+ << std::endl;
+
+ internal::print_box_coords(output, parset(p).bbox(), " ");
+
+ // EXTENSIONS - Not officially supported
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+ // End of EXTENSIONS
+
+ output << " </text_region>" << std::endl;
}
- // End of EXTENSIONS
-
- output << " </text_region>" << std::endl;
- }
}
diff --git a/scribo/scribo/io/xml/internal/full_xml_visitor.hh b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
index 614c473..c6109ee 100644
--- a/scribo/scribo/io/xml/internal/full_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
@@ -441,48 +441,49 @@ namespace scribo
const line_set<L>& lines = parset.lines();
for_all_paragraphs(p, parset)
- {
- const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
- // FIXME: compute that information on the whole paragraph
- // and use them here.
- line_id_t fid = line_ids(0);
- output << " <text_region id=\"" << p
- << "\" txt_orientation=\"" << lines(fid).orientation()
- << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
- << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
- << "\" txt_text_type=\"" << lines(fid).type()
- << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
- << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
- << "\" txt_text_colour=\"" << internal::compute_text_colour(parset(p).color())
- << "\" kerning=\"" << lines(fid).char_space();
-
- // EXTENSIONS - Not officially supported
- output << "\" baseline=\"" << lines(fid).baseline()
- << "\" meanline=\"" << lines(fid).meanline()
- << "\" x_height=\"" << lines(fid).x_height()
- << "\" d_height=\"" << lines(fid).d_height()
- << "\" a_height=\"" << lines(fid).a_height()
- << "\" char_width=\"" << lines(fid).char_width()
- << "\" color=\"" << scribo::util::color_to_hex(parset(p).color())
- << "\" color_reliability=\"" << parset(p).color_reliability();
- // End of EXTENSIONS
- output << "\">"
- << std::endl;
-
- internal::print_box_coords(output, parset(p).bbox(), " ");
-
-
- // EXTENSIONS - Not officially supported
- for_all_paragraph_lines(lid, line_ids)
+ if (parset(p).is_valid())
{
- line_id_t l = line_ids(lid);
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ // FIXME: compute that information on the whole paragraph
+ // and use them here.
+ line_id_t fid = line_ids(0);
+ output << " <text_region id=\"" << p
+ << "\" txt_orientation=\"" << lines(fid).orientation()
+ << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
+ << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
+ << "\" txt_text_type=\"" << lines(fid).type()
+ << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
+ << "\" txt_text_colour=\"" << internal::compute_text_colour(parset(p).color())
+ << "\" kerning=\"" << lines(fid).char_space();
+
+ // EXTENSIONS - Not officially supported
+ output << "\" baseline=\"" << lines(fid).baseline()
+ << "\" meanline=\"" << lines(fid).meanline()
+ << "\" x_height=\"" << lines(fid).x_height()
+ << "\" d_height=\"" << lines(fid).d_height()
+ << "\" a_height=\"" << lines(fid).a_height()
+ << "\" char_width=\"" << lines(fid).char_width()
+ << "\" color=\"" << scribo::util::color_to_hex(parset(p).color())
+ << "\" color_reliability=\"" << parset(p).color_reliability();
+ // End of EXTENSIONS
+ output << "\">"
+ << std::endl;
+
+ internal::print_box_coords(output, parset(p).bbox(), " ");
+
+
+ // EXTENSIONS - Not officially supported
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
- lines(l).accept(*this);
- }
+ lines(l).accept(*this);
+ }
- output << " </text_region>" << std::endl;
- }
+ output << " </text_region>" << std::endl;
+ }
}
diff --git a/scribo/scribo/io/xml/internal/page_xml_visitor.hh b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
index b807dbb..66ba21f 100644
--- a/scribo/scribo/io/xml/internal/page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
@@ -218,37 +218,38 @@ namespace scribo
const line_set<L>& lines = parset.lines();
for_all_paragraphs(p, parset)
- {
- const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
- // FIXME: compute that information on the whole paragraph
- // and use them here.
- line_id_t fid = line_ids(0);
- output << " <TextRegion id=\"r" << p
- << "\" orientation=\"" << lines(fid).orientation()
- << "\" readingOrientation=\"" << lines(fid).reading_orientation()
- << "\" readingDirection=\"" << lines(fid).reading_direction()
- << "\" type=\"" << ((lines(fid).type() == line::Text) ? "paragraph" : line::type2str(lines(fid).type()))
- << "\" reverseVideo=\"" << (lines(fid).reverse_video() ? "true" : "false")
- << "\" indented=\"" << (lines(fid).indented() ? "true" : "false")
- << "\" kerning=\"" << lines(fid).char_space()
- << "\" textColour=\"" << compute_text_colour(lines(fid).color())
+ if (parset(p).is_valid())
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ // FIXME: compute that information on the whole paragraph
+ // and use them here.
+ line_id_t fid = line_ids(0);
+ output << " <TextRegion id=\"r" << p
+ << "\" orientation=\"" << lines(fid).orientation()
+ << "\" readingOrientation=\"" << lines(fid).reading_orientation()
+ << "\" readingDirection=\"" << lines(fid).reading_direction()
+ << "\" type=\"" << ((lines(fid).type() == line::Text) ? "paragraph" : line::type2str(lines(fid).type()))
+ << "\" reverseVideo=\"" << (lines(fid).reverse_video() ? "true" : "false")
+ << "\" indented=\"" << (lines(fid).indented() ? "true" : "false")
+ << "\" kerning=\"" << lines(fid).char_space()
+ << "\" textColour=\"" << compute_text_colour(lines(fid).color())
// << "\" bgColour=\"" << compute_text_color(lines(fid).bgcolor())
// << "\" fontSize=\"" << compute_text_color(lines(fid).x_height())
// << "\" leading=\"" << compute_text_color(lines(fid).leading())
- << "\">"
- << std::endl;
+ << "\">"
+ << std::endl;
- // Add support for text recognition
- // <TextEquiv>
- // <PlainText></PlainText>
- // <Unicode></Unicode>
- // </TextEquiv>
+ // Add support for text recognition
+ // <TextEquiv>
+ // <PlainText></PlainText>
+ // <Unicode></Unicode>
+ // </TextEquiv>
- internal::print_box_coords(output, parset(p).bbox(), " ");
+ internal::print_box_coords(output, parset(p).bbox(), " ");
- output << " </TextRegion>" << std::endl;
- }
+ output << " </TextRegion>" << std::endl;
+ }
}
diff --git a/scribo/scribo/primitive/extract/alignments.hh b/scribo/scribo/primitive/extract/alignments.hh
index 7dbf683..b2c7c0c 100644
--- a/scribo/scribo/primitive/extract/alignments.hh
+++ b/scribo/scribo/primitive/extract/alignments.hh
@@ -43,8 +43,6 @@
# include <mln/io/pbm/load.hh>
-# include <mln/labeling/colorize.hh>
-
# include <mln/util/couple.hh>
# include <scribo/core/def/lbl_type.hh>
@@ -61,7 +59,6 @@
# include <scribo/debug/usage.hh>
# include <scribo/debug/links_image.hh>
-
# include <scribo/core/document.hh>
# include <scribo/core/component_set.hh>
# include <scribo/core/line_set.hh>
@@ -76,11 +73,6 @@
# include <scribo/preprocessing/rotate_90.hh>
# include <scribo/filter/object_links_bbox_h_ratio.hh>
-# include <scribo/primitive/extract/separators.hh>
-# include <scribo/primitive/extract/vertical_separators.hh>
-# include <scribo/primitive/extract/horizontal_separators.hh>
-# include <scribo/primitive/extract/separators_nonvisible.hh>
-
namespace scribo
{
@@ -710,7 +702,7 @@ namespace scribo
// 2.1.2. Check TOP whitespaces
{
- util::array<accu::shape::bbox<point2d> >
+ mln::util::array<accu::shape::bbox<point2d> >
group_bbox(top_groups.nelements());
// Compute group bboxes
@@ -941,7 +933,7 @@ namespace scribo
// 2.2.2. Check BOTTOM whitespaces
{
- util::array<accu::shape::bbox<point2d> >
+ mln::util::array<accu::shape::bbox<point2d> >
group_bbox(bot_groups.nelements());
// Compute group bboxes
diff --git a/scribo/scribo/primitive/extract/lines_pattern.hh b/scribo/scribo/primitive/extract/lines_pattern.hh
index 85bdbe4..ec24d4f 100644
--- a/scribo/scribo/primitive/extract/lines_pattern.hh
+++ b/scribo/scribo/primitive/extract/lines_pattern.hh
@@ -166,7 +166,7 @@ namespace scribo
mln_concrete(I) output;
initialize(output, input);
- util::array<int>
+ mln::util::array<int>
q_arr = offsets_wrt(output, win);
bool is_foreground;
diff --git a/scribo/scribo/primitive/extract/separators_nonvisible.hh b/scribo/scribo/primitive/extract/separators_nonvisible.hh
index 5c26285..3f36880 100644
--- a/scribo/scribo/primitive/extract/separators_nonvisible.hh
+++ b/scribo/scribo/primitive/extract/separators_nonvisible.hh
@@ -124,8 +124,8 @@ namespace scribo
max_angle = 5,
min_card = 3;
- util::timer t;
- util::timer gt;
+ mln::util::timer t;
+ mln::util::timer gt;
gt.start();
@@ -395,7 +395,7 @@ namespace scribo
t.restart();
- util::array<bool> relbl(unsigned(nlabels) + 1, true);
+ mln::util::array<bool> relbl(unsigned(nlabels) + 1, true);
relbl(0) = false;
unsigned invalid_ratio = unsigned(length * 0.30f);
diff --git a/scribo/scribo/primitive/group/from_double_link_any.hh b/scribo/scribo/primitive/group/from_double_link_any.hh
index 7ed15e2..9e315a3 100644
--- a/scribo/scribo/primitive/group/from_double_link_any.hh
+++ b/scribo/scribo/primitive/group/from_double_link_any.hh
@@ -79,7 +79,7 @@ namespace scribo
{
template <typename L>
- util::array<unsigned> make_parent(const object_links<L>& link)
+ mln::util::array<unsigned> make_parent(const object_links<L>& link)
{
mln::util::array<unsigned> parent = link.comp_to_link();
for_all_links(l, link)
@@ -102,8 +102,9 @@ namespace scribo
object_links<L> merged_link(left_link.components());
merged_link.init();
- util::array<unsigned> lparent = internal::make_parent(left_link);
- util::array<unsigned> rparent = internal::make_parent(right_link);
+ mln::util::array<unsigned>
+ lparent = internal::make_parent(left_link),
+ rparent = internal::make_parent(right_link);
for_all_links(i, merged_link)
{
diff --git a/scribo/scribo/text/link_lines.hh b/scribo/scribo/text/link_lines.hh
index 6c985f5..4eab43d 100644
--- a/scribo/scribo/text/link_lines.hh
+++ b/scribo/scribo/text/link_lines.hh
@@ -72,7 +72,7 @@ namespace scribo
mln::data::fill(blocks, literal::zero);
// Construct a list of rotated bboxes for each lines.
- util::array<mln_box(L)> rbbox(1);
+ mln::util::array<mln_box(L)> rbbox(1);
rbbox.reserve(lines.nelements());
for_all_lines(l, lines)
diff --git a/scribo/scribo/text/merging.hh b/scribo/scribo/text/merging.hh
index 2763882..f1135ed 100644
--- a/scribo/scribo/text/merging.hh
+++ b/scribo/scribo/text/merging.hh
@@ -181,10 +181,7 @@ namespace scribo
l1 = my_find_root(parent, l1);
l2 = my_find_root(parent, l2);
if (l1 == l2)
- {
- std::cerr << "what! in'do_union': already merged!!!" << std::endl;
- return l1;
- }
+ return l1;
swap_ordering(l1, l2);
parent[l2] = l1; // The smallest label value is root.
@@ -625,8 +622,10 @@ namespace scribo
image2d<unsigned> billboard(domain);
data::fill(billboard, 0);
+# ifndef SCRIBO_NDEBUG
image2d<value::int_u8> log(domain);
data::fill(log, 0);
+# endif // ! SCRIBO_NDEBUG
const unsigned n = v.size();
unsigned l_;
@@ -765,9 +764,10 @@ namespace scribo
// l_ = do_union(lines, mc, l, parent);
// draw_box(billboard, lines(l_).ebbox(), l_);
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 126);
-
+# endif // ! SCRIBO_NDEBUG
}
else // FIXME: Remove! since included in a non-text-line, so not drawn, so inclusion impossible!!!!!!!!!!
@@ -777,8 +777,11 @@ namespace scribo
// a non-text-line (probably a drawing or a frame) includes a text line
draw_box(billboard, lines(l).ebbox(), l);
+
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 100);
+# endif // ! SCRIBO_NDEBUG
}
}
@@ -817,8 +820,10 @@ namespace scribo
// it may change of label (take the one of the included line).
draw_box(billboard, lines(l_).ebbox(), l_);
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 128);
+# endif // ! SCRIBO_NDEBUG
}
}
}
@@ -831,11 +836,15 @@ namespace scribo
{
++count_new_txtline;
draw_box(billboard, lines(l).ebbox(), l);
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 127);
+# endif // ! SCRIBO_NDEBUG
}
+# ifndef SCRIBO_NDEBUG
else
- draw_box(log, b, 1);
+ draw_box(log, b, 1);
+# endif // ! SCRIBO_NDEBUG
}
}
else
@@ -852,8 +861,8 @@ namespace scribo
if (lcand == 0) // Skip background.
continue;
- if (lines(lcand).type() != line::Text)
- std::cerr << "again!" << std::endl;
+ // if (lines(lcand).type() != line::Text)
+ // std::cerr << "again!" << std::endl;
if (lines(l_).type() == line::Text)
@@ -865,15 +874,22 @@ namespace scribo
l_ = do_union(lines, l_, lcand, parent);
draw_box(billboard, lines(l_).ebbox(), l_);
+
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 151);
+# endif // ! SCRIBO_NDEBUG
+
continue;
}
else
{
++count_WTF;
+
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 255);
+# endif // ! SCRIBO_NDEBUG
// (*) SEE BELOW
draw_box(billboard, lines(l_).ebbox(), l_);
@@ -890,15 +906,20 @@ namespace scribo
l_ = do_union(lines, l_, lcand, parent);
draw_box(billboard, lines(l_).ebbox(), l_);
+# ifndef SCRIBO_NDEBUG
// Log:
draw_box(log, b, 169);
+# endif // ! SCRIBO_NDEBUG
+
continue;
}
+# ifndef SCRIBO_NDEBUG
else
{
// Log:
draw_box(log, b, 254);
}
+# endif // ! SCRIBO_NDEBUG
}
diff --git a/scribo/scribo/text/paragraphs.hh b/scribo/scribo/text/paragraphs.hh
index af01581..37817af 100644
--- a/scribo/scribo/text/paragraphs.hh
+++ b/scribo/scribo/text/paragraphs.hh
@@ -864,7 +864,7 @@ namespace scribo
void prepare_lines(const box2d& domain,
const line_set<L>& lines,
L& blocks,
- util::array<box2d>& rbbox)
+ mln::util::array<box2d>& rbbox)
{
std::map< int, std::vector< const box2d* > > drawn_lines;
// const unsigned nlines = lines.nelements();
@@ -989,7 +989,7 @@ namespace scribo
inline
void
process_left_link(L& blocks,
- const util::array<box2d>& rbbox,
+ const mln::util::array<box2d>& rbbox,
const line_set<L>& lines,
line_links<L>& left)
{
@@ -1133,7 +1133,7 @@ namespace scribo
inline
void
process_right_link(L& blocks,
- const util::array<box2d>& rbbox,
+ const mln::util::array<box2d>& rbbox,
const line_set<L>& lines,
line_links<L>& right)
{
@@ -1328,7 +1328,7 @@ namespace scribo
// }
/// const unsigned nlines = lines_info.nelemnts();
- util::array<box2d> rbbox;
+ mln::util::array<box2d> rbbox;
line_links<L> left(lines);
left(0) = 0;
line_links<L> right(lines);
@@ -1338,18 +1338,18 @@ namespace scribo
rbbox.resize(lines.nelements() + 1);
- std::cout << "Preparing lines" << std::endl;
+// std::cout << "Preparing lines" << std::endl;
prepare_lines(input.domain(), lines , blocks, rbbox);
// io::pgm::save(blocks, "blocks.pgm");
- std::cout << "Linking left" << std::endl;
+// std::cout << "Linking left" << std::endl;
process_left_link(blocks, rbbox, lines , left);
- std::cout << "Linking right" << std::endl;
+// std::cout << "Linking right" << std::endl;
process_right_link(blocks, rbbox, lines , right);
- std::cout << "Finalizing links" << std::endl;
+// std::cout << "Finalizing links" << std::endl;
finalize_links(left, right, lines );
// std::cout << "Finalizing merging" << std::endl;
// finalize_line_merging(left, right, lines);
- std::cout << "Extracting paragraphs" << std::endl;
+// std::cout << "Extracting paragraphs" << std::endl;
filter::paragraph_links(left, right, output, lines);
paragraph_set<L> par_set = make::paragraph(output);
diff --git a/scribo/src/primitive/extract/lines_h_thick_and_thin.cc b/scribo/src/primitive/extract/lines_h_thick_and_thin.cc
index 2942002..1161f2a 100644
--- a/scribo/src/primitive/extract/lines_h_thick_and_thin.cc
+++ b/scribo/src/primitive/extract/lines_h_thick_and_thin.cc
@@ -25,6 +25,7 @@
#include <scribo/primitive/extract/lines_h_thick_and_thin.hh>
+#include <scribo/debug/usage.hh>
const char *args_desc[][2] =
{
diff --git a/scribo/tests/primitive/extract/Makefile.am b/scribo/tests/primitive/extract/Makefile.am
index 33d3a96..b622b15 100644
--- a/scribo/tests/primitive/extract/Makefile.am
+++ b/scribo/tests/primitive/extract/Makefile.am
@@ -26,7 +26,7 @@ check_PROGRAMS =
if HAVE_MAGICKXX
-check_PROGRAMS = alignments
+check_PROGRAMS += alignments
alignments_SOURCES = alignments.cc
alignments_CPPFLAGS = $(AM_CPPFLAGS) \
$(MAGICKXX_CPPFLAGS) \
--
1.5.6.5
1
0

26 May '11
* scribo/core/paragraph_set.hh: Make use of this new type.
* scribo/core/tag/paragraph.hh: New.
---
scribo/ChangeLog | 8 +++
scribo/scribo/core/paragraph_set.hh | 49 +++++++++++++++++---
.../core/{def/color_type.hh => tag/paragraph.hh} | 19 +++-----
3 files changed, 57 insertions(+), 19 deletions(-)
copy scribo/scribo/core/{def/color_type.hh => tag/paragraph.hh} (83%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 5340656..c1e1ff8 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,13 @@
2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Introduce paragraph_id_t type.
+
+ * scribo/core/paragraph_set.hh: Make use of this new type.
+
+ * scribo/core/tag/paragraph.hh: New.
+
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Share document structure data.
* scribo/core/document.hh: Here.
diff --git a/scribo/scribo/core/paragraph_set.hh b/scribo/scribo/core/paragraph_set.hh
index 242501d..65e17c6 100644
--- a/scribo/scribo/core/paragraph_set.hh
+++ b/scribo/scribo/core/paragraph_set.hh
@@ -29,15 +29,19 @@
# include <mln/util/array.hh>
# include <mln/make/relabelfun.hh>
# include <mln/value/int_u16.hh>
+# include <mln/core/concept/function.hh>
# include <scribo/core/line_links.hh>
# include <scribo/core/line_set.hh>
# include <scribo/core/paragraph_info.hh>
# include <scribo/core/concept/serializable.hh>
+# include <scribo/core/tag/paragraph.hh>
namespace scribo
{
+ typedef mln::util::object_id<scribo::ParagraphId, unsigned> paragraph_id_t;
+
namespace internal
{
@@ -56,7 +60,6 @@ namespace scribo
} // end of namespace scribo::internal
-
/*! \brief Paragraph container.
Paragraph ids start from 1.
@@ -65,6 +68,8 @@ namespace scribo
template <typename L>
class paragraph_set : public Serializable<paragraph_set<L> >
{
+ typedef internal::paragraph_set_data<L> data_t;
+
public:
paragraph_set();
paragraph_set(internal::paragraph_set_data<L>* data);
@@ -72,15 +77,21 @@ namespace scribo
unsigned nelements() const;
- paragraph_info<L>& operator()(unsigned i);
- const paragraph_info<L>& operator()(unsigned i) const;
+ paragraph_info<L>& operator()(const paragraph_id_t& i);
+ const paragraph_info<L>& operator()(const paragraph_id_t& i) const;
bool is_valid() const;
+ // Massively invalidate paragraphs.
+ template <typename F>
+ void invalidate(const Function_v2b<F>& f);
+
const line_set<L>& lines() const;
const line_links<L>& links() const;
+ paragraph_set<L> duplicate() const;
+
private:
mln::util::tracked_ptr< internal::paragraph_set_data<L> > data_;
};
@@ -161,7 +172,7 @@ namespace scribo
template <typename L>
paragraph_info<L>&
- paragraph_set<L>::operator()(unsigned i)
+ paragraph_set<L>::operator()(const paragraph_id_t& i)
{
mln_precondition(data_ != 0);
return data_->pars_[i];
@@ -169,7 +180,7 @@ namespace scribo
template <typename L>
const paragraph_info<L>&
- paragraph_set<L>::operator()(unsigned i) const
+ paragraph_set<L>::operator()(const paragraph_id_t& i) const
{
mln_precondition(data_ != 0);
return data_->pars_[i];
@@ -183,6 +194,17 @@ namespace scribo
return data_ && !data_->pars_.is_empty();
}
+ template <typename L>
+ template <typename F>
+ void
+ paragraph_set<L>::invalidate(const Function_v2b<F>& f_)
+ {
+ const F& f = exact(f_);
+
+ for_all_paragraphs(p, (*this))
+ if (!f(p))
+ (*this)(p).invalidate();
+ }
template <typename L>
const line_set<L>&
@@ -203,6 +225,19 @@ namespace scribo
template <typename L>
+ inline
+ paragraph_set<L>
+ paragraph_set<L>::duplicate() const
+ {
+ paragraph_set<L> output;
+ output.data_ = new data_t();
+
+ *(output.data_.ptr_) = *(data_.ptr_);
+ return output;
+ }
+
+
+ template <typename L>
bool operator==(const paragraph_set<L>& lhs, const paragraph_set<L>& rhs)
{
if (! (lhs.lines() == rhs.lines() && lhs.nelements() == rhs.nelements()))
@@ -248,8 +283,8 @@ namespace scribo
{
line_links<L> links = llinks.duplicate();
- for (unsigned i = 1; i < links.nelements(); ++i)
- links(i) = internal::find_root(links, i);
+ for_all_links(l, links)
+ links(l) = internal::find_root(links, l);
unsigned npars;
mln::fun::i2v::array<unsigned>
diff --git a/scribo/scribo/core/def/color_type.hh b/scribo/scribo/core/tag/paragraph.hh
similarity index 83%
copy from scribo/scribo/core/def/color_type.hh
copy to scribo/scribo/core/tag/paragraph.hh
index 7acd334..14dd579 100644
--- a/scribo/scribo/core/def/color_type.hh
+++ b/scribo/scribo/core/tag/paragraph.hh
@@ -23,26 +23,21 @@
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.
-#ifndef SCRIBO_CORE_COLOR_TYPE_HH
-# define SCRIBO_CORE_COLOR_TYPE_HH
+#ifndef SCRIBO_CORE_TAG_PARAGRAPH_HH
+# define SCRIBO_CORE_TAG_PARAGRAPH_HH
/// \file
///
-/// Global type definition for labels.
-
-# include <mln/value/rgb8.hh>
-
+/// \brief Paragraph tags.
namespace scribo
{
- namespace def
- {
+ // Paragraph id tag.
+ struct ParagraphId;
- typedef mln::value::rgb8 color_type;
-
- } // end of namespace scribo::def
} // end of namespace scribo
-#endif // ! SCRIBO_CORE_DEF_HH
+
+#endif // ! SCRIBO_CORE_TAG_PARAGRAPH_HH
--
1.5.6.5
1
0

26 May '11
* scribo/core/document.hh: Here.
---
scribo/ChangeLog | 6 ++
scribo/scribo/core/document.hh | 171 +++++++++++++++++++++++++--------------
2 files changed, 115 insertions(+), 62 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 4fc8c54..5340656 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,9 @@
+2011-05-26 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Share document structure data.
+
+ * scribo/core/document.hh: Here.
+
2011-05-25 Coddy Levi <levi(a)lrde.epita.fr>
Deep modifications and clean correction of the previous bug.
diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh
index 98c438d..cc885e4 100644
--- a/scribo/scribo/core/document.hh
+++ b/scribo/scribo/core/document.hh
@@ -47,9 +47,44 @@
namespace scribo
{
+ namespace internal
+ {
+ /// Data structure for \c scribo::document<L>.
+ template <typename L>
+ struct document_data
+ {
+ document_data();
+ document_data(const char *filename);
+ document_data(const char *filename,
+ const mln::image2d<mln::value::rgb8>& input);
+
+ std::string filename_;
+ mln::image2d<mln::value::rgb8> image_;
+ mln::image2d<bool> binary_image_;
+ mln::image2d<bool> binary_image_wo_seps_;
+
+ paragraph_set<L> parset_;
+ component_set<L> elements_;
+
+ mln::image2d<bool> whitespace_seps_;
+ component_set<L> whitespace_seps_comps_;
+
+ mln::image2d<bool> hline_seps_;
+ component_set<L> hline_seps_comps_;
+
+ mln::image2d<bool> vline_seps_;
+ component_set<L> vline_seps_comps_;
+ };
+
+ } // end of namespace scribo::internal
+
+
+
template <typename L>
struct document : public Serializable<document<L> >
{
+ typedef internal::document_data<L> data_t;
+
public:
document();
@@ -121,22 +156,7 @@ namespace scribo
private:
- std::string filename_;
- mln::image2d<mln::value::rgb8> image_;
- mln::image2d<bool> binary_image_;
- mln::image2d<bool> binary_image_wo_seps_;
-
- paragraph_set<L> parset_;
- component_set<L> elements_;
-
- mln::image2d<bool> whitespace_seps_;
- component_set<L> whitespace_seps_comps_;
-
- mln::image2d<bool> hline_seps_;
- component_set<L> hline_seps_comps_;
-
- mln::image2d<bool> vline_seps_;
- component_set<L> vline_seps_comps_;
+ mln::util::tracked_ptr<data_t> data_;
};
@@ -146,6 +166,32 @@ namespace scribo
# ifndef MLN_INCLUDE_ONLY
+ namespace internal
+ {
+
+ template <typename L>
+ document_data<L>::document_data()
+ {
+ }
+
+ template <typename L>
+ document_data<L>::document_data(const char *filename,
+ const mln::image2d<mln::value::rgb8>& input)
+ : filename_(filename),
+ image_(input)
+ {
+ }
+
+ template <typename L>
+ document_data<L>::document_data(const char *filename)
+ : filename_(filename)
+ {
+ }
+
+
+ } // end of namespace scribo::internal
+
+
template <typename L>
document<L>::document()
@@ -155,17 +201,16 @@ namespace scribo
template <typename L>
document<L>::document(const char *filename)
- : filename_(filename)
{
+ data_ = new internal::document_data<L>(filename);
}
template <typename L>
document<L>::document(const char *filename,
const mln::image2d<mln::value::rgb8>& input)
- : filename_(filename),
- image_(input)
{
+ data_ = new internal::document_data<L>(filename, input);
}
@@ -173,7 +218,7 @@ namespace scribo
const char *
document<L>::filename() const
{
- return filename_.c_str();
+ return data_->filename_.c_str();
}
@@ -181,7 +226,7 @@ namespace scribo
void
document<L>::set_filename(const char *filename)
{
- filename_ = filename;
+ data_->filename_ = filename;
}
@@ -190,7 +235,7 @@ namespace scribo
document<L>::open()
{
Magick::InitializeMagick(0);
- mln::io::magick::load(image_, filename_);
+ mln::io::magick::load(data_->image_, data_->filename_);
}
@@ -198,7 +243,7 @@ namespace scribo
bool
document<L>::is_open() const
{
- return image_.is_valid();
+ return data_->image_.is_valid();
}
@@ -206,7 +251,7 @@ namespace scribo
bool
document<L>::is_valid() const
{
- return image_.is_valid();
+ return data_->image_.is_valid();
}
@@ -214,7 +259,7 @@ namespace scribo
mln::def::coord
document<L>::width() const
{
- return image_.ncols();
+ return data_->image_.ncols();
}
@@ -222,7 +267,7 @@ namespace scribo
mln::def::coord
document<L>::height() const
{
- return image_.nrows();
+ return data_->image_.nrows();
}
@@ -230,7 +275,7 @@ namespace scribo
bool
document<L>::has_text() const
{
- return parset_.is_valid();
+ return data_->parset_.is_valid();
}
@@ -238,14 +283,14 @@ namespace scribo
const line_set<L>&
document<L>::lines() const
{
- return parset_.lines();
+ return data_->parset_.lines();
}
template <typename L>
const paragraph_set<L>&
document<L>::paragraphs() const
{
- return parset_;
+ return data_->parset_;
}
@@ -253,7 +298,7 @@ namespace scribo
void
document<L>::set_paragraphs(const paragraph_set<L>& parset)
{
- parset_ = parset;
+ data_->parset_ = parset;
}
@@ -261,7 +306,7 @@ namespace scribo
const component_set<L>&
document<L>::elements() const
{
- return elements_;
+ return data_->elements_;
}
@@ -269,7 +314,7 @@ namespace scribo
bool
document<L>::has_elements() const
{
- return elements_.is_valid();
+ return data_->elements_.is_valid();
}
@@ -277,14 +322,14 @@ namespace scribo
void
document<L>::set_elements(const component_set<L>& elements)
{
- elements_ = elements;
+ data_->elements_ = elements;
}
template <typename L>
bool
document<L>::has_whitespace_seps() const
{
- return whitespace_seps_.is_valid();
+ return data_->whitespace_seps_.is_valid();
}
@@ -292,7 +337,7 @@ namespace scribo
const mln::image2d<bool>&
document<L>::whitespace_seps() const
{
- return whitespace_seps_;
+ return data_->whitespace_seps_;
}
@@ -300,7 +345,7 @@ namespace scribo
const component_set<L>&
document<L>::whitespace_seps_comps() const
{
- return whitespace_seps_comps_;
+ return data_->whitespace_seps_comps_;
}
@@ -309,8 +354,8 @@ namespace scribo
document<L>::set_whitespace_separators(const image2d<bool>& whitespace_seps,
const component_set<L>& whitespace_seps_comps)
{
- whitespace_seps_ = whitespace_seps;
- whitespace_seps_comps_ = whitespace_seps_comps;
+ data_->whitespace_seps_ = whitespace_seps;
+ data_->whitespace_seps_comps_ = whitespace_seps_comps;
}
@@ -318,7 +363,7 @@ namespace scribo
bool
document<L>::has_hline_seps() const
{
- return hline_seps_.is_valid();
+ return data_->hline_seps_.is_valid();
}
@@ -326,7 +371,7 @@ namespace scribo
const mln::image2d<bool>&
document<L>::hline_seps() const
{
- return hline_seps_;
+ return data_->hline_seps_;
}
@@ -334,7 +379,7 @@ namespace scribo
const component_set<L>&
document<L>::hline_seps_comps() const
{
- return hline_seps_comps_;
+ return data_->hline_seps_comps_;
}
@@ -342,12 +387,13 @@ namespace scribo
void
document<L>::set_hline_separators(const image2d<bool>& hline_seps)
{
- hline_seps_ = hline_seps;
+ data_->hline_seps_ = hline_seps;
mln_value(L) ncomps;
- hline_seps_comps_ = primitive::extract::components(hline_seps,
- mln::c8(), ncomps,
- component::HorizontalLineSeparator);
+ data_->hline_seps_comps_ = primitive::extract::components(
+ hline_seps,
+ mln::c8(), ncomps,
+ component::HorizontalLineSeparator);
}
@@ -356,8 +402,8 @@ namespace scribo
document<L>::set_hline_separators(const image2d<bool>& hline_seps,
const component_set<L>& hline_seps_comps)
{
- hline_seps_ = hline_seps;
- hline_seps_comps_ = hline_seps_comps;
+ data_->hline_seps_ = hline_seps;
+ data_->hline_seps_comps_ = hline_seps_comps;
}
@@ -365,7 +411,7 @@ namespace scribo
bool
document<L>::has_vline_seps() const
{
- return vline_seps_.is_valid();
+ return data_->vline_seps_.is_valid();
}
@@ -373,7 +419,7 @@ namespace scribo
const mln::image2d<bool>&
document<L>::vline_seps() const
{
- return vline_seps_;
+ return data_->vline_seps_;
}
@@ -381,7 +427,7 @@ namespace scribo
const component_set<L>&
document<L>::vline_seps_comps() const
{
- return vline_seps_comps_;
+ return data_->vline_seps_comps_;
}
@@ -389,12 +435,13 @@ namespace scribo
void
document<L>::set_vline_separators(const image2d<bool>& vline_seps)
{
- vline_seps_ = vline_seps;
+ data_->vline_seps_ = vline_seps;
mln_value(L) ncomps;
- vline_seps_comps_ = primitive::extract::components(vline_seps,
- mln::c8(), ncomps,
- component::VerticalLineSeparator);
+ data_->vline_seps_comps_ = primitive::extract::components(
+ vline_seps,
+ mln::c8(), ncomps,
+ component::VerticalLineSeparator);
}
@@ -403,8 +450,8 @@ namespace scribo
document<L>::set_vline_separators(const image2d<bool>& vline_seps,
const component_set<L>& vline_seps_comps)
{
- vline_seps_ = vline_seps;
- vline_seps_comps_ = vline_seps_comps;
+ data_->vline_seps_ = vline_seps;
+ data_->vline_seps_comps_ = vline_seps_comps;
}
@@ -412,7 +459,7 @@ namespace scribo
const mln::image2d<value::rgb8>&
document<L>::image() const
{
- return image_;
+ return data_->image_;
}
@@ -420,7 +467,7 @@ namespace scribo
void
document<L>::set_image(const mln::image2d<value::rgb8>& image)
{
- image_ = image;
+ data_->image_ = image;
}
@@ -428,7 +475,7 @@ namespace scribo
const mln::image2d<bool>&
document<L>::binary_image() const
{
- return binary_image_;
+ return data_->binary_image_;
}
@@ -436,7 +483,7 @@ namespace scribo
void
document<L>::set_binary_image(const mln::image2d<bool>& binary_image)
{
- binary_image_ = binary_image;
+ data_->binary_image_ = binary_image;
}
@@ -444,7 +491,7 @@ namespace scribo
const mln::image2d<bool>&
document<L>::binary_image_wo_seps() const
{
- return binary_image_wo_seps_;
+ return data_->binary_image_wo_seps_;
}
@@ -453,7 +500,7 @@ namespace scribo
document<L>::set_binary_image_wo_seps(
const mln::image2d<bool>& binary_image_wo_seps)
{
- binary_image_wo_seps_ = binary_image_wo_seps;
+ data_->binary_image_wo_seps_ = binary_image_wo_seps;
}
--
1.5.6.5
1
0

25 May '11
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Olena, a generic and efficient image processing platform".
The branch icdar/hdlac2011 has been updated
via 118f203ff8c90a367f78502c3b5ecc1883180f86 (commit)
from 12da563c7ea1fba00e47b8cdb9adf526421218d2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
118f203 2011-05-25 Coddy Levi <levi(a)lrde.epita.fr>
-----------------------------------------------------------------------
Summary of changes:
scribo/ChangeLog | 6 +
scribo/scribo/util/component_outline.hh | 190 +++++++++++++++----------------
2 files changed, 99 insertions(+), 97 deletions(-)
hooks/post-receive
--
Olena, a generic and efficient image processing platform
1
0