Olena-patches
Threads by month
- ----- 2025 -----
- 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
- 9625 discussions

last-svn-commit-864-g1027cb2 scribo/text/paragraphs.hh: Remove unused argument.
by Guillaume Lazzara 06 May '11
by Guillaume Lazzara 06 May '11
06 May '11
---
scribo/ChangeLog | 4 ++++
scribo/scribo/text/paragraphs.hh | 5 ++---
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index b7e0f5a..2fb884b 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,9 @@
2011-05-06 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+ * scribo/text/paragraphs.hh: Remove unused argument.
+
+2011-05-06 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
Fix namespace ambiguities.
* scribo/binarization/internal/first_pass_functor.hh,
diff --git a/scribo/scribo/text/paragraphs.hh b/scribo/scribo/text/paragraphs.hh
index 94e5751..6c9285b 100644
--- a/scribo/scribo/text/paragraphs.hh
+++ b/scribo/scribo/text/paragraphs.hh
@@ -64,8 +64,7 @@ namespace scribo
void paragraph_links(const line_links<L>& left,
const line_links<L>& right,
line_links<L>& output,
- const line_set<L>& lines,
- const image2d<bool>& input)
+ const line_set<L>& lines)
{
output = left.duplicate();
@@ -1039,7 +1038,7 @@ namespace scribo
// std::cout << "Finalizing merging" << std::endl;
// finalize_line_merging(left, right, lines);
std::cout << "Extracting paragraphs" << std::endl;
- filter::paragraph_links(left, right, output, lines, input);
+ filter::paragraph_links(left, right, output, lines);
paragraph_set<L> par_set = make::paragraph(output);
return par_set;
--
1.5.6.5
1
0
* scribo/binarization/internal/first_pass_functor.hh,
* scribo/binarization/sauvola_ms.hh,
* scribo/canvas/integral_browsing.hh,
* scribo/convert/to_base64.hh,
* scribo/preprocessing/denoise_bg.hh: Here.
---
scribo/ChangeLog | 10 ++++++++
.../binarization/internal/first_pass_functor.hh | 6 ++--
scribo/scribo/binarization/sauvola_ms.hh | 24 ++++++++++----------
scribo/scribo/canvas/integral_browsing.hh | 10 ++++----
scribo/scribo/convert/to_base64.hh | 4 +-
scribo/scribo/preprocessing/denoise_bg.hh | 5 ++-
6 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index d3a1780..b7e0f5a 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
2011-05-06 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+ Fix namespace ambiguities.
+
+ * scribo/binarization/internal/first_pass_functor.hh,
+ * scribo/binarization/sauvola_ms.hh,
+ * scribo/canvas/integral_browsing.hh,
+ * scribo/convert/to_base64.hh,
+ * scribo/preprocessing/denoise_bg.hh: Here.
+
+2011-05-06 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
Improve PDF output.
* demo/xml2doc/image_crop.cc: Cleanup temporary files.
diff --git a/scribo/scribo/binarization/internal/first_pass_functor.hh b/scribo/scribo/binarization/internal/first_pass_functor.hh
index fb52be5..0b1a7ac 100644
--- a/scribo/scribo/binarization/internal/first_pass_functor.hh
+++ b/scribo/scribo/binarization/internal/first_pass_functor.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -64,7 +64,7 @@ namespace scribo
image2d<value::int_u8> t_sub;
unsigned n_nbhs;
- util::array<int> dp;
+ mln::util::array<int> dp;
double K_;
diff --git a/scribo/scribo/binarization/sauvola_ms.hh b/scribo/scribo/binarization/sauvola_ms.hh
index e8eb2c2..c1a3414 100644
--- a/scribo/scribo/binarization/sauvola_ms.hh
+++ b/scribo/scribo/binarization/sauvola_ms.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -138,7 +138,7 @@ namespace scribo
unsigned lambda_min, unsigned lambda_max,
unsigned s,
unsigned q, unsigned i, unsigned w,
- const image2d<util::couple<double,double> >& integral_sum_sum_2,
+ const image2d<mln::util::couple<double,double> >& integral_sum_sum_2,
double K)
{
typedef image2d<int_u8> I;
@@ -188,7 +188,7 @@ namespace scribo
// 2nd pass
{
- util::array<mln_value_(I) *> ptr(ratio);
+ mln::util::array<mln_value_(I) *> ptr(ratio);
unsigned nrows = geom::nrows(e_2);
mln_box_runend_piter_(I) sp(sub.domain()); // Backward.
@@ -272,7 +272,7 @@ namespace scribo
template <typename I, typename J, typename K>
mln_ch_value(I, bool)
multi_scale_binarization(const I& in, const J& e2,
- const util::array<K>& t_ima,
+ const mln::util::array<K>& t_ima,
unsigned s)
{
mln_ch_value(I,bool) out;
@@ -758,10 +758,10 @@ namespace scribo
// Compute domains of subsampled images and make sure they can be
// divided by 2.
template <typename I>
- util::array<util::couple<mln_domain(I), unsigned> >
+ mln::util::array<mln::util::couple<mln_domain(I), unsigned> >
compute_sub_domains(const I& ima, unsigned n_scales, unsigned s)
{
- util::array<util::couple<unsigned, unsigned> > n(n_scales + 2);
+ mln::util::array<mln::util::couple<unsigned, unsigned> > n(n_scales + 2);
n(1) = mln::make::couple(ima.nrows(), ima.ncols());
n(2) = mln::make::couple(sub(n(1).first(), s),
@@ -771,7 +771,7 @@ namespace scribo
sub(n(i - 1).second(), 2));
- util::array<util::couple<mln_domain(I), unsigned> > out(n.size());
+ mln::util::array<mln::util::couple<mln_domain(I), unsigned> > out(n.size());
out(0) = mln::make::couple(mln::make::box2d(1,1), 1u);
out(1) = mln::make::couple(mln::make::box2d(ima.nrows(),
ima.ncols()), 2u);
@@ -833,7 +833,7 @@ namespace scribo
unsigned lambda_max_2 = lambda_min_2 * q;
- util::array<I> t_ima;
+ mln::util::array<I> t_ima;
// Make sure t_ima indexes start from 2.
{
@@ -842,7 +842,7 @@ namespace scribo
t_ima.append(dummy);
}
- util::array<I> sub_ima;
+ mln::util::array<I> sub_ima;
// Make sure sub_ima indexes start from 2.
{
@@ -851,7 +851,7 @@ namespace scribo
sub_ima.append(dummy);
}
- util::array<util::couple<box2d, unsigned> >
+ mln::util::array<mln::util::couple<box2d, unsigned> >
sub_domains = internal::compute_sub_domains(input_1, nb_subscale, s);
border::adjust(input_1, sub_domains(1).second());
@@ -859,7 +859,7 @@ namespace scribo
// Resize input and compute integral images.
- typedef image2d<util::couple<double,double> > integral_t;
+ typedef image2d<mln::util::couple<double,double> > integral_t;
integral_t integral_sum_sum_2;
// Subsampling from scale 1 to 2.
diff --git a/scribo/scribo/canvas/integral_browsing.hh b/scribo/scribo/canvas/integral_browsing.hh
index 286dc53..0ec3d83 100644
--- a/scribo/scribo/canvas/integral_browsing.hh
+++ b/scribo/scribo/canvas/integral_browsing.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -40,7 +40,7 @@ namespace scribo
template <typename F>
- void integral_browsing(const image2d<util::couple<double, double> >& ima,
+ void integral_browsing(const image2d<mln::util::couple<double, double> >& ima,
unsigned step,
unsigned w, unsigned h,
F& functor);
@@ -75,13 +75,13 @@ namespace scribo
template <typename F>
- void integral_browsing(const image2d<util::couple<double, double> >& ima,
+ void integral_browsing(const image2d<mln::util::couple<double, double> >& ima,
unsigned step,
unsigned w, unsigned h,
unsigned s,
F& functor)
{
- typedef util::couple<double, double> V;
+ typedef mln::util::couple<double, double> V;
typedef const V* Ptr;
Ptr a_ima, b_ima, c_ima, d_ima;
diff --git a/scribo/scribo/convert/to_base64.hh b/scribo/scribo/convert/to_base64.hh
index 8df3ed2..81dda1f 100644
--- a/scribo/scribo/convert/to_base64.hh
+++ b/scribo/scribo/convert/to_base64.hh
@@ -81,7 +81,7 @@ namespace scribo
template <typename I>
void
- to_base64(const Image<I>& input, util::array<unsigned char>& output);
+ to_base64(const Image<I>& input, mln::util::array<unsigned char>& output);
# ifndef MLN_INCLUDE_ONLY
@@ -116,7 +116,7 @@ namespace scribo
template <typename I>
void
- to_base64(const Image<I>& input_, util::array<unsigned char>& output)
+ to_base64(const Image<I>& input_, mln::util::array<unsigned char>& output)
{
trace::entering("scribo::convert::to_base64");
diff --git a/scribo/scribo/preprocessing/denoise_bg.hh b/scribo/scribo/preprocessing/denoise_bg.hh
index 8ad2d45..eda3803 100644
--- a/scribo/scribo/preprocessing/denoise_bg.hh
+++ b/scribo/scribo/preprocessing/denoise_bg.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.
//
@@ -131,7 +132,7 @@ namespace scribo
unsigned nlabels;
image2d<unsigned> lbl = labeling::background(input, nbh, nlabels);
- util::array<unsigned>
+ mln::util::array<unsigned>
result = labeling::compute(accu::meta::math::count(), lbl, nlabels);
mln::fun::i2v::array<bool> f(nlabels + 1, false);
--
1.5.6.5
1
0
* demo/xml2doc/image_crop.cc: Cleanup temporary files.
* demo/xml2doc/templates/pdf/line.xsl: Use paragraph
information. Take color into account.
* demo/xml2doc/templates/pdf/regions.xsl: Fix image localization.
---
scribo/ChangeLog | 11 +
scribo/demo/xml2doc/image_crop.cc | 6 +-
scribo/demo/xml2doc/templates/pdf/line.xsl | 390 +++++++++++++------------
scribo/demo/xml2doc/templates/pdf/regions.xsl | 14 +-
4 files changed, 215 insertions(+), 206 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index e30b230..d3a1780 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,14 @@
+2011-05-06 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ Improve PDF output.
+
+ * demo/xml2doc/image_crop.cc: Cleanup temporary files.
+
+ * demo/xml2doc/templates/pdf/line.xsl: Use paragraph
+ information. Take color into account.
+
+ * demo/xml2doc/templates/pdf/regions.xsl: Fix image localization.
+
2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
Add hexadecimal color conversion routines.
diff --git a/scribo/demo/xml2doc/image_crop.cc b/scribo/demo/xml2doc/image_crop.cc
index 72fd2b4..4221ee7 100644
--- a/scribo/demo/xml2doc/image_crop.cc
+++ b/scribo/demo/xml2doc/image_crop.cc
@@ -40,11 +40,15 @@ ImageCrop::ImageCrop(const QString& xml, const QString& img,
image_(img),
output_dir_(output)
{
- mln::io::magick::load(ima_, image_.toStdString());
+ if (!image_.isEmpty())
+ mln::io::magick::load(ima_, image_.toStdString());
}
ImageCrop::~ImageCrop()
{
+ // Cleanup temporary files.
+ foreach (QString value, region_map_)
+ QFile::remove(value);
}
diff --git a/scribo/demo/xml2doc/templates/pdf/line.xsl b/scribo/demo/xml2doc/templates/pdf/line.xsl
index 7056da0..4dda6c6 100644
--- a/scribo/demo/xml2doc/templates/pdf/line.xsl
+++ b/scribo/demo/xml2doc/templates/pdf/line.xsl
@@ -3,201 +3,205 @@
<!-- FILE: line.xsl
DESCRIPTION: match all pcGts/page/text_region/line in order to display the "text" attributes
- -->
-
- <xsl:template match="pcGts/page/text_region/line">
-
- <!-- x_height -->
- <xsl:variable name="x_height">
- <xsl:value-of select="@x_height" />
- </xsl:variable>
-
- <!-- a_height -->
- <xsl:variable name="a_height">
- <xsl:value-of select="@a_height" />
- </xsl:variable>
-
-
- <!-- ABS(d_height) -->
- <xsl:variable name="d_height_abs">
- <xsl:choose>
- <xsl:when test="@d_height < 0">
- <xsl:value-of select="-@d_height" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="@d_height" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <!-- a_height computed, i.e>
- if (A - X < |D|)
- A = X + |D|
+ -->
+
+ <xsl:template match="pcGts/page/text_region">
+
+ <!-- WTF !?, Necessary to do a lower-case !
+ FIXME: take a look at text-transform attribute -->
+ <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
+ <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
+
+ <!-- Text Colour -->
+ <xsl:variable name="colour">
+ <xsl:choose>
+ <xsl:when test="@color != ''">
+ <xsl:value-of select="translate(@color, $smallcase, $uppercase)" />
+ </xsl:when>
+ <xsl:otherwise>
+ black
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+
+ <xsl:for-each select="line">
+
+ <!-- x_height -->
+ <xsl:variable name="x_height">
+ <xsl:value-of select="@x_height" />
+ </xsl:variable>
+
+ <!-- a_height -->
+ <xsl:variable name="a_height">
+ <xsl:value-of select="@a_height" />
+ </xsl:variable>
+
+
+ <!-- ABS(d_height) -->
+ <xsl:variable name="d_height_abs">
+ <xsl:choose>
+ <xsl:when test="@d_height < 0">
+ <xsl:value-of select="-@d_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@d_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- a_height computed, i.e>
+ if (A - X < |D|)
+ A = X + |D|
-->
- <xsl:variable name="a">
- <xsl:choose>
- <xsl:when test="($a_height - $x_height) < $d_height_abs">
- <xsl:value-of select="$x_height + $d_height_abs" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$a_height" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <!-- d_height computed, i.e>
- if (A - A > |D|)
- |D| = A - X
+ <xsl:variable name="a">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) < $d_height_abs">
+ <xsl:value-of select="$x_height + $d_height_abs" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$a_height" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- d_height computed, i.e>
+ if (A - A > |D|)
+ |D| = A - X
-->
- <xsl:variable name="d">
- <xsl:choose>
- <xsl:when test="($a_height - $x_height) > $d_height_abs">
- <xsl:value-of select="$a_height - $x_height" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$d_height_abs" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <!-- Text lines coordinates -->
- <xsl:variable name="y1">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@y" order="ascending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@y" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:variable name="ymax">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@y" order="ascending" data-type="number"/>
- <xsl:if test="position() = 3">
- <xsl:value-of select="@y" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:variable name="x1">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@x" order="ascending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@x" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
-
- <xsl:variable name="xmax">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@x" order="ascending" data-type="number"/>
- <xsl:if test="position() = 3">
- <xsl:value-of select="@x" />
- </xsl:if>
- </xsl:for-each>
- </xsl:variable>
- <!-- END OF lines coordinates -->
-
- <!-- WTF !?, Necessary to do a lower-case !
- FIXME: take a look at text-transform attribute -->
- <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
- <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
-
- <!-- Text Colour -->
- <xsl:variable name="colour">
- <xsl:choose>
- <xsl:when test="@txt_colour != ''">
- <xsl:value-of select="translate(@txt_colour, $smallcase, $uppercase)" />
- </xsl:when>
- <xsl:otherwise>
- black
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
-
- <fo:block-container position="absolute" border-width="5mm">
-
- <xsl:attribute name="left">
- <xsl:value-of select="$x1" />px
- </xsl:attribute>
- <xsl:attribute name="top">
- <xsl:value-of select="$y1" />px
- </xsl:attribute>
-
- <xsl:attribute name="right">
- <xsl:value-of select="$xmax" />px
- </xsl:attribute>
- <xsl:attribute name="bottom">
- <xsl:value-of select="$ymax" />px
- </xsl:attribute>
-
-
- <xsl:attribute name="width">
- <xsl:value-of select="$xmax - $x1" />px
- </xsl:attribute>
-
- <xsl:attribute name="color">
- <xsl:value-of select="$colour" />
- </xsl:attribute>
-
- <!-- if necessary, put letter-spacing="-Npt" ~ -3 <= N <= -1
- in fo:block-->
-
- <!-- text-align-last="justify" will help justifying and using a
- uniform font size (it stretchs the text, at least for PDF)
- but it relies on several lines... We need paragraph
- information.
- -->
-
- <!-- FIXME: using a table allows to justify a single line of
- text. This is an UGLY HACK. Font size is also tweaked for
- now but it should not since we have font information.
- -->
- <fo:table table-layout="fixed">
-
- <xsl:attribute name="width">
- <xsl:value-of select="$xmax -$x1" />px
- </xsl:attribute>
-
- <fo:table-column column-number="1">
- <xsl:attribute name="column-width">
- <xsl:value-of select="$xmax -$x1" />px
- </xsl:attribute>
- </fo:table-column>
-
- <fo:table-body start-indent="0pt" text-align="justify" text-align-last="justify">
-
- <fo:table-row>
-
- <fo:table-cell>
-
- <fo:block font-family="Times" wrap-option="no-wrap" white-space-collapse="true" text-align-last="justify" text-align="justify">
-
- <xsl:attribute name="font-size">
- <xsl:choose>
- <xsl:when test="($a + $d) > 50">
- <xsl:value-of select="0.82 * ($a + $d)" />px
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="0.95 * ($a + $d)" />px
- </xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
-
- <xsl:value-of select="@text"/>
- </fo:block>
-
- </fo:table-cell>
-
- </fo:table-row>
-
- </fo:table-body>
-
- </fo:table>
-
-
- </fo:block-container>
+ <xsl:variable name="d">
+ <xsl:choose>
+ <xsl:when test="($a_height - $x_height) > $d_height_abs">
+ <xsl:value-of select="$a_height - $x_height" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$d_height_abs" />
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- Text lines coordinates -->
+ <xsl:variable name="y1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="ymax">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@y" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 3">
+ <xsl:value-of select="@y" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="x1">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 1">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+
+ <xsl:variable name="xmax">
+ <xsl:for-each select="coords/point">
+ <xsl:sort select="@x" order="ascending" data-type="number"/>
+ <xsl:if test="position() = 3">
+ <xsl:value-of select="@x" />
+ </xsl:if>
+ </xsl:for-each>
+ </xsl:variable>
+ <!-- END OF lines coordinates -->
+
+ <fo:block-container position="absolute" border-width="5mm">
+
+ <xsl:attribute name="left">
+ <xsl:value-of select="$x1" />px
+ </xsl:attribute>
+ <xsl:attribute name="top">
+ <xsl:value-of select="$y1" />px
+ </xsl:attribute>
+
+ <xsl:attribute name="right">
+ <xsl:value-of select="$xmax" />px
+ </xsl:attribute>
+ <xsl:attribute name="bottom">
+ <xsl:value-of select="$ymax" />px
+ </xsl:attribute>
+
+
+ <xsl:attribute name="width">
+ <xsl:value-of select="$xmax - $x1" />px
+ </xsl:attribute>
+
+ <xsl:attribute name="color">
+ <xsl:value-of select="$colour" />
+ </xsl:attribute>
+
+ <!-- if necessary, put letter-spacing="-Npt" ~ -3 <= N <= -1
+ in fo:block-->
+
+ <!-- text-align-last="justify" will help justifying and using a
+ uniform font size (it stretchs the text, at least for PDF)
+ but it relies on several lines... We need paragraph
+ information.
+ -->
+
+ <!-- FIXME: using a table allows to justify a single line of
+ text. This is an UGLY HACK. Font size is also tweaked for
+ now but it should not since we have font information.
+ -->
+ <fo:table table-layout="fixed">
+
+ <xsl:attribute name="width">
+ <xsl:value-of select="$xmax -$x1" />px
+ </xsl:attribute>
+
+ <fo:table-column column-number="1">
+ <xsl:attribute name="column-width">
+ <xsl:value-of select="$xmax -$x1" />px
+ </xsl:attribute>
+ </fo:table-column>
+
+ <fo:table-body start-indent="0pt" text-align="justify" text-align-last="justify">
+
+ <fo:table-row>
+
+ <fo:table-cell>
+
+ <fo:block font-family="Times" wrap-option="no-wrap" white-space-collapse="true" text-align-last="justify" text-align="justify">
+
+ <xsl:attribute name="font-size">
+ <xsl:choose>
+ <xsl:when test="($a + $d) > 50">
+ <xsl:value-of select="0.82 * ($a + $d)" />px
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="0.95 * ($a + $d)" />px
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:attribute>
+
+ <xsl:value-of select="@text"/>
+ </fo:block>
+
+ </fo:table-cell>
+
+ </fo:table-row>
+
+ </fo:table-body>
+
+ </fo:table>
+
+
+ </fo:block-container>
+
+ </xsl:for-each>
</xsl:template>
diff --git a/scribo/demo/xml2doc/templates/pdf/regions.xsl b/scribo/demo/xml2doc/templates/pdf/regions.xsl
index f236a1f..7772cbf 100644
--- a/scribo/demo/xml2doc/templates/pdf/regions.xsl
+++ b/scribo/demo/xml2doc/templates/pdf/regions.xsl
@@ -18,21 +18,11 @@
<!-- Regions coordinates -->
<xsl:variable name="y1">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@y" order="ascending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@y" />
- </xsl:if>
- </xsl:for-each>
+ <xsl:value-of select="@y_min" />
</xsl:variable>
<xsl:variable name="x1">
- <xsl:for-each select="coords/point">
- <xsl:sort select="@x" order="ascending" data-type="number"/>
- <xsl:if test="position() = 1">
- <xsl:value-of select="@x" />
- </xsl:if>
- </xsl:for-each>
+ <xsl:value-of select="@x_min" />
</xsl:variable>
<!-- END OF regions coordinates -->
--
1.5.6.5
1
0

last-svn-commit-861-g41f3675 configure.ac: Configure scribo/tests/util.
by Guillaume Lazzara 05 May '11
by Guillaume Lazzara 05 May '11
05 May '11
---
ChangeLog | 4 ++++
configure.ac | 3 +++
2 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 31d498c..852ea6e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ * configure.ac: Configure scribo/tests/util.
+
2011-04-05 Guillaume Lazzara <z(a)lrde.epita.fr>
* configure.ac: Configure scribo/tests/estim.
diff --git a/configure.ac b/configure.ac
index 189d905..fdbddd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -348,6 +348,8 @@ AC_CONFIG_FILES([
scribo/tests/core/Makefile
scribo/tests/estim/Makefile
scribo/tests/filter/Makefile
+ scribo/tests/io/Makefile
+ scribo/tests/io/xml/Makefile
scribo/tests/preprocessing/Makefile
scribo/tests/primitive/Makefile
scribo/tests/primitive/extract/Makefile
@@ -357,6 +359,7 @@ AC_CONFIG_FILES([
scribo/tests/toolchain/Makefile
scribo/tests/toolchain/nepomuk/Makefile
scribo/tests/unit_test/Makefile
+ scribo/tests/util/Makefile
])
# Flags for Scribo
--
1.5.6.5
1
0

last-svn-commit-859-gd90f512 Explicitly set vertical or horizontal attribute for separators in XML output.
by Guillaume Lazzara 05 May '11
by Guillaume Lazzara 05 May '11
05 May '11
* demo/xml2doc/image_crop.cc,
* demo/xml2doc/templates/pdf/regions.xsl: Handle new XML tags.
* scribo/core/document.hh,
* scribo/core/tag/component.hh,
* scribo/io/img/internal/debug_img_visitor.hh,
* scribo/io/img/internal/full_img_visitor.hh,
* scribo/io/img/internal/non_text_img_visitor.hh,
* 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: Update enum
declaration and handle new cases.
---
scribo/ChangeLog | 18 ++++++++
scribo/demo/xml2doc/image_crop.cc | 7 ++-
scribo/demo/xml2doc/templates/pdf/regions.xsl | 3 +-
scribo/scribo/core/document.hh | 4 +-
scribo/scribo/core/tag/component.hh | 16 +++++--
scribo/scribo/io/img/internal/debug_img_visitor.hh | 3 +-
scribo/scribo/io/img/internal/full_img_visitor.hh | 3 +-
.../scribo/io/img/internal/non_text_img_visitor.hh | 3 +-
.../io/xml/internal/extended_page_xml_visitor.hh | 24 +++++++++-
scribo/scribo/io/xml/internal/full_xml_visitor.hh | 45 +++++++++++++++++---
scribo/scribo/io/xml/internal/page_xml_visitor.hh | 3 +-
11 files changed, 105 insertions(+), 24 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index efc42cf..e857752 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,23 @@
2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+ Explicitly set vertical or horizontal attribute for separators in
+ XML output.
+
+ * demo/xml2doc/image_crop.cc,
+ * demo/xml2doc/templates/pdf/regions.xsl: Handle new XML tags.
+
+ * scribo/core/document.hh,
+ * scribo/core/tag/component.hh,
+ * scribo/io/img/internal/debug_img_visitor.hh,
+ * scribo/io/img/internal/full_img_visitor.hh,
+ * scribo/io/img/internal/non_text_img_visitor.hh,
+ * 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: Update enum
+ declaration and handle new cases.
+
+2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
Make use of opacity in PDF output.
* demo/xml2doc/image_crop.cc: Create opacity mask.
diff --git a/scribo/demo/xml2doc/image_crop.cc b/scribo/demo/xml2doc/image_crop.cc
index 7d61f75..72fd2b4 100644
--- a/scribo/demo/xml2doc/image_crop.cc
+++ b/scribo/demo/xml2doc/image_crop.cc
@@ -101,7 +101,7 @@ void ImageCrop::from_base64()
child = child.firstChild();
while (!child.isNull())
{
- if (child.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
+ if (child.toElement().tagName().contains(QRegExp("(image|graphic|chart|horizontal_separator|vertical_separator|table)_region")))
{
QDomNode node = child.firstChild();
QString id = child.toElement().attribute("id", "none");
@@ -208,7 +208,7 @@ void ImageCrop::to_base64(const QString& out_file, bool no_crop)
while(!line.contains("</pcGts>"))
{
stream2 << "\n" << line;
- if (line.contains(QRegExp("<(image|graphic|chart|separator|table)_region")))
+ if (line.contains(QRegExp("<(image|graphic|chart|horizontal_separator|vertical_separator|table)_region")))
{
stream2 << "\n" << " <container>\n";
stream2 << " <mime>png</mime>\n";
@@ -268,7 +268,7 @@ bool ImageCrop::crop_regions(bool temp)
while (!region.isNull())
{
- if (region.toElement().tagName().contains(QRegExp("(image|graphic|chart|separator|table)_region")))
+ if (region.toElement().tagName().contains(QRegExp("(image|graphic|chart|vertical_separator|horizontal_separator|table)_region")))
{
found_regions = true;
@@ -338,6 +338,7 @@ bool ImageCrop::crop_regions(bool temp)
else
io::magick::save(crop, opacity_mask, QString(output_dir_ + id + ".png").toStdString());
}
+
region = region.nextSibling();
}
diff --git a/scribo/demo/xml2doc/templates/pdf/regions.xsl b/scribo/demo/xml2doc/templates/pdf/regions.xsl
index add0cba..f236a1f 100644
--- a/scribo/demo/xml2doc/templates/pdf/regions.xsl
+++ b/scribo/demo/xml2doc/templates/pdf/regions.xsl
@@ -8,7 +8,8 @@
pcGts/page/graphic_region|
pcGts/page/chart_region|
pcGts/page/table_region|
- pcGts/page/separator_region">
+ pcGts/page/vertical_separator_region|
+ pcGts/page/horizontal_separator_region">
<!-- ID of the region, used to display id.png -->
<xsl:variable name="data">
diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh
index e287c1d..0fe2be3 100644
--- a/scribo/scribo/core/document.hh
+++ b/scribo/scribo/core/document.hh
@@ -343,7 +343,7 @@ namespace scribo
mln_value(L) ncomps;
hline_seps_comps_ = primitive::extract::components(hline_seps,
mln::c8(), ncomps,
- component::LineSeparator);
+ component::HorizontalLineSeparator);
}
@@ -390,7 +390,7 @@ namespace scribo
mln_value(L) ncomps;
vline_seps_comps_ = primitive::extract::components(vline_seps,
mln::c8(), ncomps,
- component::LineSeparator);
+ component::VerticalLineSeparator);
}
diff --git a/scribo/scribo/core/tag/component.hh b/scribo/scribo/core/tag/component.hh
index 7cd2ede..dc9db90 100644
--- a/scribo/scribo/core/tag/component.hh
+++ b/scribo/scribo/core/tag/component.hh
@@ -55,7 +55,8 @@ namespace scribo
{
Undefined = 0,
Character,
- LineSeparator,
+ VerticalLineSeparator,
+ HorizontalLineSeparator,
WhitespaceSeparator,
Noise,
Punctuation,
@@ -117,8 +118,11 @@ namespace scribo
case Character:
str = "Character";
break;
- case LineSeparator:
- str = "LineSeparator";
+ case HorizontalLineSeparator:
+ str = "HorizontalLineSeparator";
+ break;
+ case VerticalLineSeparator:
+ str = "VerticalLineSeparator";
break;
case WhitespaceSeparator:
str = "WhitespaceSeparator";
@@ -143,8 +147,10 @@ namespace scribo
{
if (str == "Character")
return Character;
- else if (str == "LineSeparator")
- return LineSeparator;
+ else if (str == "HorizontalLineSeparator")
+ return HorizontalLineSeparator;
+ else if (str == "VerticalLineSeparator")
+ return VerticalLineSeparator;
else if (str == "WhitespaceSeparator")
return WhitespaceSeparator;
else if (str == "Noise")
diff --git a/scribo/scribo/io/img/internal/debug_img_visitor.hh b/scribo/scribo/io/img/internal/debug_img_visitor.hh
index f1c689d..62097f5 100644
--- a/scribo/scribo/io/img/internal/debug_img_visitor.hh
+++ b/scribo/scribo/io/img/internal/debug_img_visitor.hh
@@ -179,7 +179,8 @@ namespace scribo
{
switch (info.type())
{
- case component::LineSeparator:
+ case component::HorizontalLineSeparator:
+ case component::VerticalLineSeparator:
{
mln::draw::box(output, compute_bbox(info.bbox()),
literal::cyan);
diff --git a/scribo/scribo/io/img/internal/full_img_visitor.hh b/scribo/scribo/io/img/internal/full_img_visitor.hh
index 30987db..170b6a1 100644
--- a/scribo/scribo/io/img/internal/full_img_visitor.hh
+++ b/scribo/scribo/io/img/internal/full_img_visitor.hh
@@ -135,7 +135,8 @@ namespace scribo
{
switch (info.type())
{
- case component::LineSeparator:
+ case component::HorizontalLineSeparator:
+ case component::VerticalLineSeparator:
{
mln::draw::box(output, info.bbox(), literal::cyan);
}
diff --git a/scribo/scribo/io/img/internal/non_text_img_visitor.hh b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
index 24b027e..cc1acb9 100644
--- a/scribo/scribo/io/img/internal/non_text_img_visitor.hh
+++ b/scribo/scribo/io/img/internal/non_text_img_visitor.hh
@@ -132,7 +132,8 @@ namespace scribo
{
switch (info.type())
{
- case component::LineSeparator:
+ case component::HorizontalLineSeparator:
+ case component::VerticalLineSeparator:
{
mln::draw::box(output, info.bbox(), literal::cyan);
}
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 eaf08ac..83e5b0b 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -179,9 +179,9 @@ namespace scribo
break;
}
- case component::LineSeparator:
+ case component::VerticalLineSeparator:
{
- output << " <separator_region id=\"sr" << info.id()
+ output << " <vertical_separator_region id=\"vlsr" << info.id()
<< "\" sep_orientation=\"0.000000\" "
<< " sep_colour=\"Black\" "
<< " sep_bgcolour=\"White\""
@@ -193,7 +193,25 @@ namespace scribo
internal::print_box_coords(output, info.bbox(), " ");
- output << " </separator_region>" << std::endl;
+ output << " </vertical_separator_region>" << std::endl;
+ break;
+ }
+
+ case component::HorizontalLineSeparator:
+ {
+ output << " <horizontal_separator_region id=\"hlsr" << info.id()
+ << "\" sep_orientation=\"0.000000\" "
+ << " sep_colour=\"Black\" "
+ << " sep_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </horizontal_separator_region>" << std::endl;
break;
}
diff --git a/scribo/scribo/io/xml/internal/full_xml_visitor.hh b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
index c294bbc..b920ca8 100644
--- a/scribo/scribo/io/xml/internal/full_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
@@ -355,7 +355,12 @@ namespace scribo
{
output << " <whitespace_separator_region id=\"wss"
<< info.id()
- << "\">" << std::endl;
+ << "\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
@@ -363,16 +368,39 @@ namespace scribo
break;
}
- case component::LineSeparator:
+ case component::VerticalLineSeparator:
{
- output << " <separator_region id=\"sr" << info.id()
+ output << " <vertical_separator_region id=\"vlsr" << info.id()
<< "\" sep_orientation=\"0.000000\" "
<< " sep_colour=\"Black\" "
- << " sep_bgcolour=\"White\">" << std::endl;
+ << " sep_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
- output << " </separator_region>" << std::endl;
+ output << " </vertical_separator_region>" << std::endl;
+ break;
+ }
+
+ case component::HorizontalLineSeparator:
+ {
+ output << " <horizontal_separator_region id=\"hlsr" << info.id()
+ << "\" sep_orientation=\"0.000000\" "
+ << " sep_colour=\"Black\" "
+ << " sep_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </horizontal_separator_region>" << std::endl;
break;
}
@@ -383,7 +411,12 @@ namespace scribo
<< "\" img_colour_type=\"24_Bit_Colour\""
<< " img_orientation=\"0.000000\" "
<< " img_emb_text=\"No\" "
- << " img_bgcolour=\"White\">" << std::endl;
+ << " img_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
diff --git a/scribo/scribo/io/xml/internal/page_xml_visitor.hh b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
index 19665d6..0014caf 100644
--- a/scribo/scribo/io/xml/internal/page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
@@ -146,7 +146,8 @@ namespace scribo
{
switch (info.type())
{
- case component::LineSeparator:
+ case component::VerticalLineSeparator:
+ case component::HorizontalLineSeparator:
{
output << " <separator_region id=\"sr" << info.id()
<< "\" sep_orientation=\"0.000000\" "
--
1.5.6.5
1
0

05 May '11
* demo/xml2doc/image_crop.cc: Create opacity mask.
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Add bbox
information in region tag.
---
scribo/ChangeLog | 9 +++
scribo/demo/xml2doc/image_crop.cc | 60 +++++++++++++-------
.../io/xml/internal/extended_page_xml_visitor.hh | 21 ++++++-
3 files changed, 67 insertions(+), 23 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index a213078..efc42cf 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,12 @@
+2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ Make use of opacity in PDF output.
+
+ * demo/xml2doc/image_crop.cc: Create opacity mask.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Add bbox
+ information in region tag.
+
2011-05-04 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
Small fixes in Scribo.
diff --git a/scribo/demo/xml2doc/image_crop.cc b/scribo/demo/xml2doc/image_crop.cc
index ba30d8a..7d61f75 100644
--- a/scribo/demo/xml2doc/image_crop.cc
+++ b/scribo/demo/xml2doc/image_crop.cc
@@ -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.
//
@@ -16,10 +17,13 @@
#include <limits.h>
+#include <scribo/core/macros.hh>
#include <scribo/preprocessing/crop.hh>
#include <mln/value/rgb8.hh>
#include <mln/core/alias/box2d.hh>
#include <mln/core/image/image2d.hh>
+#include <mln/util/couple.hh>
+#include <mln/draw/line.hh>
#include <mln/io/magick/save.hh>
#include <mln/io/magick/load.hh>
#include <mln/io/ppm/all.hh>
@@ -28,6 +32,7 @@
#include "loader.hh"
#include "common.hh"
+#include <mln/io/pbm/save.hh>
ImageCrop::ImageCrop(const QString& xml, const QString& img,
const QString& output)
@@ -270,7 +275,14 @@ bool ImageCrop::crop_regions(bool temp)
QDomNode coords = region.firstChild();
QString id = region.toElement().attribute("id", "none");
- // qDebug() << region.toElement().tagName();
+ // Retrieve region bbox.
+ using namespace mln;
+ def::coord
+ x_min = region.toElement().attribute("x_min").toInt(),
+ y_min = region.toElement().attribute("y_min").toInt(),
+ x_max = region.toElement().attribute("x_max").toInt(),
+ y_max = region.toElement().attribute("y_max").toInt();
+ box2d box = make::box2d(y_min, x_min, y_max, x_max);
while (!coords.isNull() && !coords.toElement().tagName().contains("coords"))
coords = coords.nextSibling();
@@ -279,44 +291,52 @@ bool ImageCrop::crop_regions(bool temp)
break;
QDomNode point = coords.firstChild();
- int x_max = 0;
- int y_max = 0;
- int x_min = INT_MAX;
- int y_min = INT_MAX;
+ // For each row, store first and last column of the line
+ // to be set as object. The rest will be considered as
+ // transparent.
+ util::array<util::couple<def::coord, def::coord> >
+ p_mask(box.nrows(),
+ util::couple<def::coord, def::coord>(x_max + 1, x_min - 1));
+
+ // Compute opacity mask for image region.
while (!point.isNull())
{
int x = point.toElement().attribute("x", "none").toInt();
int y = point.toElement().attribute("y", "none").toInt();
- if (x < x_min)
- x_min = x;
- if (x > x_max)
- x_max = x;
-
- if (y < y_min)
- y_min = y;
- if (y > y_max)
- y_max = y;
+ if (p_mask(y - y_min).first() > x)
+ p_mask(y - y_min).first() = x;
+ if (p_mask(y - y_min).second() < x)
+ p_mask(y - y_min).second() = x;
point = point.nextSibling();
}
- using namespace mln;
- box2d box = make::box2d(y_min, x_min, y_max, x_max);
-
+ // Crop image in input.
image2d<value::rgb8> crop = scribo::preprocessing::crop(ima_, box);
+ // Build image mask.
+ image2d<bool> opacity_mask(box);
+ {
+ data::fill(opacity_mask, true);
+ for_all_elements(e, p_mask)
+ draw::line(opacity_mask,
+ point2d(e + y_min, p_mask(e).first()),
+ point2d(e + y_min, p_mask(e).second()),
+ false);
+ }
+
if (temp)
{
QTemporaryFile tmp(output_dir_ + id + ".XXXXXX.png");
tmp.open();
region_map_[id] = tmp.fileName();
tmp.setAutoRemove(false);
- io::magick::save(crop, tmp.fileName().toStdString());
+ io::magick::save(crop, opacity_mask, tmp.fileName().toStdString());
}
else
- io::magick::save(crop, QString(output_dir_ + id + ".png").toStdString());
+ io::magick::save(crop, opacity_mask, QString(output_dir_ + id + ".png").toStdString());
}
region = region.nextSibling();
}
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 b463677..eaf08ac 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -166,7 +166,12 @@ namespace scribo
{
output << " <whitespace_separator_region id=\"wss"
<< info.id()
- << "\">" << std::endl;
+ << "\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
@@ -179,7 +184,12 @@ namespace scribo
output << " <separator_region id=\"sr" << info.id()
<< "\" sep_orientation=\"0.000000\" "
<< " sep_colour=\"Black\" "
- << " sep_bgcolour=\"White\">" << std::endl;
+ << " sep_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
@@ -195,7 +205,12 @@ namespace scribo
<< "\" img_colour_type=\"24_Bit_Colour\""
<< " img_orientation=\"0.000000\" "
<< " img_emb_text=\"No\" "
- << " img_bgcolour=\"White\">" << std::endl;
+ << " img_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() << "\""
+ << " y_min=\"" << info.bbox().pmin().row() << "\""
+ << " x_max=\"" << info.bbox().pmax().col() << "\""
+ << " y_max=\"" << info.bbox().pmax().row() << "\""
+ << ">" << std::endl;
internal::print_image_coords(output,
((elt_edge | info.bbox())
--
1.5.6.5
1
0

last-svn-commit-857-g9b5c9ab mln/io/magick/save.hh: Add support for opacity.
by Guillaume Lazzara 05 May '11
by Guillaume Lazzara 05 May '11
05 May '11
---
milena/ChangeLog | 4 +
milena/mln/io/magick/save.hh | 155 ++++++++++++++++++++++++++++++++++--------
2 files changed, 131 insertions(+), 28 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 8008503..d12cc20 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,7 @@
+2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ * mln/io/magick/save.hh: Add support for opacity.
+
2011-04-05 Guillaume Lazzara <z(a)lrde.epita.fr>
* mln/accu/stat/median_h.hh: Add missing operator=().
diff --git a/milena/mln/io/magick/save.hh b/milena/mln/io/magick/save.hh
index 2ea2957..f592059 100644
--- a/milena/mln/io/magick/save.hh
+++ b/milena/mln/io/magick/save.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -59,13 +59,29 @@ namespace mln
{
/** Save a Milena image into a file using Magick++.
+ \overload
- \param[out] ima The image to save.
- \param[in] filename The name of the output file. */
+ \param[in] ima The image to save.
+ \param[in] filename The name of the output file. */
template <typename I>
void
save(const Image<I>& ima, const std::string& filename);
+ /** Save a Milena image into a file using Magick++.
+
+ \param[in] ima The image to save.
+
+ \param[in] opacity_mask Mask used to set pixel opacity_mask in output
+ image. Output format must support this feature to be taken
+ into account.
+
+ \param[in] filename The name of the output file.
+ */
+ template <typename I, typename J>
+ void
+ save(const Image<I>& ima, const Image<J>& opacity_mask,
+ const std::string& filename);
+
// FIXME: Unfinished?
#if 0
@@ -125,10 +141,92 @@ namespace mln
} // end of namespace mln::io::magick::impl
- template <typename I>
- inline
+ namespace internal
+ {
+
+ template <typename I>
+ void
+ paste_data(const Image<I>& ima_, Magick::Image& magick_ima)
+ {
+ const I& ima = exact(ima_);
+
+ def::coord
+ minrow = geom::min_row(ima),
+ mincol = geom::min_col(ima),
+ maxrow = geom::max_row(ima),
+ maxcol = geom::max_col(ima),
+ ncols = geom::ncols(ima),
+ nrows = geom::nrows(ima);
+
+ // Ensure that there is only one reference to underlying image
+ // If this is not done, then image pixels will not be modified.
+ magick_ima.modifyImage();
+
+ Magick::Pixels view(magick_ima);
+ // As above, `ncols' is passed before `nrows'.
+ Magick::PixelPacket* pixels = view.get(0, 0, ncols, nrows);
+ const mln_value(I) *ptr_ima = &ima(ima.domain().pmin());
+
+ unsigned row_offset = ima.delta_index(dpoint2d(+1, - ncols));
+
+ for (def::coord row = minrow; row <= maxrow;
+ ++row, ptr_ima += row_offset)
+ for (def::coord col = mincol; col <= maxcol; ++col)
+ *pixels++ = impl::get_color(*ptr_ima++);
+
+ view.sync();
+ }
+
+ template <typename I, typename J>
+ void
+ paste_data_opacity(const Image<I>& ima_,
+ const Image<J>& opacity_mask_,
+ Magick::Image& magick_ima)
+ {
+ const I& ima = exact(ima_);
+ const J& opacity_mask = exact(opacity_mask_);
+
+ def::coord
+ minrow = geom::min_row(ima),
+ mincol = geom::min_col(ima),
+ maxrow = geom::max_row(ima),
+ maxcol = geom::max_col(ima),
+ ncols = geom::ncols(ima),
+ nrows = geom::nrows(ima);
+
+ // Ensure that there is only one reference to underlying image
+ // If this is not done, then image pixels will not be modified.
+ magick_ima.modifyImage();
+
+ Magick::Pixels view(magick_ima);
+ // As above, `ncols' is passed before `nrows'.
+ Magick::PixelPacket* pixels = view.get(0, 0, ncols, nrows);
+ const mln_value(I) *ptr_ima = &ima(ima.domain().pmin());
+ const mln_value(J) *ptr_opacity_mask = &opacity_mask(opacity_mask.domain().pmin());
+
+ unsigned row_offset = ima.delta_index(dpoint2d(+1, - ncols));
+ unsigned opacity_row_offset = opacity_mask.delta_index(dpoint2d(+1, - ncols));
+
+ for (def::coord row = minrow; row <= maxrow;
+ ++row, ptr_ima += row_offset,
+ ptr_opacity_mask += opacity_row_offset)
+ for (def::coord col = mincol; col <= maxcol; ++col)
+ {
+ *pixels = impl::get_color(*ptr_ima++);
+ (*pixels).opacity = ((*ptr_opacity_mask++) ? 255 : 0);
+ ++pixels;
+ }
+
+ view.sync();
+ }
+
+ } // end of namespace mln::io::magick::internal
+
+
+ template <typename I, typename J>
void
- save(const Image<I>& ima_, const std::string& filename)
+ save(const Image<I>& ima_, const Image<J>& opacity_mask_,
+ const std::string& filename)
{
trace::entering("mln::io::magick::save");
@@ -149,15 +247,13 @@ namespace mln
}
const I& ima = exact(ima_);
+ const J& opacity_mask = exact(opacity_mask_);
def::coord
- minrow = geom::min_row(ima),
- mincol = geom::min_col(ima),
- maxrow = geom::max_row(ima),
- maxcol = geom::max_col(ima),
ncols = geom::ncols(ima),
nrows = geom::nrows(ima);
+
// In the construction of a Geometry object, the width (i.e.
// `ncols') comes first, then the height (i.e. `nrows')
// follows.
@@ -168,28 +264,31 @@ namespace mln
// declared further fails and segfault...
Magick::Image magick_ima(Magick::Geometry(ncols, nrows), "white");
- magick_ima.type(Magick::TrueColorType);
-
- // Ensure that there is only one reference to underlying image
- // If this is not done, then image pixels will not be modified.
- magick_ima.modifyImage();
+ if (opacity_mask.is_valid())
+ {
+ magick_ima.type(Magick::TrueColorMatteType);
+ internal::paste_data_opacity(ima, opacity_mask, magick_ima);
+ }
+ else
+ {
+ magick_ima.type(Magick::TrueColorType);
+ internal::paste_data(ima, magick_ima);
+ }
- Magick::Pixels view(magick_ima);
- // As above, `ncols' is passed before `nrows'.
- Magick::PixelPacket* pixels = view.get(0, 0, ncols, nrows);
- const mln_value(I) *ptr_ima = &ima(ima.domain().pmin());
+ magick_ima.write(filename);
- unsigned row_offset = ima.delta_index(dpoint2d(+1, - ncols));
+ trace::exiting("mln::io::magick::save");
+ }
- for (def::coord row = minrow; row <= maxrow;
- ++row, ptr_ima += row_offset)
- for (def::coord col = mincol; col <= maxcol; ++col)
- *pixels++ = impl::get_color(*ptr_ima++);
- view.sync();
- magick_ima.write(filename);
- trace::exiting("mln::io::magick::save");
+ template <typename I>
+ inline
+ void
+ save(const Image<I>& ima, const std::string& filename)
+ {
+ mln_ch_value(I,bool) opacity_mask;
+ save(ima, opacity_mask, filename);
}
--
1.5.6.5
1
0
* demo/xml2doc/image_crop.cc: Abort xml loading if an error
is found.
* scribo/core/line_info.hh: Fix text cleanup.
* scribo/io/img/save.hh: Add documentation.
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Use
internal_gradient.
* scribo/primitive/extract/alignments.hh: Set component type to
whitespaceSeparator.
* src/binarization/sauvola_ms_fg.cc: Fix argument use.
---
scribo/ChangeLog | 19 +++++++++++++++++++
scribo/demo/xml2doc/image_crop.cc | 2 ++
scribo/scribo/core/line_info.hh | 3 ++-
scribo/scribo/io/img/save.hh | 7 +++++++
.../io/xml/internal/extended_page_xml_visitor.hh | 4 ++--
scribo/scribo/primitive/extract/alignments.hh | 2 +-
scribo/src/binarization/sauvola_ms_fg.cc | 6 ++++--
7 files changed, 37 insertions(+), 6 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index fc761c3..a213078 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,24 @@
2011-05-04 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+ Small fixes in Scribo.
+
+ * demo/xml2doc/image_crop.cc: Abort xml loading if an error
+ is found.
+
+ * scribo/core/line_info.hh: Fix text cleanup.
+
+ * scribo/io/img/save.hh: Add documentation.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Use
+ internal_gradient.
+
+ * scribo/primitive/extract/alignments.hh: Set component type to
+ whitespaceSeparator.
+
+ * src/binarization/sauvola_ms_fg.cc: Fix argument use.
+
+2011-05-04 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
Make paragraph extraction work with this branch.
* scribo/core/line_info.hh: Keep few attributes public and update
diff --git a/scribo/demo/xml2doc/image_crop.cc b/scribo/demo/xml2doc/image_crop.cc
index 29a93d8..ba30d8a 100644
--- a/scribo/demo/xml2doc/image_crop.cc
+++ b/scribo/demo/xml2doc/image_crop.cc
@@ -326,6 +326,8 @@ bool ImageCrop::crop_regions(bool temp)
else
{
f.close();
+ qDebug() << "Error while reading XML file!";
+ abort();
return false;
}
}
diff --git a/scribo/scribo/core/line_info.hh b/scribo/scribo/core/line_info.hh
index 27dda84..e91e1c3 100644
--- a/scribo/scribo/core/line_info.hh
+++ b/scribo/scribo/core/line_info.hh
@@ -351,7 +351,7 @@ namespace scribo
static std::map<char, std::string> map = init_map();
std::string output = input;
- for (unsigned i = 0; i < input.size(); ++i)
+ for (unsigned i = 0; i < output.size(); ++i)
{
std::map<char, std::string>::iterator it = map.find(output.at(i));
if (it != map.end())
@@ -360,6 +360,7 @@ namespace scribo
i += it->second.size() - 1;
}
}
+
return output;
}
diff --git a/scribo/scribo/io/img/save.hh b/scribo/scribo/io/img/save.hh
index 56300d6..04f0a3c 100644
--- a/scribo/scribo/io/img/save.hh
+++ b/scribo/scribo/io/img/save.hh
@@ -66,6 +66,13 @@ namespace scribo
NonText : Display non-text regions.
Full : Text and non-text regions.
+
+ DebugWoImage : Display all regions onto a subsampled copy of
+ the original image. A dark background is used as background.
+
+ DebugWithImage : Display all regions onto a subsampled copy of
+ the original image. The original image is used as background.
+
*/
enum Format
{
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 b906a4a..b463677 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -32,7 +32,7 @@
# include <fstream>
-# include <mln/morpho/elementary/gradient_external.hh>
+# include <mln/morpho/elementary/gradient_internal.hh>
# include <mln/pw/all.hh>
# include <mln/core/image/dmorph/image_if.hh>
@@ -122,7 +122,7 @@ namespace scribo
if (doc.has_elements())
{
// Prepare element edges
- elt_edge = morpho::elementary::gradient_external(doc.elements().labeled_image(), c4());
+ elt_edge = morpho::elementary::gradient_internal(doc.elements().labeled_image(), c4());
doc.elements().accept(*this);
}
diff --git a/scribo/scribo/primitive/extract/alignments.hh b/scribo/scribo/primitive/extract/alignments.hh
index 8d18d93..1e3d835 100644
--- a/scribo/scribo/primitive/extract/alignments.hh
+++ b/scribo/scribo/primitive/extract/alignments.hh
@@ -1085,7 +1085,7 @@ namespace scribo
V ndelim;
component_set<L>
- delim_comps = primitive::extract::components(delimitors, c8(), ndelim);
+ delim_comps = primitive::extract::components(delimitors, c8(), ndelim, component::WhitespaceSeparator);
mln::util::couple<component_set<L>, mln_ch_value(L,bool)>
output(delim_comps, delimitors);
diff --git a/scribo/src/binarization/sauvola_ms_fg.cc b/scribo/src/binarization/sauvola_ms_fg.cc
index 7ff9321..2c5e7fa 100644
--- a/scribo/src/binarization/sauvola_ms_fg.cc
+++ b/scribo/src/binarization/sauvola_ms_fg.cc
@@ -58,10 +58,10 @@ bool check_args(int argc, char * argv[])
const char *args_desc[][2] =
{
{ "input.*", "An image." },
- { "output.pbm", "A binary image." },
{ "lambda", "Lambda used to split bg/fg." },
{ "w", "Window size at scale 1. (Common value: 101)" },
{ "s", "First subsampling ratio (Common value: 3)." },
+ { "output.pbm", "A binary image." },
{0, 0}
};
@@ -92,6 +92,8 @@ int main(int argc, char *argv[])
std::cout << "Using w_1=" << w_1 << " - s=" << s << std::endl;
+ Magick::InitializeMagick(0);
+
// Load
image2d<value::rgb8> input_1;
io::magick::load(input_1, argv[1]);
@@ -108,7 +110,7 @@ int main(int argc, char *argv[])
image2d<bool>
output = scribo::binarization::sauvola_ms(fg_gl, w_1, s, SCRIBO_DEFAULT_SAUVOLA_K);
- io::pbm::save(output, argv[6]);
+ io::pbm::save(output, argv[5]);
}
--
1.5.6.5
1
0

last-svn-commit-855-gae863e4 Make paragraph extraction work with this branch.
by Guillaume Lazzara 04 May '11
by Guillaume Lazzara 04 May '11
04 May '11
* scribo/core/line_info.hh: Keep few attributes public and update
method names.
* scribo/core/stats.hh: Fix missed elements in computation.
* scribo/text/paragraphs.hh: Use line_set and line_links
structures.
* scribo/toolchain/internal/content_in_doc_functor.hh: Make use of
the new paragraph extraction algorithm.
---
scribo/ChangeLog | 15 +
scribo/scribo/core/line_info.hh | 10 +-
scribo/scribo/core/stats.hh | 13 +-
scribo/scribo/text/paragraphs.hh | 1360 ++++++++++----------
.../toolchain/internal/content_in_doc_functor.hh | 178 ++--
5 files changed, 808 insertions(+), 768 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index a6ef3f8..fc761c3 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,18 @@
+2011-05-04 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ Make paragraph extraction work with this branch.
+
+ * scribo/core/line_info.hh: Keep few attributes public and update
+ method names.
+
+ * scribo/core/stats.hh: Fix missed elements in computation.
+
+ * scribo/text/paragraphs.hh: Use line_set and line_links
+ structures.
+
+ * scribo/toolchain/internal/content_in_doc_functor.hh: Make use of
+ the new paragraph extraction algorithm.
+
2011-05-03 Guillaume Lazzara <lazzara(a)lrde.epita.fr>
* tests/unit_test/unit-tests.mk: Regen.
diff --git a/scribo/scribo/core/line_info.hh b/scribo/scribo/core/line_info.hh
index 949315a..27dda84 100644
--- a/scribo/scribo/core/line_info.hh
+++ b/scribo/scribo/core/line_info.hh
@@ -145,14 +145,12 @@ namespace scribo
// Line set holding this element.
line_set<L> holder_;
- private:
- void init_();
-
// DEBUG
stats< float > meanline_clusters_;
stats< float > baseline_clusters_;
- };
+ private:
+ void init_();
};
} // end of namespace scribo::internal
@@ -980,8 +978,8 @@ namespace scribo
{
const component_set<L>& comp_set = data_->holder_.components();
- const unsigned c1 = data_->components_(0);
- const unsigned c2 = data_->components_(1);
+ const unsigned c1 = data_->component_ids_(0);
+ const unsigned c2 = data_->component_ids_(1);
if (data_->holder_.components()(c1).type() == component::Punctuation
|| data_->holder_.components()(c2).type() == component::Punctuation)
diff --git a/scribo/scribo/core/stats.hh b/scribo/scribo/core/stats.hh
index bc24044..095735c 100644
--- a/scribo/scribo/core/stats.hh
+++ b/scribo/scribo/core/stats.hh
@@ -261,7 +261,7 @@ private:
unsigned i = 0;
const unsigned nelements = data_.nelements();
- clusters[0] = cluster_index;
+ clusters.push_back(cluster_index);
const T std = data_.standard_deviation();
for (i = 1; i < nelements - 1; ++i)
@@ -276,11 +276,12 @@ private:
clusters.push_back(cluster_index);
}
- if (nelements > 1
- && data_[i] - data_[i - 1] > std)
- ++cluster_index;
-
- clusters.push_back(cluster_index);
+ if (nelements > 1)
+ {
+ if (data_[i] - data_[i - 1] > std)
+ ++cluster_index;
+ clusters.push_back(cluster_index);
+ }
clusters_.clear();
clusters_.reserve(cluster_index);
diff --git a/scribo/scribo/text/paragraphs.hh b/scribo/scribo/text/paragraphs.hh
index 5cb253e..94e5751 100644
--- a/scribo/scribo/text/paragraphs.hh
+++ b/scribo/scribo/text/paragraphs.hh
@@ -15,7 +15,9 @@
#include <scribo/core/macros.hh>
#include <scribo/core/line_set.hh>
+#include <scribo/core/line_links.hh>
#include <scribo/core/line_info.hh>
+#include <scribo/core/paragraph_set.hh>
using namespace mln;
@@ -59,15 +61,15 @@ namespace scribo
template <typename L>
inline
- void paragraph_links(const util::array<value::int_u16>& left,
- const util::array<value::int_u16>& right,
- util::array<value::int_u16>& output,
- const util::array< line_info<L> >& lines,
+ void paragraph_links(const line_links<L>& left,
+ const line_links<L>& right,
+ line_links<L>& output,
+ const line_set<L>& lines,
const image2d<bool>& input)
{
- output = left;
+ output = left.duplicate();
- const unsigned nlines = lines.nelements();
+ // const unsigned nlines = lines.nelements();
// image2d<value::rgb8> links = data::convert(value::rgb8(), input);
// for (unsigned l = 0; l < nlines; ++l)
@@ -77,242 +79,259 @@ namespace scribo
// mln::io::ppm::save(links, "out_links.ppm");
// For each line
- for (unsigned l = 0; l < nlines; ++l)
- {
- // Neighbors
-
- const value::int_u16 left_nbh = output(l);
- const value::int_u16 right_nbh = right(l);
- const value::int_u16 lol_nbh = output(left_nbh);
-
- // Line features
- const float x_height = lines(l).x_height();
- const float left_x_height = lines(left_nbh).x_height();
- const float right_x_height = lines(right_nbh).x_height();
-
- const box2d& left_line_bbox = lines(left_nbh).bbox();
- const box2d& current_line_bbox = lines(l).bbox();
- const box2d& right_line_bbox = lines(right_nbh).bbox();
- const box2d& lol_line_bbox = lines(lol_nbh).bbox(); // lol : left neighbor of the left neighbor
-
- const int lline_col_min = left_line_bbox.pmin().col();
- const int cline_col_min = current_line_bbox.pmin().col();
- const int rline_col_min = right_line_bbox.pmin().col();
- const int lolline_col_min = lol_line_bbox.pmin().col();
-
- const int lline_col_max = left_line_bbox.pmax().col();
- const int cline_col_max = current_line_bbox.pmax().col();
- const int rline_col_max = right_line_bbox.pmax().col();
-
- const int lline_cw = lines(left_nbh).char_width();
- const int cline_cw = lines(l).char_width();
- const int rline_cw = lines(right_nbh).char_width();
- // Maximal x variation to consider two lines vertically aligned
- const int delta_alignment = cline_cw;
-
- // Checks the baseline distances of the two neighbors
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
{
- // Current line baseline
- const int c_baseline = lines(l).baseline();
-
- // Baseline distance with the left and right neighbors
- const int lc_baseline = lines(left_nbh).baseline() - c_baseline;
- const int rc_baseline = c_baseline -lines(right_nbh).baseline();
+ // Neighbors
+
+ const line_id_t left_nbh = output(l);
+ const line_id_t right_nbh = right(l);
+ const line_id_t lol_nbh = output(left_nbh);
+
+ // Line features
+ const float x_height = lines(l).x_height();
+ const float left_x_height = lines(left_nbh).x_height();
+ const float right_x_height = lines(right_nbh).x_height();
+
+ const box2d& left_line_bbox = lines(left_nbh).bbox();
+ const box2d& current_line_bbox = lines(l).bbox();
+ const box2d& right_line_bbox = lines(right_nbh).bbox();
+ const box2d& lol_line_bbox = lines(lol_nbh).bbox(); // lol : left neighbor of the left neighbor
+
+ const int lline_col_min = left_line_bbox.pmin().col();
+ const int cline_col_min = current_line_bbox.pmin().col();
+ const int rline_col_min = right_line_bbox.pmin().col();
+ const int lolline_col_min = lol_line_bbox.pmin().col();
+
+ const int lline_col_max = left_line_bbox.pmax().col();
+ const int cline_col_max = current_line_bbox.pmax().col();
+ const int rline_col_max = right_line_bbox.pmax().col();
+
+ const int lline_cw = lines(left_nbh).char_width();
+ const int cline_cw = lines(l).char_width();
+ const int rline_cw = lines(right_nbh).char_width();
+ // Maximal x variation to consider two lines vertically aligned
+ const int delta_alignment = cline_cw;
+
+ // Checks the baseline distances of the two neighbors
+ {
+ // Current line baseline
+ const int c_baseline = lines(l).baseline();
- // Max baseline distance between the two neighbors
- // const float delta_baseline_max = std::max(lc_baseline, rc_baseline);
- // const float delta_baseline_min = std::min(lc_baseline,
- // rc_baseline);
+ // Baseline distance with the left and right neighbors
+ const int lc_baseline = lines(left_nbh).baseline() - c_baseline;
+ const int rc_baseline = c_baseline -lines(right_nbh).baseline();
- // Only two lines, meaning the current line has only one neighbor
- bool two_lines = false;
+ // Max baseline distance between the two neighbors
+ // const float delta_baseline_max = std::max(lc_baseline, rc_baseline);
+ // const float delta_baseline_min = std::min(lc_baseline,
+ // rc_baseline);
- // If the current line has no left neighbor
- if (lc_baseline == 0)
- {
- // ror : right neighbor of the right neighbor
- const value::int_u16 ror_nbh = right(right_nbh);
- // const box2d& ror_line_bbox = lines(ror_nbh).bbox();
+ // Only two lines, meaning the current line has only one neighbor
+ bool two_lines = false;
- // If the current line has a ror
- if (ror_nbh != right_nbh
- && output(ror_nbh) == right_nbh)
+ // If the current line has no left neighbor
+ if (lc_baseline == 0)
{
- // Distance between the current line and the right neighbor
- const float right_distance = lines(l).meanline() - lines(right_nbh).baseline();
- // Distance between the right neighbor and the ror
- const float ror_distance = lines(right_nbh).meanline() - lines(ror_nbh).baseline();
- // ror x_height
- const float ror_x_height = lines(ror_nbh).x_height();
-
- // Conditions to cut the link between the current line
- // and its right neighbor
- if (right_distance > 1.4f * ror_distance
- && std::max(ror_x_height, right_x_height) <
- 1.2f * std::min(ror_x_height, right_x_height)
- && output(right_nbh) == l)
+ // ror : right neighbor of the right neighbor
+ const line_id_t ror_nbh = right(right_nbh);
+ //const box2d& ror_line_bbox = lines(ror_nbh).bbox();
+
+ // If the current line has a ror
+ if (ror_nbh != right_nbh
+ && output(ror_nbh) == right_nbh)
{
+ // Distance between the current line and the right neighbor
+ const float right_distance = lines(l).meanline() - lines(right_nbh).baseline();
+ // Distance between the right neighbor and the ror
+ const float ror_distance = lines(right_nbh).meanline() - lines(ror_nbh).baseline();
+ // ror x_height
+ const float ror_x_height = lines(ror_nbh).x_height();
+
+ // Conditions to cut the link between the current line
+ // and its right neighbor
+ if (right_distance > 1.4f * ror_distance
+ && std::max(ror_x_height, right_x_height) <
+ 1.2f * std::min(ror_x_height, right_x_height)
+ && output(right_nbh) == l)
+ {
output(right_nbh) = right_nbh;
continue;
+ }
}
- }
- // Otherwise we only have a group of two lines
- else
- {
- // We determine the distance between the two lines
- const float distance = lines(l).meanline() - lines(right_nbh).baseline();
- two_lines = true;
-
- // If the distance between the two lines is greater than
- // the minimum x height of the two lines then we cut the
- // link between them
- if (distance > 2.0f * std::min(x_height, right_x_height)
- && output(right_nbh) == l)
+ // Otherwise we only have a group of two lines
+ else
{
+ // We determine the distance between the two lines
+ const float distance = lines(l).meanline() - lines(right_nbh).baseline();
+ two_lines = true;
+
+ // If the distance between the two lines is greater than
+ // the minimum x height of the two lines then we cut the
+ // link between them
+ if (distance > 2.0f * std::min(x_height, right_x_height)
+ && output(right_nbh) == l)
+ {
output(right_nbh) = right_nbh;
continue;
+ }
}
- }
- // Lines features
- const float min_x_height = std::min(x_height, right_x_height);
- const float max_x_height = std::max(x_height, right_x_height);
- const float min_char_width = std::min(rline_cw, cline_cw);
- const float max_char_width = std::max(rline_cw, cline_cw);
+ // Lines features
+ const float min_x_height = std::min(x_height, right_x_height);
+ const float max_x_height = std::max(x_height, right_x_height);
+ const float min_char_width = std::min(rline_cw, cline_cw);
+ const float max_char_width = std::max(rline_cw, cline_cw);
- // Condition to cut the link between the current line and
- // its right neighbor
- if ((max_x_height > min_x_height * 1.2f) &&
- !(max_char_width <= 1.2f * min_char_width))
- {
- if (output(right_nbh) == l)
+ // Condition to cut the link between the current line and
+ // its right neighbor
+ if ((max_x_height > min_x_height * 1.2f) &&
+ !(max_char_width <= 1.2f * min_char_width))
{
- output(right_nbh) = right_nbh;
- continue;
+ if (output(right_nbh) == l)
+ {
+ output(right_nbh) = right_nbh;
+ continue;
+ }
}
- }
-
- // If we only have two lines we stop the study
- if (two_lines)
- continue;
- }
- // If the current line has no right neighbor
- else if (rc_baseline == 0)
- {
- // lol : left neighbor of the left neighbor
- // If the left neighbor of the current line has a left neighbor
- if (lol_nbh != left_nbh)
+ // If we only have two lines we stop the study
+ if (two_lines)
+ continue;
+ }
+ // If the current line has no right neighbor
+ else if (rc_baseline == 0)
{
- // Distance between the current line and its left neighbor
- const float left_distance = lines(left_nbh).meanline() -
- lines(l).baseline();
- // Distance between the left neighbor and the left
- // neighbor of its left neighbor
- const float lol_distance = lines(lol_nbh).meanline() -
- lines(left_nbh).baseline();
- // lol x height
- const float lol_x_height = lines(lol_nbh).x_height();
-
- // Conditions to cut the link between the current line
- // and its left neighbor
- if (left_distance > 1.4f * lol_distance
- && std::max(lol_x_height, left_x_height) <
- 1.2f * std::min(lol_x_height, left_x_height))
+ // lol : left neighbor of the left neighbor
+
+ // If the left neighbor of the current line has a left neighbor
+ if (lol_nbh != left_nbh)
{
+ // Distance between the current line and its left neighbor
+ const float left_distance = lines(left_nbh).meanline() -
+ lines(l).baseline();
+ // Distance between the left neighbor and the left
+ // neighbor of its left neighbor
+ const float lol_distance = lines(lol_nbh).meanline() -
+ lines(left_nbh).baseline();
+ // lol x height
+ const float lol_x_height = lines(lol_nbh).x_height();
+
+ // Conditions to cut the link between the current line
+ // and its left neighbor
+ if (left_distance > 1.4f * lol_distance
+ && std::max(lol_x_height, left_x_height) <
+ 1.2f * std::min(lol_x_height, left_x_height))
+ {
output(l) = l;
continue;
+ }
}
- }
- // Otherwise we only have a group of two lines
- else
- {
- // Distance between the current line and it left neighbor
- const float distance = lines(left_nbh).meanline() -
- lines(l).baseline();
+ // Otherwise we only have a group of two lines
+ else
+ {
+ // Distance between the current line and it left neighbor
+ const float distance = lines(left_nbh).meanline() -
+ lines(l).baseline();
- two_lines = true;
+ two_lines = true;
- // If the distance is greater than the min x height
- // between the two lines
- if (distance > 2.0f * std::min(x_height, left_x_height))
- {
+ // If the distance is greater than the min x height
+ // between the two lines
+ if (distance > 2.0f * std::min(x_height, left_x_height))
+ {
output(l) = l;
continue;
+ }
}
- }
-
- // Lines features
- const float min_x_height = std::min(x_height, left_x_height);
- const float max_x_height = std::max(x_height, left_x_height);
- const float min_char_width = std::min(lline_cw, cline_cw);
- const float max_char_width = std::max(lline_cw, cline_cw);
-
- // Condition to cut the link between the current line and
- // its left neighbor
- if ((max_x_height > min_x_height * 1.2f) &&
- !(max_char_width <= 1.2f * min_char_width))
- {
- output(l) = l;
- continue;
- }
- // If we only have two lines we stop the study
- if (two_lines)
- continue;
- }
- // The current line has at least one left and one right neighbor
- else // if (delta_baseline_max >= delta_baseline_min)
- {
- // Distance between the left and the current line
- const float left_distance =
- lines(left_nbh).meanline() - lines(l).baseline();
- // Distance between the right and the current line
- const float right_distance =
- lines(l).meanline() - lines(right_nbh).baseline();
-
- // If the left line is too far compared to the right one
- // we cut the link with it
- if (left_distance > 1.2f * right_distance
- && std::max(x_height, left_x_height) > 1.2f * std::min(x_height, left_x_height))
- {
- output(l) = l;
- continue;
- }
- // If the right line is too far compared to the left one
- // we cut the link with it
- else if (right_distance > 1.2f * left_distance
- && std::max(x_height, right_x_height) > 1.2f * std::min(x_height, right_x_height)
- && output(right_nbh) == l)
- {
- output(right_nbh) = right_nbh;
- continue;
- }
-
- // If the distance between the baseline of the left
- // neighbor and the baseline of the current line is
- // greater than the one between the current line baseline
- // and the right line baseline we have to study the texte
- // features of the right and left lines
- if (lc_baseline > rc_baseline)
- {
- const float cw_max = std::max(lline_cw, cline_cw);
- const float cw_min = std::min(lline_cw, cline_cw);
+ // Lines features
const float min_x_height = std::min(x_height, left_x_height);
const float max_x_height = std::max(x_height, left_x_height);
+ const float min_char_width = std::min(lline_cw, cline_cw);
+ const float max_char_width = std::max(lline_cw, cline_cw);
+ // Condition to cut the link between the current line and
+ // its left neighbor
if ((max_x_height > min_x_height * 1.2f) &&
- !(cw_max <= 1.2f * cw_min))
+ !(max_char_width <= 1.2f * min_char_width))
{
output(l) = l;
continue;
}
+ // If we only have two lines we stop the study
+ if (two_lines)
+ continue;
+ }
+ // The current line has at least one left and one right neighbor
+ else // if (delta_baseline_max >= delta_baseline_min)
+ {
+ // Distance between the left and the current line
+ const float left_distance =
+ lines(left_nbh).meanline() - lines(l).baseline();
+ // Distance between the right and the current line
+ const float right_distance =
+ lines(l).meanline() - lines(right_nbh).baseline();
+
+ // If the left line is too far compared to the right one
+ // we cut the link with it
+ if (left_distance > 1.2f * right_distance
+ && std::max(x_height, left_x_height) > 1.2f * std::min(x_height, left_x_height))
+ {
+ output(l) = l;
+ continue;
+ }
+ // If the right line is too far compared to the left one
+ // we cut the link with it
+ else if (right_distance > 1.2f * left_distance
+ && std::max(x_height, right_x_height) > 1.2f * std::min(x_height, right_x_height)
+ && output(right_nbh) == l)
+ {
+ output(right_nbh) = right_nbh;
+ continue;
+ }
+
+ // If the distance between the baseline of the left
+ // neighbor and the baseline of the current line is
+ // greater than the one between the current line baseline
+ // and the right line baseline we have to study the texte
+ // features of the right and left lines
+ if (lc_baseline > rc_baseline)
+ {
+ const float cw_max = std::max(lline_cw, cline_cw);
+ const float cw_min = std::min(lline_cw, cline_cw);
+ const float min_x_height = std::min(x_height, left_x_height);
+ const float max_x_height = std::max(x_height, left_x_height);
+
+ if ((max_x_height > min_x_height * 1.2f) &&
+ !(cw_max <= 1.2f * cw_min))
+ {
+ output(l) = l;
+ continue;
+ }
+
+ {
+ const float min_x_height = std::min(x_height, right_x_height);
+ const float max_x_height = std::max(x_height, right_x_height);
+ const float cw_max = std::max(rline_cw, cline_cw);
+ const float cw_min = std::min(rline_cw, cline_cw);
+
+ if ((max_x_height > min_x_height * 1.2f)
+ && !(cw_max <= 1.2f * cw_min)
+ && output(right_nbh) == l)
+ {
+ output(right_nbh) = right_nbh;
+ continue;
+ }
+ }
+ }
+ else
{
- const float min_x_height = std::min(x_height, right_x_height);
- const float max_x_height = std::max(x_height, right_x_height);
const float cw_max = std::max(rline_cw, cline_cw);
const float cw_min = std::min(rline_cw, cline_cw);
+ const float min_x_height = std::min(x_height, right_x_height);
+ const float max_x_height = std::max(x_height, right_x_height);
if ((max_x_height > min_x_height * 1.2f)
&& !(cw_max <= 1.2f * cw_min)
@@ -321,44 +340,28 @@ namespace scribo
output(right_nbh) = right_nbh;
continue;
}
- }
- }
- else
- {
- const float cw_max = std::max(rline_cw, cline_cw);
- const float cw_min = std::min(rline_cw, cline_cw);
- const float min_x_height = std::min(x_height, right_x_height);
- const float max_x_height = std::max(x_height, right_x_height);
- if ((max_x_height > min_x_height * 1.2f)
- && !(cw_max <= 1.2f * cw_min)
- && output(right_nbh) == l)
- {
- output(right_nbh) = right_nbh;
- continue;
- }
-
- {
- const float min_x_height = std::min(x_height, left_x_height);
- const float max_x_height = std::max(x_height, left_x_height);
- const float cw_max = std::max(lline_cw, cline_cw);
- const float cw_min = std::min(lline_cw, cline_cw);
-
- if ((max_x_height > min_x_height * 1.2f)
- && !(cw_max <= 1.2f * cw_min))
{
- output(l) = l;
- continue;
+ const float min_x_height = std::min(x_height, left_x_height);
+ const float max_x_height = std::max(x_height, left_x_height);
+ const float cw_max = std::max(lline_cw, cline_cw);
+ const float cw_min = std::min(lline_cw, cline_cw);
+
+ if ((max_x_height > min_x_height * 1.2f)
+ && !(cw_max <= 1.2f * cw_min))
+ {
+ output(l) = l;
+ continue;
+ }
}
}
}
}
- }
- // If we arrive here, it means than the lines in the
- // neighborhood of the current line are quite similar. We can
- // then begin to study the indentations in order to determine
- // the beginning of new paragraphs
+ // If we arrive here, it means than the lines in the
+ // neighborhood of the current line are quite similar. We can
+ // then begin to study the indentations in order to determine
+ // the beginning of new paragraphs
//-----------------------------------------------------------------------------
// ___________________________
@@ -375,35 +378,35 @@ namespace scribo
//
//-----------------------------------------------------------------------------
- {
- // Check if the current line neighbors are aligned
- bool left_right_aligned = false;
- bool left_lol_aligned = false;
- const int dx_lr = std::abs(lline_col_min - rline_col_min);
- const int dx_llol = std::abs(lline_col_min - lolline_col_min);
+ {
+ // Check if the current line neighbors are aligned
+ bool left_right_aligned = false;
+ bool left_lol_aligned = false;
+ const int dx_lr = std::abs(lline_col_min - rline_col_min);
+ const int dx_llol = std::abs(lline_col_min - lolline_col_min);
- if (dx_lr < delta_alignment)
- left_right_aligned = true;
+ if (dx_lr < delta_alignment)
+ left_right_aligned = true;
- if (dx_llol < delta_alignment)
- left_lol_aligned = true;
+ if (dx_llol < delta_alignment)
+ left_lol_aligned = true;
- if (left_right_aligned && left_lol_aligned)
- {
- const int left_right_col_min = std::min(lline_col_min, rline_col_min);
- const int dx_lrc = std::abs(left_right_col_min - cline_col_min);
- const float l_char_width = 1.5f * lines(l).char_width();
-
- if (dx_lrc > l_char_width &&
- dx_lrc < 3.0f * l_char_width &&
- cline_col_min > rline_col_min &&
- cline_col_min > lline_col_min)
+ if (left_right_aligned && left_lol_aligned)
{
- output(right_nbh) = right_nbh;
- continue;
+ const int left_right_col_min = std::min(lline_col_min, rline_col_min);
+ const int dx_lrc = std::abs(left_right_col_min - cline_col_min);
+ const float l_char_width = 1.5f * lines(l).char_width();
+
+ if (dx_lrc > l_char_width &&
+ dx_lrc < 3.0f * l_char_width &&
+ cline_col_min > rline_col_min &&
+ cline_col_min > lline_col_min)
+ {
+ output(right_nbh) = right_nbh;
+ continue;
+ }
}
}
- }
//-----------------------------------------------------------------------------
// ___________________________
@@ -419,41 +422,41 @@ namespace scribo
//
//-----------------------------------------------------------------------------
- {
- // Check if the current line neighbors are aligned
- bool left_right_max_aligned = false;
- bool left_current_min_aligned = false;
- bool lol_current_min_aligned = false;
- const bool lol_is_left = output(left_nbh) == left_nbh;
- const int dx_lr_max = std::abs(lline_col_max - rline_col_max);
- const int dx_lc_min = std::abs(lline_col_min - cline_col_min);
- const int dx_lolc_min = std::abs(lolline_col_min - cline_col_min);
-
- if (dx_lr_max < delta_alignment)
- left_right_max_aligned = true;
-
- if (dx_lc_min < delta_alignment)
- left_current_min_aligned = true;
-
- if (dx_lolc_min < delta_alignment)
- lol_current_min_aligned = true;
-
- if (!left_current_min_aligned && left_right_max_aligned &&
- (lol_current_min_aligned || lol_is_left))
{
- const int dx_lrc = std::abs(lline_col_max - cline_col_max);
- const int l_char_width = lines(l).char_width();
-
- if (dx_lrc > l_char_width &&
- cline_col_max < lline_col_max &&
- cline_col_min < lline_col_min &&
- (lline_col_min > lolline_col_min || lol_is_left))
+ // Check if the current line neighbors are aligned
+ bool left_right_max_aligned = false;
+ bool left_current_min_aligned = false;
+ bool lol_current_min_aligned = false;
+ const bool lol_is_left = output(left_nbh) == left_nbh;
+ const int dx_lr_max = std::abs(lline_col_max - rline_col_max);
+ const int dx_lc_min = std::abs(lline_col_min - cline_col_min);
+ const int dx_lolc_min = std::abs(lolline_col_min - cline_col_min);
+
+ if (dx_lr_max < delta_alignment)
+ left_right_max_aligned = true;
+
+ if (dx_lc_min < delta_alignment)
+ left_current_min_aligned = true;
+
+ if (dx_lolc_min < delta_alignment)
+ lol_current_min_aligned = true;
+
+ if (!left_current_min_aligned && left_right_max_aligned &&
+ (lol_current_min_aligned || lol_is_left))
{
- output(l) = l;
- continue;
+ const int dx_lrc = std::abs(lline_col_max - cline_col_max);
+ const int l_char_width = lines(l).char_width();
+
+ if (dx_lrc > l_char_width &&
+ cline_col_max < lline_col_max &&
+ cline_col_min < lline_col_min &&
+ (lline_col_min > lolline_col_min || lol_is_left))
+ {
+ output(l) = l;
+ continue;
+ }
}
}
- }
//-----------------------------------------------------------------------------
@@ -469,68 +472,69 @@ namespace scribo
//
//-----------------------------------------------------------------------------
- if (left_nbh == l)
- {
- const value::int_u16 ror_nbh = right(right_nbh);
- const box2d& ror_line_bbox = lines(ror_nbh).bbox();
- const int rorline_col_min = ror_line_bbox.pmin().col();
+ if (left_nbh == l)
+ {
+ const line_id_t ror_nbh = right(right_nbh);
+ const box2d& ror_line_bbox = lines(ror_nbh).bbox();
+ const int rorline_col_min = ror_line_bbox.pmin().col();
- bool right_ror_min_aligned = false;
- const int dx_rror_min = std::abs(rline_col_min - rorline_col_min);
+ bool right_ror_min_aligned = false;
+ const int dx_rror_min = std::abs(rline_col_min - rorline_col_min);
- if (dx_rror_min < delta_alignment)
- right_ror_min_aligned = true;
+ if (dx_rror_min < delta_alignment)
+ right_ror_min_aligned = true;
- if (right_ror_min_aligned)
- {
- const int right_ror_col_min = std::min(rline_col_min, rorline_col_min);
- const int dx_rrorc = std::abs(right_ror_col_min - cline_col_min);
- const float l_char_width = 1.5f * lines(l).char_width();
-
- if (dx_rrorc > l_char_width &&
- dx_rrorc < 3.0f * l_char_width &&
- cline_col_min > rline_col_min &&
- cline_col_max >= rline_col_max)
+ if (right_ror_min_aligned)
{
- output(right_nbh) = right_nbh;
- continue;
+ const int right_ror_col_min = std::min(rline_col_min, rorline_col_min);
+ const int dx_rrorc = std::abs(right_ror_col_min - cline_col_min);
+ const float l_char_width = 1.5f * lines(l).char_width();
+
+ if (dx_rrorc > l_char_width &&
+ dx_rrorc < 3.0f * l_char_width &&
+ cline_col_min > rline_col_min &&
+ cline_col_max >= rline_col_max)
+ {
+ output(right_nbh) = right_nbh;
+ continue;
+ }
}
}
}
- }
// Only debug
- {
- image2d<value::rgb8> debug = data::convert(value::rgb8(), input);
-
- for (unsigned i = 0; i < output.nelements(); ++i)
- output(i) = internal::find_root(output, i);
-
- mln::util::array<accu::shape::bbox<point2d> > nbbox(output.nelements());
- for (unsigned i = 0; i < nlines; ++i)
- {
- // if (lines(i).is_textline())
- // {
- // mln::draw::box(debug, lines(i).bbox(), literal::red);
- nbbox(output(i)).take(lines(i).bbox());
- // }
- }
-
- for (unsigned i = 0; i < nbbox.nelements(); ++i)
- if (nbbox(i).is_valid())
- {
- box2d b = nbbox(i).to_result();
- mln::draw::box(debug, b, literal::orange);
- b.enlarge(1);
- mln::draw::box(debug, b, literal::orange);
- b.enlarge(1);
- mln::draw::box(debug, b, literal::orange);
- }
-
- mln::io::ppm::save(debug, "out_paragraph.ppm");
- }
+ // {
+ // image2d<value::rgb8> debug = data::convert(value::rgb8(), input);
+
+ // for (unsigned i = 0; i < output.nelements(); ++i)
+ // output(i) = scribo::make::internal::find_root(output, i);
+
+ // mln::util::array<accu::shape::bbox<point2d> > nbbox(output.nelements());
+ // for_all_lines(l, lines)
+ // if (lines(l).is_textline())
+ // {
+ // // if (lines(i).is_textline())
+ // // {
+ // // mln::draw::box(debug, lines(i).bbox(), literal::red);
+ // nbbox(output(l)).take(lines(l).bbox());
+ // // }
+ // }
+
+ // for (unsigned i = 0; i < nbbox.nelements(); ++i)
+ // if (nbbox(i).is_valid())
+ // {
+ // box2d b = nbbox(i).to_result();
+ // mln::draw::box(debug, b, literal::orange);
+ // b.enlarge(1);
+ // mln::draw::box(debug, b, literal::orange);
+ // b.enlarge(1);
+ // mln::draw::box(debug, b, literal::orange);
+ // }
+
+ // mln::io::ppm::save(debug, "out_paragraph.ppm");
+ // }
}
}
@@ -547,262 +551,269 @@ namespace scribo
template <typename L>
inline
void prepare_lines(const box2d& domain,
- const util::array< line_info<L> >& lines,
- image2d<value::int_u16>& blocks,
+ const line_set<L>& lines,
+ L& blocks,
util::array<box2d>& rbbox)
{
std::map< int, std::vector< const box2d* > > drawn_lines;
- const unsigned nlines = lines.nelements();
+ // const unsigned nlines = lines.nelements();
// For each line
- for (unsigned l = 0; l < nlines; ++l)
- {
- // Rotation of the bounding box
- box2d b = geom::rotate(lines(l).bbox(), -90, domain.pcenter());
- rbbox.append(b);
-
- const unsigned index = l + 1;
- const unsigned even_index = 2 * index;
- const unsigned odd_index = even_index + 1;
-
- // Top of the line
+ //for (unsigned l = 0; l < nlines; ++l)
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
{
- bool not_finished = true;
- int col_offset = 0;
+ // Rotation of the bounding box
+ box2d b = geom::rotate(lines(l).bbox(), -90, domain.pcenter());
+// rbbox.append(b);
+ rbbox(l) = b;
- while (not_finished)
- {
- // Looking for a column in the image to draw the top of the
- // line
+ const unsigned index = l + 1;
+ const unsigned even_index = 2 * index;
+ const unsigned odd_index = even_index + 1;
- const int col = b.pmax().col() + col_offset;
- std::map< int, std::vector< const box2d* > >::iterator it
- = drawn_lines.find(col);
+ // Top of the line
+ {
+ bool not_finished = true;
+ int col_offset = 0;
- if (it != drawn_lines.end())
+ while (not_finished)
{
- const std::vector< const box2d* >& lines = (*it).second;
- const unsigned nb_lines = lines.size();
- unsigned i = 0;
+ // Looking for a column in the image to draw the top of the
+ // line
+
+ const int col = b.pmax().col() + col_offset;
+ std::map< int, std::vector< const box2d* > >::iterator it
+ = drawn_lines.find(col);
- for (i = 0; i < nb_lines; ++i)
+ if (it != drawn_lines.end())
{
- const box2d* box = lines[i];
- const int min_row = std::max(b.pmin().row(), box->pmin().row());
- const int max_row = std::min(b.pmax().row(), box->pmax().row());
+ const std::vector< const box2d* >& lines = (*it).second;
+ const unsigned nb_lines = lines.size();
+ unsigned i = 0;
- if (min_row - max_row <= 0)
- break;
- }
+ for (i = 0; i < nb_lines; ++i)
+ {
+ const box2d* box = lines[i];
+ const int min_row = std::max(b.pmin().row(), box->pmin().row());
+ const int max_row = std::min(b.pmax().row(), box->pmax().row());
- if (i == nb_lines)
+ if (min_row - max_row <= 0)
+ break;
+ }
+
+ if (i == nb_lines)
+ {
+ mln::draw::line(blocks, point2d(b.pmin().row(), col),
+ point2d(b.pmax().row(), col), even_index);
+ not_finished = false;
+ drawn_lines[col].push_back(&(rbbox[l]));
+ }
+ else
+ ++col_offset;
+ }
+ else
{
mln::draw::line(blocks, point2d(b.pmin().row(), col),
point2d(b.pmax().row(), col), even_index);
not_finished = false;
drawn_lines[col].push_back(&(rbbox[l]));
}
- else
- ++col_offset;
- }
- else
- {
- mln::draw::line(blocks, point2d(b.pmin().row(), col),
- point2d(b.pmax().row(), col), even_index);
- not_finished = false;
- drawn_lines[col].push_back(&(rbbox[l]));
}
}
- }
- // Bottom of the line
- {
- bool not_finished = true;
- int col_offset = 0;
-
- while (not_finished)
+ // Bottom of the line
{
- // Looking for a column in the image to draw the bottom of
- // the line
+ bool not_finished = true;
+ int col_offset = 0;
- const int col = b.pmin().col() - col_offset;
- std::map< int, std::vector< const box2d* > >::iterator it
- = drawn_lines.find(col);
-
- if (it != drawn_lines.end())
+ while (not_finished)
{
- const std::vector< const box2d* >& lines = (*it).second;
- const unsigned nb_lines = lines.size();
- unsigned i = 0;
+ // Looking for a column in the image to draw the bottom of
+ // the line
+
+ const int col = b.pmin().col() - col_offset;
+ std::map< int, std::vector< const box2d* > >::iterator it
+ = drawn_lines.find(col);
- for (i = 0; i < nb_lines; ++i)
+ if (it != drawn_lines.end())
{
- const box2d* box = lines[i];
- const int min_row = std::max(b.pmin().row(), box->pmin().row());
- const int max_row = std::min(b.pmax().row(), box->pmax().row());
+ const std::vector< const box2d* >& lines = (*it).second;
+ const unsigned nb_lines = lines.size();
+ unsigned i = 0;
- if (min_row - max_row <= 0)
- break;
- }
+ for (i = 0; i < nb_lines; ++i)
+ {
+ const box2d* box = lines[i];
+ const int min_row = std::max(b.pmin().row(), box->pmin().row());
+ const int max_row = std::min(b.pmax().row(), box->pmax().row());
- if (i == nb_lines)
+ if (min_row - max_row <= 0)
+ break;
+ }
+
+ if (i == nb_lines)
+ {
+ mln::draw::line(blocks, point2d(b.pmin().row(), col),
+ point2d(b.pmax().row(), col), odd_index);
+ not_finished = false;
+ drawn_lines[col].push_back(&(rbbox[l]));
+ }
+ else
+ ++col_offset;
+ }
+ else
{
mln::draw::line(blocks, point2d(b.pmin().row(), col),
point2d(b.pmax().row(), col), odd_index);
not_finished = false;
drawn_lines[col].push_back(&(rbbox[l]));
}
- else
- ++col_offset;
- }
- else
- {
- mln::draw::line(blocks, point2d(b.pmin().row(), col),
- point2d(b.pmax().row(), col), odd_index);
- not_finished = false;
- drawn_lines[col].push_back(&(rbbox[l]));
}
}
}
- }
}
template <typename L>
inline
void
- process_left_link(image2d<value::int_u16>& blocks,
+ process_left_link(L& blocks,
const util::array<box2d>& rbbox,
- const util::array< line_info<L> >& lines,
- util::array<value::int_u16>& left)
+ const line_set<L>& lines,
+ line_links<L>& left)
{
- typedef value::int_u16 V;
+ typedef scribo::def::lbl_type V;
// At the beginning each line is its own neighbor
- for (unsigned i = 0; i < left.nelements(); ++i)
- left(i) = i;
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
+ left(l) = l;
+ else
+ left(l) = 0;
- const unsigned nlines = lines.nelements();
+ // const unsigned nlines = lines.nelements();
// For each line
- for (unsigned i = 0; i < nlines; ++i)
- {
- // Max distance for the line search
- int dmax = 1.5f * lines(i).x_height();
-
- // Starting points in the current line box
- point2d c = rbbox(i).pcenter();
- point2d q(rbbox(i).pmin().row() + ((c.row() - rbbox(i).pmin().row()) / 4), c.col());
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
+ {
+ // Max distance for the line search
+ int dmax = 1.5f * lines(l).x_height();
- int
- midcol = (rbbox(i).pmax().col()
- - rbbox(i).pmin().col()) / 2;
+ // Starting points in the current line box
+ point2d c = rbbox(l).pcenter();
+ point2d q(rbbox(l).pmin().row() + ((c.row() - rbbox(l).pmin().row()) / 4), c.col());
- // Left
- {
- // marge gauche
int
- nleftima = c.col() - blocks.domain().pmin().col(),
- // Distance gauche
- nleft = std::min(nleftima, midcol + dmax);
-
- V
- // Starting points in the box
- *p = &blocks(c),
- *p2 = &blocks(q),
- // End of search
- *pstop = p - nleft - 1,
- // Line neighbor
- *nbh_p = 0;
-
- // While we haven't found a neighbor or reached the limit
- for (; p != pstop; --p, --p2)
+ midcol = (rbbox(l).pmax().col()
+ - rbbox(l).pmin().col()) / 2;
+
+ // Left
{
- if (*p2 != literal::zero // Not the background
- && ((*p2 % 2) == 0) // Looking for the bottom of a line
- && left((*p2 >> 1) - 1) != i) // No loops
+ // marge gauche
+ int
+ nleftima = c.col() - blocks.domain().pmin().col(),
+ // Distance gauche
+ nleft = std::min(nleftima, midcol + dmax);
+
+ V
+ // Starting points in the box
+ *p = &blocks(c),
+ *p2 = &blocks(q),
+ // End of search
+ *pstop = p - nleft - 1,
+ // Line neighbor
+ *nbh_p = 0;
+
+ // While we haven't found a neighbor or reached the limit
+ for (; p != pstop; --p, --p2)
{
- // Neightbor found, we stop the research
- nbh_p = p2;
- break;
- }
+ if (*p2 != literal::zero // Not the background
+ && ((*p2 % 2) == 0) // Looking for the bottom of a line
+ && left((*p2 >> 1) - 1) != l) // No loops
+ {
+ // Neightbor found, we stop the research
+ nbh_p = p2;
+ break;
+ }
- if (*p != literal::zero // Not the background
- && ((*p % 2) == 0) // Looking for the bottom of a line
- && left((*p >> 1) - 1) != i) // No loops
- {
- // Neightbor found, we stop the research
- nbh_p = p;
- break;
+ if (*p != literal::zero // Not the background
+ && ((*p % 2) == 0) // Looking for the bottom of a line
+ && left((*p >> 1) - 1) != l) // No loops
+ {
+ // Neightbor found, we stop the research
+ nbh_p = p;
+ break;
+ }
}
- }
-
- // If a neighbor was found, then we have found the top of the
- // line. We are then looking for the bottom of the encountered
- // line. If during the search process we find a complete line
- // included in the touched line, this line is considered as
- // the neighbor under certain conditions (see below)
-
- //---------------------------------------------------------------
- // _________________________ |
- // |_________________________| => Current line | Search direction
- // v
- // => First encountered top line
- // __________________________________________________ 2Q
- // | Q |
- // | _________________________ |2P
- // | |_____________P___________| => Second top |2P + 1
- // | line |
- // |__________________________________________________|2Q + 1
- //
- //
- //---------------------------------------------------------------
-
- if (nbh_p)
- {
- std::vector<V> lines_nbh;
- const V end_p = *nbh_p + 1;
- const V* nbh_p_copy = nbh_p;
- for (; *nbh_p != end_p; --nbh_p)
+ // If a neighbor was found, then we have found the top of the
+ // line. We are then looking for the bottom of the encountered
+ // line. If during the search process we find a complete line
+ // included in the touched line, this line is considered as
+ // the neighbor under certain conditions (see below)
+
+ //---------------------------------------------------------------
+ // _________________________ |
+ // |_________________________| => Current line | Search direction
+ // v
+ // => First encountered top line
+ // __________________________________________________ 2Q
+ // | Q |
+ // | _________________________ |2P
+ // | |_____________P___________| => Second top |2P + 1
+ // | line |
+ // |__________________________________________________|2Q + 1
+ //
+ //
+ //---------------------------------------------------------------
+
+ if (nbh_p)
{
- if ((*nbh_p) != literal::zero) // Not the background
+ std::vector<V> lines_nbh;
+ const V end_p = *nbh_p + 1;
+ const V* nbh_p_copy = nbh_p;
+
+ for (; *nbh_p != end_p; --nbh_p)
{
- if ((*nbh_p) % 2 == 0)// We have found the top of
- // another line
- lines_nbh.push_back(*nbh_p);
- else
+ if ((*nbh_p) != literal::zero) // Not the background
{
- // We have found the bottom of a line. We are looking if
- // we have already encountered the top of this
- // line. If so, we link the current line with this one
- // under certain conditions:
-
- if (std::find(lines_nbh.begin(), lines_nbh.end(),
- (*nbh_p) - 1) != lines_nbh.end())
+ if ((*nbh_p) % 2 == 0)// We have found the top of
+ // another line
+ lines_nbh.push_back(*nbh_p);
+ else
{
- // If we can link the complete line with the current line
- if (// It must be in the search range
- nbh_p > pstop
- // Avoid loops
- && left(((*nbh_p - 1) >> 1) - 1) != i)
- left(i) = ((*nbh_p - 1) >> 1) - 1;
-
- // We have found a complete line so we stop the search
- break;
+ // We have found the bottom of a line. We are looking if
+ // we have already encountered the top of this
+ // line. If so, we link the current line with this one
+ // under certain conditions:
+
+ if (std::find(lines_nbh.begin(), lines_nbh.end(),
+ (*nbh_p) - 1) != lines_nbh.end())
+ {
+ // If we can link the complete line with the current line
+ if (// It must be in the search range
+ nbh_p > pstop
+ // Avoid loops
+ && left(((*nbh_p - 1) >> 1) - 1) != l)
+ left(l) = ((*nbh_p - 1) >> 1) - 1;
+
+ // We have found a complete line so we stop the search
+ break;
+ }
}
}
}
- }
- // If we haven't found any included line in the first
- // neighbor, then the line is considered as the neighbor of
- // the current line
- if (*nbh_p == end_p)
- left(i) = (*nbh_p_copy >> 1) - 1;
+ // If we haven't found any included line in the first
+ // neighbor, then the line is considered as the neighbor of
+ // the current line
+ if (*nbh_p == end_p)
+ left(l) = (*nbh_p_copy >> 1) - 1;
+ }
}
}
- }
}
@@ -810,137 +821,141 @@ namespace scribo
template <typename L>
inline
void
- process_right_link(image2d<value::int_u16>& blocks,
+ process_right_link(L& blocks,
const util::array<box2d>& rbbox,
- const util::array< line_info<L> >& lines,
- util::array<value::int_u16>& right)
+ const line_set<L>& lines,
+ line_links<L>& right)
{
- typedef value::int_u16 V;
+ typedef scribo::def::lbl_type V;
// At the beginning each line is its own neighbor
- for (unsigned i = 0; i < right.nelements(); ++i)
- right(i) = i;
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
+ right(l) = l;
+ else
+ right(l) = 0;
- const unsigned nlines = lines.nelements();
+ // const unsigned nlines = lines.nelements();
// For each line
- for (unsigned i = 0; i < nlines; ++i)
- {
- // Max distance for the line search
- int dmax = 1.5f * lines(i).x_height();
-
- // Starting points in the current line box
- point2d c = rbbox(i).pcenter();
- point2d q(rbbox(i).pmax().row() - ((rbbox(i).pmax().row() - c.row()) / 4), c.col());
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
+ {
+ // Max distance for the line search
+ int dmax = 1.5f * lines(l).x_height();
- int
- midcol = (rbbox(i).pmax().col()
- - rbbox(i).pmin().col()) / 2;
+ // Starting points in the current line box
+ point2d c = rbbox(l).pcenter();
+ point2d q(rbbox(l).pmax().row() - ((rbbox(l).pmax().row() - c.row()) / 4), c.col());
- // Right
- {
int
- nrightima = geom::ncols(blocks) - c.col() + blocks.domain().pmin().col(),
- nright = std::min(nrightima, midcol + dmax);
-
- V
- // Starting points in the box
- *p = &blocks(c),
- *p2 = &blocks(q),
- // End of search
- *pstop = p + nright - 1,
- // Line neighbor
- *nbh_p = 0;
-
- // While we haven't found a neighbor or reached the limit
- for (; p != pstop; ++p, ++p2)
+ midcol = (rbbox(l).pmax().col()
+ - rbbox(l).pmin().col()) / 2;
+
+ // Right
{
- if (*p2 != literal::zero // Not the background
- && ((*p2 % 2) == 1) // Looking for the bottom of a line
- && right(((*p2 - 1) >> 1) - 1) != i) // No loops
+ int
+ nrightima = geom::ncols(blocks) - c.col() + blocks.domain().pmin().col(),
+ nright = std::min(nrightima, midcol + dmax);
+
+ V
+ // Starting points in the box
+ *p = &blocks(c),
+ *p2 = &blocks(q),
+ // End of search
+ *pstop = p + nright - 1,
+ // Line neighbor
+ *nbh_p = 0;
+
+ // While we haven't found a neighbor or reached the limit
+ for (; p != pstop; ++p, ++p2)
{
- // Neightbor found, we stop the research
- nbh_p = p2;
- break;
- }
+ if (*p2 != literal::zero // Not the background
+ && ((*p2 % 2) == 1) // Looking for the bottom of a line
+ && right(((*p2 - 1) >> 1) - 1) != l) // No loops
+ {
+ // Neightbor found, we stop the research
+ nbh_p = p2;
+ break;
+ }
- if (*p != literal::zero // Not the background
- && ((*p % 2) == 1) // Looking for the bottom of a line
- && right(((*p - 1) >> 1) - 1) != i) // No loops
- {
- // Neightbor found, we stop the research
- nbh_p = p;
- break;
+ if (*p != literal::zero // Not the background
+ && ((*p % 2) == 1) // Looking for the bottom of a line
+ && right(((*p - 1) >> 1) - 1) != l) // No loops
+ {
+ // Neightbor found, we stop the research
+ nbh_p = p;
+ break;
+ }
}
- }
-
- // If a neighbor was found, then we have found the bottom of the
- // line. We are then looking for the top of the encountered
- // line. If during the search process we find a complete line
- // included in the touched line, this line is considered as
- // the neighbor under certain conditions (see below)
-
- //---------------------------------------------------------------
- //
- //
- // __________________________________________________ 2Q
- // | Q |
- // | _________________________ |2P
- // | |_____________P___________| => Second bottom |2P + 1
- // | line |
- // |__________________________________________________|2Q + 1
- // => First encountered bottom line
- // _________________________ ^
- // |_________________________| => Current line | Search direction
- // |
- //---------------------------------------------------------------
-
- if (nbh_p)
- {
- std::vector<V> lines_nbh;
- const V end_p = *nbh_p - 1;
- const V* nbh_p_copy = nbh_p;
- for (; *nbh_p != end_p; ++nbh_p)
+ // If a neighbor was found, then we have found the bottom of the
+ // line. We are then looking for the top of the encountered
+ // line. If during the search process we find a complete line
+ // included in the touched line, this line is considered as
+ // the neighbor under certain conditions (see below)
+
+ //---------------------------------------------------------------
+ //
+ //
+ // __________________________________________________ 2Q
+ // | Q |
+ // | _________________________ |2P
+ // | |_____________P___________| => Second bottom |2P + 1
+ // | line |
+ // |__________________________________________________|2Q + 1
+ // => First encountered bottom line
+ // _________________________ ^
+ // |_________________________| => Current line | Search direction
+ // |
+ //---------------------------------------------------------------
+
+ if (nbh_p)
{
- if (*nbh_p != literal::zero) // Not the background
+ std::vector<V> lines_nbh;
+ const V end_p = *nbh_p - 1;
+ const V* nbh_p_copy = nbh_p;
+
+ for (; *nbh_p != end_p; ++nbh_p)
{
- if (*nbh_p % 2 == 1) // We have found the bottom of
- // another line
- lines_nbh.push_back(*nbh_p);
- else
+ if (*nbh_p != literal::zero) // Not the background
{
- // We have found the top of a line. We are looking if
- //we have already encountered the bottom of this
- // line. If so, we link the current line with this one
- // under certain conditions:
-
- if (std::find(lines_nbh.begin(), lines_nbh.end(),
- *nbh_p + 1) != lines_nbh.end())
+ if (*nbh_p % 2 == 1) // We have found the bottom of
+ // another line
+ lines_nbh.push_back(*nbh_p);
+ else
{
- // If we can link the complete line with the current line
- if (// It must be in the search range
- nbh_p < pstop
- // Avoid loops
- && right((*nbh_p >> 1) - 1) != i)
- right(i) = (*nbh_p >> 1) - 1;
-
- // We have found a complete line, so we stop the search
- break;
+ // We have found the top of a line. We are looking if
+ //we have already encountered the bottom of this
+ // line. If so, we link the current line with this one
+ // under certain conditions:
+
+ if (std::find(lines_nbh.begin(), lines_nbh.end(),
+ *nbh_p + 1) != lines_nbh.end())
+ {
+ // If we can link the complete line with the current line
+ if (// It must be in the search range
+ nbh_p < pstop
+ // Avoid loops
+ && right((*nbh_p >> 1) - 1) != l)
+ right(l) = (*nbh_p >> 1) - 1;
+
+ // We have found a complete line, so we stop the search
+ break;
+ }
}
}
}
- }
- // If we haven't found any included line in the first
- // neighbor, then the line is considered as the neighbor of
- // the current line
+ // If we haven't found any included line in the first
+ // neighbor, then the line is considered as the neighbor of
+ // the current line
- if (*nbh_p == end_p)
- right(i) = ((*nbh_p_copy - 1) >> 1) - 1;
+ if (*nbh_p == end_p)
+ right(l) = ((*nbh_p_copy - 1) >> 1) - 1;
+ }
}
}
- }
}
//-----------------------------------------------------------------------
@@ -950,76 +965,83 @@ namespace scribo
template< typename L >
inline
- void finalize_links(util::array<value::int_u16>& left,
- util::array<value::int_u16>& right,
- const util::array< line_info<L> >& lines)
+ void finalize_links(line_links<L>& left,
+ line_links<L>& right,
+ const line_set<L>& lines)
{
- const unsigned nlines = lines.nelements();
-
- for (unsigned i = 0; i < nlines; ++i)
- {
- const unsigned left_value = left(i);
- const unsigned right_value = right(i);
+ // const unsigned nlines = lines.nelements();
- // If the right neighbor of my left neighbor is itself then its
- // right neighbor is me
+ for_all_lines(l, lines)
+ if (lines(l).is_textline())
{
- value::int_u16& v = right(left_value);
+ const unsigned left_value = left(l);
+ const unsigned right_value = right(l);
- if (v == left_value)
- v = i;
- }
+ // If the right neighbor of my left neighbor is itself then its
+ // right neighbor is me
+ {
+ line_id_t& v = right(left_value);
- // If the left neighbor of my right neighbor is itself then its
- // left neighbor is me
- {
- value::int_u16& v = left(right_value);
+ if (v == left_value)
+ v = l;
+ }
+
+ // If the left neighbor of my right neighbor is itself then its
+ // left neighbor is me
+ {
+ line_id_t& v = left(right_value);
- if (v == right_value)
- v = i;
+ if (v == right_value)
+ v = l;
+ }
}
- }
}
template <typename L>
inline
- void extract_paragraphs(line_set<L>& lines,
- const image2d<bool>& input)
+ paragraph_set<L>
+ extract_paragraphs(line_set<L>& lines,
+ const image2d<bool>& input)
{
- typedef value::int_u16 V;
+ typedef scribo::def::lbl_type V;
image2d<V> blocks(geom::rotate(input.domain(), -90, input.domain().pcenter()));
data::fill(blocks, 0);
- util::array< line_info<L> > lines_info;
+ // util::array< line_info<L> > lines_info;
- for_all_lines(l, lines)
- {
- if (lines(l).is_textline())
- lines_info.append(lines(l));
- }
+ // for_all_lines(l, lines)
+ // {
+ // if (lines(l).is_textline())
+ // lines_info.append(lines(l));
+ // }
- const unsigned nlines = lines_info.nelements();
+/// const unsigned nlines = lines_info.nelemnts();
util::array<box2d> rbbox;
- util::array<V> left(nlines);
- util::array<V> right(nlines);
- util::array<V> output;
+ line_links<L> left(lines);
+ left(0) = 0;
+ line_links<L> right(lines);
+ right(0) = 0;
+ line_links<L> output(lines);
+ output(0) = 0;
- rbbox.reserve(nlines);
- output.reserve(nlines);
+ rbbox.resize(lines.nelements() + 1);
std::cout << "Preparing lines" << std::endl;
- prepare_lines(input.domain(), lines_info, blocks, rbbox);
+ prepare_lines(input.domain(), lines , blocks, rbbox);
// io::pgm::save(blocks, "blocks.pgm");
std::cout << "Linking left" << std::endl;
- process_left_link(blocks, rbbox, lines_info, left);
+ process_left_link(blocks, rbbox, lines , left);
std::cout << "Linking right" << std::endl;
- process_right_link(blocks, rbbox, lines_info, right);
+ process_right_link(blocks, rbbox, lines , right);
std::cout << "Finalizing links" << std::endl;
- finalize_links(left, right, lines_info);
+ finalize_links(left, right, lines );
// std::cout << "Finalizing merging" << std::endl;
// finalize_line_merging(left, right, lines);
std::cout << "Extracting paragraphs" << std::endl;
- filter::paragraph_links(left, right, output, lines_info, input);
+ filter::paragraph_links(left, right, output, lines, input);
+
+ paragraph_set<L> par_set = make::paragraph(output);
+ return par_set;
}
}
diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
index 25b328b..d60f3cc 100644
--- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
@@ -60,6 +60,7 @@
# include <scribo/text/recognition.hh>
# include <scribo/text/merging.hh>
# include <scribo/text/link_lines.hh>
+# include <scribo/text/paragraphs.hh>
# include <scribo/make/debug_filename.hh>
@@ -444,93 +445,96 @@ namespace scribo
on_progress();
}
- // Link text lines
- on_new_progress_label("Linking text lines");
- line_links<L> llinks = scribo::text::link_lines(lines);
-
-
- //===== DEBUG =====
-# ifndef SCRIBO_NDEBUG
- if (debug::logger().is_enabled())
- {
- image2d<value::rgb8>
- debug = data::convert(value::rgb8(), original_image);
- for_all_lines(l, lines)
- {
- if (! lines(l).is_textline())
- continue;
-
- mln::draw::box(debug, lines(l).bbox(), literal::blue);
- mln::draw::line(debug, lines(l).bbox().pcenter(),
- lines(llinks(l)).bbox().pcenter(), literal::green);
- }
-
- debug::logger().log_image(debug::AuxiliaryResults,
- debug, "links_raw");
- }
-# endif // ! SCRIBO_NDEBUG
- //===== END OF DEBUG =====
-
- on_progress();
-
-
- // Filter line links.
- on_new_progress_label("Filter line links");
- llinks = scribo::filter::line_links_x_height(llinks);
-
- //===== DEBUG =====
-# ifndef SCRIBO_NDEBUG
- if (debug::logger().is_enabled())
- {
- image2d<value::rgb8>
- debug = data::convert(value::rgb8(), original_image);
- for_all_links(i, llinks)
- if (llinks(i) && llinks(i) != i)
- mln::draw::line(debug, lines(i).bbox().pcenter(),
- lines(llinks(i)).bbox().pcenter(), literal::red);
-
- debug::logger().log_image(debug::AuxiliaryResults,
- debug, "links");
-
- for (unsigned i = 1; i < llinks.nelements(); ++i)
- llinks(i) = scribo::make::internal::find_root(llinks, i);
-
- debug = data::convert(value::rgb8(), original_image);
- mln::util::array<accu::shape::bbox<point2d> >
- nbbox(llinks.nelements());
-
- for_all_lines(i, lines)
- {
- if (! lines(i).is_textline())
- continue;
-
- mln::draw::box(debug, lines(i).bbox(), literal::red);
- nbbox(llinks(i)).take(lines(i).bbox());
- }
-
- for (unsigned i = 1; i < nbbox.nelements(); ++i)
- if (nbbox(i).is_valid())
- {
- box2d b = nbbox(i).to_result();
- mln::draw::box(debug, b, literal::green);
- b.enlarge(1);
- mln::draw::box(debug, b, literal::green);
- b.enlarge(1);
- mln::draw::box(debug, b, literal::green);
- }
-
- debug::logger().log_image(debug::AuxiliaryResults,
- debug, "par");
- }
-# endif // ! SCRIBO_NDEBUG
- //===== END OF DEBUG =====
-
- on_progress();
-
-
- // Construct paragraphs
- on_new_progress_label("Constructing paragraphs");
- scribo::paragraph_set<L> parset = scribo::make::paragraph(llinks);
+// // Link text lines
+// on_new_progress_label("Linking text lines");
+// line_links<L> llinks = scribo::text::link_lines(lines);
+
+
+// //===== DEBUG =====
+// # ifndef SCRIBO_NDEBUG
+// if (debug::logger().is_enabled())
+// {
+// image2d<value::rgb8>
+// debug = data::convert(value::rgb8(), original_image);
+// for_all_lines(l, lines)
+// {
+// if (! lines(l).is_textline())
+// continue;
+
+// mln::draw::box(debug, lines(l).bbox(), literal::blue);
+// mln::draw::line(debug, lines(l).bbox().pcenter(),
+// lines(llinks(l)).bbox().pcenter(), literal::green);
+// }
+
+// debug::logger().log_image(debug::AuxiliaryResults,
+// debug, "links_raw");
+// }
+// # endif // ! SCRIBO_NDEBUG
+// //===== END OF DEBUG =====
+
+// on_progress();
+
+
+// // Filter line links.
+// on_new_progress_label("Filter line links");
+// llinks = scribo::filter::line_links_x_height(llinks);
+
+// //===== DEBUG =====
+// # ifndef SCRIBO_NDEBUG
+// if (debug::logger().is_enabled())
+// {
+// image2d<value::rgb8>
+// debug = data::convert(value::rgb8(), original_image);
+// for_all_links(i, llinks)
+// if (llinks(i) && llinks(i) != i)
+// mln::draw::line(debug, lines(i).bbox().pcenter(),
+// lines(llinks(i)).bbox().pcenter(), literal::red);
+
+// debug::logger().log_image(debug::AuxiliaryResults,
+// debug, "links");
+
+// for (unsigned i = 1; i < llinks.nelements(); ++i)
+// llinks(i) = scribo::make::internal::find_root(llinks, i);
+
+// debug = data::convert(value::rgb8(), original_image);
+// mln::util::array<accu::shape::bbox<point2d> >
+// nbbox(llinks.nelements());
+
+// for_all_lines(i, lines)
+// {
+// if (! lines(i).is_textline())
+// continue;
+
+// mln::draw::box(debug, lines(i).bbox(), literal::red);
+// nbbox(llinks(i)).take(lines(i).bbox());
+// }
+
+// for (unsigned i = 1; i < nbbox.nelements(); ++i)
+// if (nbbox(i).is_valid())
+// {
+// box2d b = nbbox(i).to_result();
+// mln::draw::box(debug, b, literal::green);
+// b.enlarge(1);
+// mln::draw::box(debug, b, literal::green);
+// b.enlarge(1);
+// mln::draw::box(debug, b, literal::green);
+// }
+
+// debug::logger().log_image(debug::AuxiliaryResults,
+// debug, "par");
+// }
+// # endif // ! SCRIBO_NDEBUG
+// //===== END OF DEBUG =====
+
+// on_progress();
+
+
+// // Construct paragraphs
+// on_new_progress_label("Constructing paragraphs");
+// scribo::paragraph_set<L> parset = scribo::make::paragraph(llinks);
+
+ scribo::paragraph_set<L>
+ parset = extract_paragraphs(lines, doc.binary_image());
doc.set_paragraphs(parset);
on_progress();
--
1.5.6.5
1
0
---
scribo/scribo/core/stats.hh | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/scribo/scribo/core/stats.hh b/scribo/scribo/core/stats.hh
index bc24044..88ecd68 100644
--- a/scribo/scribo/core/stats.hh
+++ b/scribo/scribo/core/stats.hh
@@ -261,7 +261,7 @@ private:
unsigned i = 0;
const unsigned nelements = data_.nelements();
- clusters[0] = cluster_index;
+ clusters.push_back(cluster_index);
const T std = data_.standard_deviation();
for (i = 1; i < nelements - 1; ++i)
@@ -276,11 +276,13 @@ private:
clusters.push_back(cluster_index);
}
- if (nelements > 1
- && data_[i] - data_[i - 1] > std)
- ++cluster_index;
+ if (nelements > 1)
+ {
+ if (data_[i] - data_[i - 1] > std)
+ ++cluster_index;
- clusters.push_back(cluster_index);
+ clusters.push_back(cluster_index);
+ }
clusters_.clear();
clusters_.reserve(cluster_index);
--
1.5.6.5
1
0