LRE
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
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
List overview
Download
Olena-patches
June 2013
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
olena-patches@lrde.epita.fr
5 participants
104 discussions
Start a n
N
ew thread
olena: olena-2.0-571-g929c08c Create blured copies of original image
by Anthony Seure
--- milena/sandbox/anthony/Makefile | 11 ++- milena/sandbox/anthony/src/scale_space.cc | 114 ++++++++++++++++++++++++----- 2 files changed, 103 insertions(+), 22 deletions(-) diff --git a/milena/sandbox/anthony/Makefile b/milena/sandbox/anthony/Makefile index 7f990da..81f788e 100644 --- a/milena/sandbox/anthony/Makefile +++ b/milena/sandbox/anthony/Makefile @@ -1,8 +1,8 @@ CCACHE=ccache CC=g++ -CFLAGS=-Wall -Werror -O3 -DNDEBUG -CLIBS=-I../../../scribo/ -I../../ -CLEAN=*.o output/* log final.xml *.pgm +CFLAGS=-Wall -Werror +CLIBS=-I../../ +CLEAN=*.o output/* log SRC=src/scale_space.cc OUTPUT=a.out @@ -10,7 +10,10 @@ OUTPUT=a.out all: scale scale: - $(CCACHE) $(CC) $(CFLAGS) $(CLIBS) $(SRC) -o $(OUTPUT) + $(CCACHE) $(CC) $(CFLAGS) -O2 -DNDEBUG $(CLIBS) $(SRC) -o $(OUTPUT) + +debug: + $(CCACHE) $(CC) $(CFLAGS) -g -ggdb $(CLIBS) $(SRC) -o $(OUTPUT) clean: rm -rf $(CLEAN) diff --git a/milena/sandbox/anthony/src/scale_space.cc b/milena/sandbox/anthony/src/scale_space.cc index 9e452a3..31180af 100644 --- a/milena/sandbox/anthony/src/scale_space.cc +++ b/milena/sandbox/anthony/src/scale_space.cc @@ -1,36 +1,114 @@ -#include <mln/binarization/all.hh> - #include <mln/core/image/image2d.hh> - +#include <mln/core/alias/neighb2d.hh> #include <mln/data/all.hh> -#include <mln/draw/line.hh> +#include <mln/io/pgm/all.hh> +#include <mln/literal/all.hh> +#include <mln/value/all.hh> +#include <mln/make/w_window2d.hh> +#include <mln/core/alias/w_window2d_int.hh> -#include <mln/fun/v2v/rgb_to_luma.hh> +#include <cmath> -#include <mln/io/pgm/all.hh> +using namespace mln; -#include <mln/labeling/all.hh> -#include <mln/literal/all.hh> -#include <mln/logical/and.hh> +// Set the gaussian kernel of size (6 * t + 1) +double *gaussian_kernel(unsigned t) +{ + int size = 6 * t + 1; + unsigned index = 0; + double *kernel = new double[size * size]; + static const double pi = 4.0 * atan(1.0); + double div = (2.0 * pi * t * t); -#include <mln/value/all.hh> + for (int i = -(size / 2); i < (size / 2) + 1; ++i) + { + for (int j = -(size / 2); j < (size / 2) + 1; ++j) + { + double e = exp(- (i * i + j * j) / (2.0 * t * t) ); + kernel[index++] = e / div; + } + } -#include <tesseract/baseapi.h> + return kernel; +} -#include <scribo/binarization/sauvola.hh> -#include <scribo/core/component_set.hh> -#include <scribo/preprocessing/denoise_fg.hh> -#include <scribo/primitive/extract/all.hh> +// Apply the convolution of the image by the kernel +template<typename I> +void convolve(const I& original, I& filtered, double *kernel, unsigned t) +{ + mln_piter(I) p(filtered.domain()); + int size = 6 * t + 1; + window2d win; -using namespace mln; + for (int i = -(size / 2); i < (size / 2) + 1; ++i) + { + for (int j = -(size / 2); j < (size / 2) + 1; ++j) + { + win.insert(i, j); + } + } + + + // Iterate through all image sites + for_all(p) + { + // Create the window around the site + mln_qiter(window2d) q(win, p); + float sum = 0; + int index = 0; + // Iterate through all window image sites + for_all(q) + { + if (filtered.has(q)) + sum += original(q) * kernel[index++]; + else + sum += 127 * kernel[index++]; + } + + filtered(p) = static_cast<int>(sum); + } +} + +// Blur the image thanks to a convolution matrix +template<typename I> +image2d<value::int_u8> blur(const I& original, unsigned t) +{ + I filtered; + double *kernel = gaussian_kernel(t); + + initialize(filtered, original); + convolve(original, filtered, kernel, t); + + return filtered; +} + +template<typename I> +void downscaleResolution(const I& original, I& toReduce) +{ +} + +// MAIN ENTRY POINT int main(int argc, char** argv) { image2d<value::int_u8> original; + io::pgm::load(original, "images/flower.pgm"); + + image2d<value::int_u8> blur1, blur2, blur4; + initialize(blur1, original); + initialize(blur2, original); + initialize(blur4, original); + + io::pgm::save(original, "output/original.pgm"); + + blur1 = blur(original, 1); + io::pgm::save(blur1, "output/blur1.pgm"); - io::pgm::load(original, "images/keith.pgm"); + blur2 = blur(original, 2); + io::pgm::save(blur2, "output/blur2.pgm"); - io::pgm::save(original, "final.pgm"); + blur4 = blur(original, 4); + io::pgm::save(blur4, "output/blur4.pgm"); return 0; } -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-570-g6836fdc Init scale space working directory
by Anthony Seure
--- milena/sandbox/anthony/Makefile | 21 +++++++++++++++++ milena/sandbox/anthony/src/scale_space.cc | 36 +++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 0 deletions(-) create mode 100644 milena/sandbox/anthony/Makefile create mode 100644 milena/sandbox/anthony/src/scale_space.cc diff --git a/milena/sandbox/anthony/Makefile b/milena/sandbox/anthony/Makefile new file mode 100644 index 0000000..7f990da --- /dev/null +++ b/milena/sandbox/anthony/Makefile @@ -0,0 +1,21 @@ +CCACHE=ccache +CC=g++ +CFLAGS=-Wall -Werror -O3 -DNDEBUG +CLIBS=-I../../../scribo/ -I../../ +CLEAN=*.o output/* log final.xml *.pgm + +SRC=src/scale_space.cc +OUTPUT=a.out + +all: scale + +scale: + $(CCACHE) $(CC) $(CFLAGS) $(CLIBS) $(SRC) -o $(OUTPUT) + +clean: + rm -rf $(CLEAN) + +mrproper: clean + rm -f $(OUTPUT) + +.PHONY: scale clean mrproper diff --git a/milena/sandbox/anthony/src/scale_space.cc b/milena/sandbox/anthony/src/scale_space.cc new file mode 100644 index 0000000..9e452a3 --- /dev/null +++ b/milena/sandbox/anthony/src/scale_space.cc @@ -0,0 +1,36 @@ +#include <mln/binarization/all.hh> + +#include <mln/core/image/image2d.hh> + +#include <mln/data/all.hh> +#include <mln/draw/line.hh> + +#include <mln/fun/v2v/rgb_to_luma.hh> + +#include <mln/io/pgm/all.hh> + +#include <mln/labeling/all.hh> +#include <mln/literal/all.hh> +#include <mln/logical/and.hh> + +#include <mln/value/all.hh> + +#include <tesseract/baseapi.h> + +#include <scribo/binarization/sauvola.hh> +#include <scribo/core/component_set.hh> +#include <scribo/preprocessing/denoise_fg.hh> +#include <scribo/primitive/extract/all.hh> + +using namespace mln; + +int main(int argc, char** argv) +{ + image2d<value::int_u8> original; + + io::pgm::load(original, "images/keith.pgm"); + + io::pgm::save(original, "final.pgm"); + + return 0; +} -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-569-g4ecdb6a Remove many false positives (intersecting boxes)
by Anthony Seure
--- scribo/sandbox/icdar_13_table/src/new.cc | 35 +++++++++++++++++++++++++++++- 1 files changed, 34 insertions(+), 1 deletions(-) diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index bcf127e..d52ac15 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -58,6 +58,13 @@ using namespace mln; +// Check if two boxes intersected +bool intersect(const box2d& b1, const box2d& b2) +{ + return ((unsigned) abs(b1.pcenter().col() - b2.pcenter().col()) * 2 < b1.width() + b2.width() + && (unsigned) abs(b1.pcenter().row() - b2.pcenter().row()) * 2 < b1.height() + b2.height()); +} + // Draw weighted boxes (red < orange < cyan < green) // 1 link < 2 links < 3 links < 3+ links template<typename T, typename L> @@ -581,6 +588,9 @@ int main(int argc, char** argv) descendants[columns_set.find(j)].insert(j); } + std::vector<box2d> columns; + std::set<unsigned> not_valid; + // Visualization: columns. image2d<value::rgb8> ima_columns = data::convert(value::rgb8(), bin_merged); for (unsigned i = 0; i < groups.nelements(); ++i) @@ -590,9 +600,32 @@ int main(int argc, char** argv) for (group_set::const_iterator j = descendants[i].begin(); j != descendants[i].end(); ++j) column_box.merge(groups(*j).bbox()); - draw::box(ima_columns, column_box, literal::red); + draw::box(ima_columns, column_box, literal::green); + columns.push_back(column_box); } + for (unsigned i = 0; i < columns.size(); ++i) + { + for (unsigned j = 0; j < columns.size(); ++j) + { + if (i != j) + { + const box2d& c1 = columns[i]; + const box2d& c2 = columns[j]; + + if (intersect(c1, c2) || intersect(c2, c1)) + { + not_valid.insert(i); + not_valid.insert(j); + } + } + } + } + + for (unsigned i = 0; i < columns.size(); ++i) + if (not_valid.find(i) != not_valid.end()) + draw::box(ima_columns, columns[i], literal::red); + // Write images and close XML std::ostringstream path; unsigned number = 0; -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-568-gc9c37e9 Build the set of detected columns during table recognition.
by Roland Levillain
* scribo/sandbox/icdar_13_table/src/new.cc: Here. * scribo/sandbox/icdar_13_table/src/disjoint_set.hh: New. --- scribo/sandbox/icdar_13_table/src/disjoint_set.hh | 54 +++++++++++++++++++++ scribo/sandbox/icdar_13_table/src/new.cc | 36 ++++++++++++++ 2 files changed, 90 insertions(+), 0 deletions(-) create mode 100644 scribo/sandbox/icdar_13_table/src/disjoint_set.hh diff --git a/scribo/sandbox/icdar_13_table/src/disjoint_set.hh b/scribo/sandbox/icdar_13_table/src/disjoint_set.hh new file mode 100644 index 0000000..b8ae409 --- /dev/null +++ b/scribo/sandbox/icdar_13_table/src/disjoint_set.hh @@ -0,0 +1,54 @@ +#ifndef DISJOINT_SET_HH +# define DISJOINT_SET_HH + +/// \file +/// Implementation of a disjoint-set forest. + +# include <limits> +# include <vector> + +template <typename T> +struct disjoint_set +{ + disjoint_set(size_t size) + // The maximum value of T is considered an ``invalid value''. + : parent(size, std::numeric_limits<T>::max()) + { + for (unsigned i = 0; i < parent.size(); ++i) + make_set(i); + } + + /// Create initial sets (singletons). + void make_set(T x) + { + parent[x] = x; + } + + bool is_root(T x) + { + return parent[x] == x; + } + + /// Find the root of the set containing \a x. + T find(T x) + { + if (!is_root(x)) + // Path compression. + parent[x] = find(parent[x]); + return parent[x]; + } + + /// Merge the set containing \a y into the set containing \a x. + void make_union(T x, T y) + { + T x_root = find(x); + T y_root = find(y); + parent[y_root] = x_root; + } + + /// Parent relationship. A node with is its own parent is a + /// root (representative of a component). + std::vector<T> parent; +}; + +#endif // ! DISJOINT_SET_HH diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index 2c41e31..bcf127e 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -54,6 +54,8 @@ #include <scribo/text/extract_paragraphs.hh> #include <scribo/text/merging.hh> +#include "disjoint_set.hh" + using namespace mln; // Draw weighted boxes (red < orange < cyan < green) @@ -558,6 +560,39 @@ int main(int argc, char** argv) } } + // Build the columns. + // First pass. + disjoint_set<node_id> columns_set(groups.nelements()); + for (unsigned i = 0; i < groups.nelements(); ++i) + { + const group_set& successors = nodes_below[i]; + for (group_set::const_iterator j = successors.begin(); + j != successors.end(); ++j) + columns_set.make_union(i, *j); + } + // Second pass: assign labels. Label 0 is unused and means + // ``default''. + std::vector<group_set> descendants(groups.nelements()); + for (unsigned i = 0; i < groups.nelements(); ++i) + { + // Process groups in reverse order. + unsigned j = groups.nelements() - 1 - i; + if (!columns_set.is_root(j)) + descendants[columns_set.find(j)].insert(j); + } + + // Visualization: columns. + image2d<value::rgb8> ima_columns = data::convert(value::rgb8(), bin_merged); + for (unsigned i = 0; i < groups.nelements(); ++i) + if (!descendants[i].empty()) + { + box2d column_box = groups(i).bbox(); + for (group_set::const_iterator j = descendants[i].begin(); + j != descendants[i].end(); ++j) + column_box.merge(groups(*j).bbox()); + draw::box(ima_columns, column_box, literal::red); + } + // Write images and close XML std::ostringstream path; unsigned number = 0; @@ -572,6 +607,7 @@ int main(int argc, char** argv) write_image(ima_links, "components", page, number, path); write_image(ima_groups, "groups", page, number, path); write_image(ima_valid, "valid", page, number, path); + write_image(ima_columns, "columns", page, number, path); } delete xml; -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-567-g5ead1be Build spatial relations between text boxes as directed graphs.
by Roland Levillain
* scribo/sandbox/icdar_13_table/src/new.cc: Here. --- scribo/sandbox/icdar_13_table/src/new.cc | 89 ++++++++++++++++++++++++++++++ 1 files changed, 89 insertions(+), 0 deletions(-) diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index 02e7594..2c41e31 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -469,6 +469,95 @@ int main(int argc, char** argv) draw_links_rl(groups, ima_groups, balance, vlines); draw_adjacency_boxes(balance, ima_valid, groups); + /* FIXME: The code below duplicates some of the code in the + draw_links_* routines. Factor. */ + // Adjacencies between nodes. Of course, an actual digraph data + // structure would be better. + typedef unsigned node_id; + typedef std::set<node_id> group_set; + typedef std::vector<group_set> adjacencies; + adjacencies nodes_below(groups.nelements()); + adjacencies nodes_above(groups.nelements()); + adjacencies nodes_right(groups.nelements()); + adjacencies nodes_left(groups.nelements()); + + // Draw vertical links (red) + for (unsigned i = 1; i < groups.nelements(); ++i) + { + for (unsigned j = i + 1; j < groups.nelements(); ++j) + { + const box2d& b1 = groups(i).bbox(); + const box2d& b2 = groups(j).bbox(); + const point2d& p1 = b1.pcenter(); + const point2d& p2 = b2.pcenter(); + + unsigned max_height = std::max(b1.height(), b2.height()); + unsigned min_height = std::min(b1.height(), b2.height()); + + if (/* p1[0] < p2[0] // Avoid redundancy + && */ + max_height * 2 < bin_merged.ncols() + && min_height + 3 >= max_height // Same heights + && b1.width() < 2 * average_width && b2.width() < 2 * average_width // Regular width + && (b1.pmin()[1] == b2.pmin()[1] + || (b1.pmin()[1] < b2.pmin()[1] && b1.pmax()[1] > b2.pmin()[1]) + || (b1.pmin()[1] > b2.pmin()[1] && b2.pmax()[1] > b1.pmin()[1])) // Boxes are aligned + && abs(p1[0] - p2[0]) < 3 * max_height // Reduced gap + && abs(p1[1] - p2[1]) < 20) // Vertical proximity + { + // Build the above/below adjacencies. + node_id top_node, bottom_node; + if (p1.row() < p2.col()) + { + top_node = i; + bottom_node = j; + } + else + { + top_node = j; + bottom_node = i; + } + nodes_below[top_node].insert(bottom_node); + nodes_above[bottom_node].insert(top_node); + } + } + } + + // Draw horizontal links (green) + for (unsigned i = 1; i < groups.nelements(); ++i) + { + for (unsigned j = i + 1; j < groups.nelements(); ++j) + { + const box2d& b1 = groups(i).bbox(); + const box2d& b2 = groups(j).bbox(); + const point2d& p1 = b1.pcenter(); + const point2d& p2 = b2.pcenter(); + + if (/* p1[1] < p2[1] // Avoid redundancy + && */ + (b1.pmin()[0] == b2.pmin()[0] + || (b1.pmin()[0] < b2.pmin()[0] && b1.pmax()[0] > b2.pmin()[0]) + || (b1.pmin()[0] > b2.pmin()[0] && b2.pmax()[0] > b1.pmin()[0])) // Boxes are aligned + && abs(p1[0] - p2[0]) < 10) // Reduced gap + { + // Build the right/left adjacencies. + node_id left_node, right_node; + if (p1.col() < p2.col()) + { + left_node = i; + right_node = j; + } + else + { + left_node = j; + right_node = i; + } + nodes_right[left_node].insert(right_node); + nodes_left[right_node].insert(left_node); + } + } + } + // Write images and close XML std::ostringstream path; unsigned number = 0; -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-566-g6117c48 Fix various issues in the table detection experiment.
by Roland Levillain
* scribo/sandbox/icdar_13_table/src/new.cc: Use the multiscale version of the Sauvola binarization. (main): Remove an unused variable. Remove superfluous `return' statement. --- scribo/sandbox/icdar_13_table/src/new.cc | 7 +------ 1 files changed, 1 insertions(+), 6 deletions(-) diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index b13696e..02e7594 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -26,7 +26,6 @@ #include <tesseract/baseapi.h> // INCLUDES SCRIBO -#include <scribo/binarization/sauvola.hh> #include <scribo/binarization/sauvola_ms.hh> #include <scribo/core/component_set.hh> @@ -353,8 +352,7 @@ int main(int argc, char** argv) { I8 original = pdf[page]; image2d<value::int_u8> filtered = data::transform(original, fun::v2v::rgb_to_luma<value::int_u8>()); - IB bin = scribo::binarization::sauvola(filtered, 81, 0.44); - //IB bin = scribo::binarization::sauvola_ms(filtered, 81, 2); + IB bin = scribo::binarization::sauvola_ms(filtered, 81, 2); // Reverse selection IB reverse = logical::not_(bin); @@ -378,7 +376,6 @@ int main(int argc, char** argv) // Find separators IB bin_without_separators = duplicate(bin); - IB separators = separators; V nhlines, nvlines; unsigned min_width = 31; unsigned min_height = 71; @@ -489,6 +486,4 @@ int main(int argc, char** argv) } delete xml; - - return 0; } -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-565-g103edf9 [ICDAR_13] Refactore and use of sauvola_ms instead of sauvola
by Anthony Seure
--- scribo/sandbox/icdar_13_table/src/new.cc | 93 +++++++++++++++++------------- 1 files changed, 53 insertions(+), 40 deletions(-) diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index 5370164..b13696e 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -27,6 +27,7 @@ // INCLUDES SCRIBO #include <scribo/binarization/sauvola.hh> +#include <scribo/binarization/sauvola_ms.hh> #include <scribo/core/component_set.hh> #include <scribo/core/line_set.hh> @@ -56,6 +57,29 @@ using namespace mln; +// Draw weighted boxes (red < orange < cyan < green) +// 1 link < 2 links < 3 links < 3+ links +template<typename T, typename L> +void draw_adjacency_boxes(const std::vector<short>& balance, + image2d<T>& ima, + const scribo::object_groups< image2d<L> >& groups) +{ + for (unsigned i = 0; i < balance.size(); ++i) + { + if (balance[i] == 1) + draw::box(ima, groups(i).bbox(), literal::red); + + if (balance[i] == 2) + draw::box(ima, groups(i).bbox(), literal::orange); + + if (balance[i] == 3) + draw::box(ima, groups(i).bbox(), literal::cyan); + + if (balance[i] > 3) + draw::box(ima, groups(i).bbox(), literal::green); + } +} + // Write image2d<bool> images void write_image(const image2d<bool>& ima, const char* name, @@ -226,7 +250,8 @@ void draw_links_lr(const scribo::object_groups< image2d<unsigned> >& groups, && (b1.pmin()[0] == b2.pmin()[0] || (b1.pmin()[0] < b2.pmin()[0] && b1.pmax()[0] > b2.pmin()[0]) || (b1.pmin()[0] > b2.pmin()[0] && b2.pmax()[0] > b1.pmin()[0])) // Boxes are aligned - && abs(p1[0] - p2[0]) < 10) // Reduced gap + && abs(p1[0] - p2[0]) < 10 // Reduced gap + && abs(p1[1] - p2[1]) > (b1.width() + b2.width()) / 4) // Consistent gap { unsigned k = 1; short separators = 0; @@ -277,7 +302,8 @@ void draw_links_rl(const scribo::object_groups< image2d<unsigned> >& groups, && (b1.pmin()[0] == b2.pmin()[0] || (b1.pmin()[0] < b2.pmin()[0] && b1.pmax()[0] > b2.pmin()[0]) || (b1.pmin()[0] > b2.pmin()[0] && b2.pmax()[0] > b1.pmin()[0])) // Boxes are aligned - && abs(p1[0] - p2[0]) < 10) // Reduced gap + && abs(p1[0] - p2[0]) < 10 // Reduced gap + && abs(p1[1] - p2[1]) > (b1.width() + b2.width()) / 4) // Consistent gap { unsigned k = 1; short separators = 0; @@ -311,34 +337,33 @@ int main(int argc, char** argv) { typedef value::label_16 V; typedef image2d<V> L; - - std::ostringstream path; - image2d<value::rgb8> original, ima_links, ima_groups, ima_valid; - image2d<value::int_u8> filtered; - image2d<bool> bin, reverse, reverse_selection, bin_merged, separators, bin_without_separators, whitespaces, comp, denoised; - scribo::component_set< image2d<unsigned> > components, rcomponents; - - unsigned dpi = 72; + typedef image2d<value::rgb8> I8; + typedef image2d<bool> IB; + typedef scribo::component_set< image2d<unsigned> > CS; // Loading and binarization XML* xml = new XML("final.xml", argv[1]); util::array< image2d<value::rgb8> > pdf; + unsigned dpi = 72; io::pdf::load(pdf, argv[1], dpi); + // Iterate over all pages for (unsigned page = 0; page < pdf.nelements(); ++page) { - original = pdf[page]; - filtered = data::transform(original, fun::v2v::rgb_to_luma<value::int_u8>()); - bin = scribo::binarization::sauvola(filtered, 81, 0.44); + I8 original = pdf[page]; + image2d<value::int_u8> filtered = data::transform(original, fun::v2v::rgb_to_luma<value::int_u8>()); + IB bin = scribo::binarization::sauvola(filtered, 81, 0.44); + //IB bin = scribo::binarization::sauvola_ms(filtered, 81, 2); // Reverse selection - reverse = logical::not_(bin); + IB reverse = logical::not_(bin); + IB reverse_selection; initialize(reverse_selection, reverse); data::fill(reverse_selection, false); unsigned nrcomponents; - rcomponents = scribo::primitive::extract::components(reverse, c8(), nrcomponents); + CS rcomponents = scribo::primitive::extract::components(reverse, c8(), nrcomponents); for (unsigned i = 1; i < rcomponents.nelements(); ++i) { @@ -352,8 +377,8 @@ int main(int argc, char** argv) reverse_selection = scribo::preprocessing::denoise_fg(reverse_selection, c8(), 4); // Find separators - bin_without_separators = duplicate(bin); - separators = separators; + IB bin_without_separators = duplicate(bin); + IB separators = separators; V nhlines, nvlines; unsigned min_width = 31; unsigned min_height = 71; @@ -366,14 +391,15 @@ int main(int argc, char** argv) data::fill((bin_without_separators | vlines(i).bbox()).rw(), false); // Denoise - denoised = scribo::preprocessing::denoise_fg(bin_without_separators, c8(), 4); + IB denoised = scribo::preprocessing::denoise_fg(bin_without_separators, c8(), 4); // Bin merged - bin_merged = logical::or_(denoised, reverse_selection); + IB bin_merged = logical::or_(denoised, reverse_selection); // Extract components unsigned ncomponents; - components = scribo::primitive::extract::components(bin_merged, c8(), ncomponents); + CS components = scribo::primitive::extract::components(bin_merged, c8(), ncomponents); + IB comp; initialize(comp, bin_merged); data::fill(comp, false); @@ -398,9 +424,11 @@ int main(int argc, char** argv) // Filter links scribo::object_links< image2d<unsigned> > hratio_filtered_links = scribo::filter::object_links_bbox_h_ratio(merged_links, 2.5f); - ima_links = data::convert(value::rgb8(), bin_merged); - ima_groups = data::convert(value::rgb8(), bin_merged); - ima_valid = data::convert(value::rgb8(), bin_merged); + IB tmp = logical::and_(bin_merged, comp); + + I8 ima_links = data::convert(value::rgb8(), tmp); + I8 ima_groups = data::convert(value::rgb8(), tmp); + I8 ima_valid = data::convert(value::rgb8(), tmp); // Write links for (unsigned l = 1; l < merged_links.nelements(); ++l) @@ -442,25 +470,10 @@ int main(int argc, char** argv) draw_links_bt(groups, ima_groups, balance, average_width, hlines); draw_links_lr(groups, ima_groups, balance, vlines); draw_links_rl(groups, ima_groups, balance, vlines); - - // Draw weighted boxes (red < orange < cyan < green) - // 1 link < 2 links < 3 links < 3+ links - for (unsigned i = 0; i < balance.size(); ++i) - { - if (balance[i] == 1) - draw::box(ima_valid, groups(i).bbox(), literal::red); - - if (balance[i] == 2) - draw::box(ima_valid, groups(i).bbox(), literal::orange); - - if (balance[i] == 3) - draw::box(ima_valid, groups(i).bbox(), literal::cyan); - - if (balance[i] > 3) - draw::box(ima_valid, groups(i).bbox(), literal::green); - } + draw_adjacency_boxes(balance, ima_valid, groups); // Write images and close XML + std::ostringstream path; unsigned number = 0; write_image(bin, "bin", page, number, path); -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-564-g3e47e4a [ICDAR_13] Validate links of boxes based on separators
by Anthony Seure
--- scribo/sandbox/icdar_13_table/src/new.cc | 123 +++++++++++++++++++++++++----- 1 files changed, 102 insertions(+), 21 deletions(-) diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index 9f05030..5370164 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -87,10 +87,12 @@ void write_image(const image2d<value::rgb8>& ima, } // Draw vertical links from top to bottom (red) +template<typename L> void draw_links_tb(const scribo::object_groups< image2d<unsigned> >& groups, image2d<value::rgb8>& ima_groups, std::vector<short>& balance, - unsigned average_width) + unsigned average_width, + const scribo::component_set<L>& hlines) { for (unsigned i = 1; i <= groups.nelements(); ++i) { @@ -116,9 +118,27 @@ void draw_links_tb(const scribo::object_groups< image2d<unsigned> >& groups, && (unsigned) abs(p1[0] - p2[0]) < 3 * max_height // Reduced gap && (unsigned) abs(p1[1] - p2[1]) < 20) // Vertical proximity { - draw::line(ima_groups, p1, p2, literal::red); - balance[i] += 1; - break; + unsigned k = 1; + short separators = 0; + + while (k <= hlines.nelements() && separators < 2) + { + const box2d& s = hlines(k).bbox(); + + if (s.pmin()[1] <= b1.pmin()[1] && s.pmax()[1] >= b1.pmax()[1] + && s.pmin()[0] > b1.pmax()[0] + && s.pmax()[0] < b2.pmin()[0]) + ++separators; + + ++k; + } + + if (separators < 2) + { + draw::line(ima_groups, p1, p2, literal::red); + balance[i] += 1; + break; + } } } } @@ -126,10 +146,12 @@ void draw_links_tb(const scribo::object_groups< image2d<unsigned> >& groups, } // Draw vertical links from bottom to top (red) +template<typename L> void draw_links_bt(const scribo::object_groups< image2d<unsigned> >& groups, image2d<value::rgb8>& ima_groups, std::vector<short>& balance, - unsigned average_width) + unsigned average_width, + const scribo::component_set<L>& hlines) { for (unsigned i = groups.nelements(); i > 0; --i) { @@ -155,9 +177,27 @@ void draw_links_bt(const scribo::object_groups< image2d<unsigned> >& groups, && (unsigned) abs(p1[0] - p2[0]) < 3 * max_height // Reduced gap && (unsigned) abs(p1[1] - p2[1]) < 20) // Vertical proximity { - draw::line(ima_groups, p1, p2, literal::red); - balance[i] += 1; - break; + unsigned k = 1; + short separators = 0; + + while (k <= hlines.nelements() && separators < 2) + { + const box2d& s = hlines(k).bbox(); + + if (s.pmin()[1] <= b1.pmin()[1] && s.pmax()[1] >= b1.pmax()[1] + && s.pmax()[0] < b1.pmin()[0] + && s.pmin()[0] > b2.pmax()[0]) + ++separators; + + ++k; + } + + if (separators < 2) + { + draw::line(ima_groups, p1, p2, literal::red); + balance[i] += 1; + break; + } } } } @@ -165,9 +205,11 @@ void draw_links_bt(const scribo::object_groups< image2d<unsigned> >& groups, } // Draw horizontal links from left to right (green) +template<typename L> void draw_links_lr(const scribo::object_groups< image2d<unsigned> >& groups, image2d<value::rgb8>& ima_groups, - std::vector<short>& balance) + std::vector<short>& balance, + const scribo::component_set<L>& vlines) { for (unsigned i = 1; i <= groups.nelements(); ++i) { @@ -186,9 +228,27 @@ void draw_links_lr(const scribo::object_groups< image2d<unsigned> >& groups, || (b1.pmin()[0] > b2.pmin()[0] && b2.pmax()[0] > b1.pmin()[0])) // Boxes are aligned && abs(p1[0] - p2[0]) < 10) // Reduced gap { - draw::line(ima_groups, p1, p2, literal::green); - balance[i] += 1; - break; + unsigned k = 1; + short separators = 0; + + while (k <= vlines.nelements() && separators < 2) + { + const box2d& s = vlines(k).bbox(); + + if (s.pmin()[0] <= b1.pmin()[0] && s.pmax()[0] >= b1.pmax()[0] + && s.pmin()[1] > b1.pmax()[1] + && s.pmax()[1] < b2.pmin()[1]) + ++separators; + + ++k; + } + + if (separators < 2) + { + draw::line(ima_groups, p1, p2, literal::green); + balance[i] += 1; + break; + } } } } @@ -196,9 +256,11 @@ void draw_links_lr(const scribo::object_groups< image2d<unsigned> >& groups, } // Draw horizontal links from right to left (green) +template<typename L> void draw_links_rl(const scribo::object_groups< image2d<unsigned> >& groups, image2d<value::rgb8>& ima_groups, - std::vector<short>& balance) + std::vector<short>& balance, + const scribo::component_set<L>& vlines) { for (unsigned i = groups.nelements(); i > 0; --i) { @@ -217,9 +279,27 @@ void draw_links_rl(const scribo::object_groups< image2d<unsigned> >& groups, || (b1.pmin()[0] > b2.pmin()[0] && b2.pmax()[0] > b1.pmin()[0])) // Boxes are aligned && abs(p1[0] - p2[0]) < 10) // Reduced gap { - draw::line(ima_groups, p1, p2, literal::green); - balance[i] += 1; - break; + unsigned k = 1; + short separators = 0; + + while (k <= vlines.nelements() && separators < 2) + { + const box2d& s = vlines(k).bbox(); + + if (s.pmin()[0] <= b1.pmin()[0] && s.pmax()[0] >= b1.pmax()[0] + && s.pmax()[1] < b1.pmin()[1] + && s.pmin()[1] > b2.pmax()[1]) + ++separators; + + ++k; + } + + if (separators < 2) + { + draw::line(ima_groups, p1, p2, literal::green); + balance[i] += 1; + break; + } } } } @@ -358,12 +438,13 @@ int main(int argc, char** argv) std::vector<short> balance(groups.nelements(), 0); // Draw and count links - draw_links_tb(groups, ima_groups, balance, average_width); - draw_links_bt(groups, ima_groups, balance, average_width); - draw_links_lr(groups, ima_groups, balance); - draw_links_rl(groups, ima_groups, balance); + draw_links_tb(groups, ima_groups, balance, average_width, hlines); + draw_links_bt(groups, ima_groups, balance, average_width, hlines); + draw_links_lr(groups, ima_groups, balance, vlines); + draw_links_rl(groups, ima_groups, balance, vlines); - // Draw weighted boxes (red < orange < cyan < green) (useless ?) + // Draw weighted boxes (red < orange < cyan < green) + // 1 link < 2 links < 3 links < 3+ links for (unsigned i = 0; i < balance.size(); ++i) { if (balance[i] == 1) -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-563-g2661c4d [ICDAR_13] Check old version XML output with GUI Annotator
by Anthony Seure
--- scribo/sandbox/icdar_13_table/Makefile | 3 ++- .../competition-entry-region-model.xsd | 0 scribo/sandbox/icdar_13_table/src/main.cc | 9 ++++++--- 3 files changed, 8 insertions(+), 4 deletions(-) rename scribo/sandbox/icdar_13_table/{ => originals}/competition-entry-region-model.xsd (100%) diff --git a/scribo/sandbox/icdar_13_table/Makefile b/scribo/sandbox/icdar_13_table/Makefile index 7c11bf1..baa9ae1 100644 --- a/scribo/sandbox/icdar_13_table/Makefile +++ b/scribo/sandbox/icdar_13_table/Makefile @@ -1,6 +1,7 @@ CCACHE=ccache CC=g++ CFLAGS=-Wall -Werror -O3 -DHAVE_TESSERACT_3 -DNDEBUG -DMLN_WO_GLOBAL_VARS +CFLAGS_OLD=-Wall -Werror -O3 -DHAVE_TESSERACT_3 -DNDEBUG CLIBS=-I../../../milena/ -I../../ -I/usr/include/poppler CLEAN=*.o output/* log final.xml @@ -15,7 +16,7 @@ table: $(CCACHE) $(CC) $(CFLAGS) $(CLIBS) $(SRC) -ltesseract -lpoppler-cpp -o $(OUTPUT) old: - $(CCACHE) $(CC) $(CFLAGS) $(CLIBS) $(SRC_OLD) -ltesseract -lpoppler-cpp -o $(OUTPUT_OLD) + $(CCACHE) $(CC) $(CFLAGS_OLD) $(CLIBS) $(SRC_OLD) -ltesseract -lpoppler-cpp -o $(OUTPUT_OLD) clean: rm -rf $(CLEAN) diff --git a/scribo/sandbox/icdar_13_table/competition-entry-region-model.xsd b/scribo/sandbox/icdar_13_table/originals/competition-entry-region-model.xsd similarity index 100% rename from scribo/sandbox/icdar_13_table/competition-entry-region-model.xsd rename to scribo/sandbox/icdar_13_table/originals/competition-entry-region-model.xsd diff --git a/scribo/sandbox/icdar_13_table/src/main.cc b/scribo/sandbox/icdar_13_table/src/main.cc index be394ba..3aa40c2 100644 --- a/scribo/sandbox/icdar_13_table/src/main.cc +++ b/scribo/sandbox/icdar_13_table/src/main.cc @@ -26,9 +26,12 @@ using namespace mln; -void start_xml(std::ofstream& xml, const char* name, const char* pdf) +void start_xml(std::ofstream& xml, const char* pdf) { - xml.open(name); + //std::ostringstream name; + //name << pdf << "-reg-result.xml"; + //xml.open((name.str()).c_str()); + xml.open("us-005-reg-result.xml"); xml << "<?xml version\"1.0\" encoding=\"UTF-8\"?>" << std::endl << "<document filename='" << pdf << "'>" << std::endl; } @@ -212,7 +215,7 @@ int main(int argc, char** argv) // Loading and binarization std::ofstream xml; - start_xml(xml, "final.xml", argv[1]); + start_xml(xml, argv[1]); //io::ppm::load(original, argv[1]); util::array< image2d<value::rgb8> > pdf; -- 1.7.2.5
11 years, 6 months
1
0
0
0
olena: olena-2.0-562-g8241f48 [ICDAR_13] Update XML output + Add XML reference
by Anthony Seure
--- scribo/sandbox/icdar_13_table/Makefile | 2 +- .../competition-entry-region-model.xsd | 45 +++++++++++++++++++ scribo/sandbox/icdar_13_table/src/new.cc | 5 +-- scribo/sandbox/icdar_13_table/src/xml.cc | 47 +++++++++++++------ scribo/sandbox/icdar_13_table/src/xml.hh | 9 +++- 5 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 scribo/sandbox/icdar_13_table/competition-entry-region-model.xsd diff --git a/scribo/sandbox/icdar_13_table/Makefile b/scribo/sandbox/icdar_13_table/Makefile index 8d0cd1a..7c11bf1 100644 --- a/scribo/sandbox/icdar_13_table/Makefile +++ b/scribo/sandbox/icdar_13_table/Makefile @@ -1,6 +1,6 @@ CCACHE=ccache CC=g++ -CFLAGS=-Wall -Werror -O3 -DHAVE_TESSERACT_3 -DNDEBUG +CFLAGS=-Wall -Werror -O3 -DHAVE_TESSERACT_3 -DNDEBUG -DMLN_WO_GLOBAL_VARS CLIBS=-I../../../milena/ -I../../ -I/usr/include/poppler CLEAN=*.o output/* log final.xml diff --git a/scribo/sandbox/icdar_13_table/competition-entry-region-model.xsd b/scribo/sandbox/icdar_13_table/competition-entry-region-model.xsd new file mode 100644 index 0000000..2e0d0d4 --- /dev/null +++ b/scribo/sandbox/icdar_13_table/competition-entry-region-model.xsd @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" + xmlns:xsd="
http://www.w3.org/2001/XMLSchema
" > + <xsd:element name="document"> + <xsd:complexType> + <xsd:sequence> + <xsd:element minOccurs="0" maxOccurs="unbounded" name="table"> <!-- a document can contain 0 or more tables --> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="region" maxOccurs="unbounded" nillable="false"> <!-- each table must contain 1 or more regions --> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="instruction" minOccurs="0" maxOccurs="unbounded"> <!-- the instructions are optional --> + <xsd:complexType> + <xsd:attribute name="instr-id" type="xsd:integer" use="required"/> + <xsd:attribute name="subinstr-id" type="xsd:integer"/> + <!--<xsd:attribute name="text" type="xsd:string" use="required"/> + <xsd:attribute name="x1" type="xsd:integer" use="required"/> + <xsd:attribute name="y1" type="xsd:integer" use="required"/> + <xsd:attribute name="x2" type="xsd:integer" use="required"/> + <xsd:attribute name="y2" type="xsd:integer" use="required"/>--> + </xsd:complexType> + </xsd:element> + <xsd:element name="bounding-box"> <!-- each region contains one bounding box --> + <xsd:complexType> + <xsd:attribute name="x1" type="xsd:integer" use="required"/> + <xsd:attribute name="y1" type="xsd:integer" use="required"/> + <xsd:attribute name="x2" type="xsd:integer" use="required"/> + <xsd:attribute name="y2" type="xsd:integer" use="required"/> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + <xsd:attribute name="id" type="xsd:nonNegativeInteger" use="required"/> + <xsd:attribute name="page" type="xsd:positiveInteger" use="required"/> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + <xsd:attribute name="id" type="xsd:nonNegativeInteger" use="required"/> + </xsd:complexType> + </xsd:element> + </xsd:sequence> + <xsd:attribute name="filename" type="xsd:string" use="required"/> + </xsd:complexType> + </xsd:element> +</xsd:schema> diff --git a/scribo/sandbox/icdar_13_table/src/new.cc b/scribo/sandbox/icdar_13_table/src/new.cc index 95bf575..9f05030 100644 --- a/scribo/sandbox/icdar_13_table/src/new.cc +++ b/scribo/sandbox/icdar_13_table/src/new.cc @@ -1,3 +1,4 @@ +#undef MLN_WO_GLOBAL_VARS #include "xml.hh" // INCLUDES OLENA @@ -231,7 +232,6 @@ int main(int argc, char** argv) typedef value::label_16 V; typedef image2d<V> L; - //std::ofstream xml; std::ostringstream path; image2d<value::rgb8> original, ima_links, ima_groups, ima_valid; image2d<value::int_u8> filtered; @@ -241,7 +241,6 @@ int main(int argc, char** argv) unsigned dpi = 72; // Loading and binarization - //start_xml(xml, "final.xml", argv[1]); XML* xml = new XML("final.xml", argv[1]); util::array< image2d<value::rgb8> > pdf; @@ -395,8 +394,6 @@ int main(int argc, char** argv) write_image(ima_valid, "valid", page, number, path); } - - //end_xml(xml); delete xml; return 0; diff --git a/scribo/sandbox/icdar_13_table/src/xml.cc b/scribo/sandbox/icdar_13_table/src/xml.cc index 76fed84..86e66e2 100644 --- a/scribo/sandbox/icdar_13_table/src/xml.cc +++ b/scribo/sandbox/icdar_13_table/src/xml.cc @@ -1,31 +1,48 @@ #include "xml.hh" -XML::XML(const char* name, const char* pdf) - : _name(name), _pdf(pdf) +XML::XML(const char* name, + const char* pdf) + : _name(name), _pdf(pdf), _table(0), _region(0), _first_time(true) { _xml.open(_name); _xml << "<?xml version\"1.0\" encoding=\"UTF-8\"?>" << std::endl - << "<document filename='" << _pdf << "'>" << std::endl; + << "<document filename='" << _pdf << "'>" << std::endl; } -XML::~XML() +XML::~XML(void) { _xml << "</document>" << std::endl; _xml.close(); } -void XML::write_table(const point2d& start, const point2d& end) +void XML::table(const point2d& start, + const point2d& end, + const unsigned page, + const bool connect) { - static unsigned table = 0; - static unsigned region = 0; - static unsigned page = 1; + if (_first_time) + { + _xml << "\t<table id='" << _table << "'>" << std::endl; + ++_table; + _first_time = false; + } + else + { + if (!connect) + { + _xml << "\t</table>" << std::endl; + _xml << "\t<table id='" << _table << "'>" << std::endl; + _region = 0; + ++_table; + } + } - _xml << "\t<table id='" << table << "'>" << std::endl - << "\t\t<region id='" << region << "' page='" << page << "'>" << std::endl - << "\t\t<bounding-box x1='" << start[1] << "' y1='" << start[0] << "' " - << "x2='" << end[1] << "' y2='" << end[0] << "'/>" << std::endl - << "\t\t</region>" << std::endl - << "\t</table>" << std::endl; + _xml << "\t\t<region id='" << _region << "' page='" << page + 1 << "'>" << std::endl + << "\t\t\t<bounding-box x1='" << start[1] + << "' y1='" << start[0] + << "' x2='" << end[1] + << "' y2='" << end[0] << "'/>" << std::endl + << "\t\t</region>" << std::endl; - ++table; + ++_region; } diff --git a/scribo/sandbox/icdar_13_table/src/xml.hh b/scribo/sandbox/icdar_13_table/src/xml.hh index 397d585..b4cef29 100644 --- a/scribo/sandbox/icdar_13_table/src/xml.hh +++ b/scribo/sandbox/icdar_13_table/src/xml.hh @@ -1,6 +1,5 @@ #ifndef XML_HH # define XML_HH -# define MLN_WO_GLOBAL_VARS # include <iostream> # include <fstream> @@ -13,12 +12,18 @@ class XML public: XML(const char* name, const char* pdf); ~XML(); - void write_table(const point2d& start, const point2d& end); + void table(const point2d& start, + const point2d& end, + const unsigned page, + const bool connect); private: std::ofstream _xml; const char* _name; const char* _pdf; + unsigned _table; + unsigned _region; + bool _first_time; }; #endif /* !XML_HH */ -- 1.7.2.5
11 years, 6 months
1
0
0
0
← Newer
1
...
6
7
8
9
10
11
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
Results per page:
10
25
50
100
200