
* tests/core/Makefile.am: New target. * tests/core/object_groups.cc: New. --- scribo/ChangeLog | 8 ++ scribo/tests/core/Makefile.am | 8 ++- .../object_groups.cc} | 70 +++++++++++++------- 3 files changed, 60 insertions(+), 26 deletions(-) copy scribo/tests/{filter/object_groups_small.cc => core/object_groups.cc} (50%) diff --git a/scribo/ChangeLog b/scribo/ChangeLog index 9395d2b..f139bb6 100644 --- a/scribo/ChangeLog +++ b/scribo/ChangeLog @@ -1,5 +1,13 @@ 2011-05-03 Guillaume Lazzara <lazzara@lrde.epita.fr> + Add a test for object_groups. + + * tests/core/Makefile.am: New target. + + * tests/core/object_groups.cc: New. + +2011-05-03 Guillaume Lazzara <lazzara@lrde.epita.fr> + * scribo/primitive/extract/separators_nonvisible.hh: Update use of object_groups and object_links. diff --git a/scribo/tests/core/Makefile.am b/scribo/tests/core/Makefile.am index 356cc31..c9af42d 100644 --- a/scribo/tests/core/Makefile.am +++ b/scribo/tests/core/Makefile.am @@ -1,5 +1,5 @@ -# Copyright (C) 2009, 2010 EPITA Research and Development Laboratory -# (LRDE). +# Copyright (C) 2009, 2010, 2011 EPITA Research and Development +# Laboratory (LRDE). # # This file is part of Olena. # @@ -20,8 +20,10 @@ include $(top_srcdir)/scribo/tests/tests.mk -check_PROGRAMS = line_info +check_PROGRAMS = line_info \ + object_groups line_info_SOURCES = line_info.cc +object_groups_SOURCES = object_groups.cc TESTS = $(check_PROGRAMS) diff --git a/scribo/tests/filter/object_groups_small.cc b/scribo/tests/core/object_groups.cc similarity index 50% copy from scribo/tests/filter/object_groups_small.cc copy to scribo/tests/core/object_groups.cc index 9812b70..33e408f 100644 --- a/scribo/tests/filter/object_groups_small.cc +++ b/scribo/tests/core/object_groups.cc @@ -25,55 +25,79 @@ /// \file -#include <iostream> - #include <mln/core/image/image2d.hh> #include <mln/core/alias/neighb2d.hh> #include <mln/io/pbm/load.hh> + +#include <scribo/core/component_set.hh> #include <scribo/core/def/lbl_type.hh> +#include <scribo/core/object_links.hh> +#include <scribo/core/object_groups.hh> #include <scribo/primitive/extract/components.hh> #include <scribo/primitive/link/with_single_left_link.hh> -#include <scribo/primitive/group/from_single_link.hh> -#include <scribo/filter/object_groups_small.hh> #include "tests/data.hh" -int main() +int main(int argc, char *argv[]) { - using namespace scribo; using namespace mln; + using namespace scribo; std::string img = SCRIBO_IMG_DIR "/the_valleys.pbm"; - const bool ref[] = { false, true, true, true, true }; - const bool filtered_ref[] = { false, false, true, false, false }; - const unsigned size_ref[] = { 0, 1, 7, 1, 3 }; - + static const int comp_to_group_ref[] = { 0, 1, 4, 2, 3, 2, 2, 4, 4, 2, 2, 2, 2 }; + static const int pixel_area_ref[] = { 0, 3, 973, 39, 426 }; + static const box2d bbox_ref[] = { + box2d(), + make::box2d(0,91, 1,92), + make::box2d(9,95, 45,224), + make::box2d(9,204, 20,209), + make::box2d(9,12, 36,64) + }; + + static const int comp_ids_count_ref[] = { 0, 1, 7, 1, 3 }; + static const int comp_ids_ref[][7] = { + { 0, 0, 0, 0, 0, 0, 0 }, + { 1, 0, 0, 0, 0, 0, 0 }, + { 3, 9, 5, 6, 10, 11, 12 }, + { 4, 0, 0, 0, 0, 0, 0 }, + { 7, 2, 8, 0, 0, 0, 0 } }; image2d<bool> input; io::pbm::load(input, img.c_str()); typedef scribo::def::lbl_type V; + V nlabels; typedef image2d<V> L; - - V nbboxes; component_set<L> - text = primitive::extract::components(input, c8(), nbboxes); - object_links<L> links = primitive::link::with_single_left_link(text, 30); + comps = scribo::primitive::extract::components(input, c8(), nlabels); - object_groups<L> groups = primitive::group::from_single_link(links); + object_links<L> link + = primitive::link::with_single_left_link(comps, 30); - mln_assertion(groups.nelements() == 5); - for_all_groups(g, groups) - mln_assertion(groups(g).is_valid() == ref[g]); + object_groups<L> group(link); - object_groups<L> groups2 = filter::object_groups_small(groups, 4); + mln_assertion(group.nelements() == 5); + mln_assertion(group.comp_to_group().nelements() == 13); - for_all_groups(g, groups2) + // Checking comp_to_group() + for (int i = 0; i < group.comp_to_group().nelements(); ++i) + mln_assertion(group.comp_to_group()[i] == comp_to_group_ref[i]); + + // Checking group info data. + for_all_groups(g, group) { - mln_assertion(groups2(g).is_valid() == filtered_ref[g]); - mln_assertion(groups2(g).card() == size_ref[g]); + mln_assertion(group(g).id() == g); + mln_assertion(group(g).is_valid()); + mln_assertion(group(g).pixel_area() == pixel_area_ref[g]); + mln_assertion(group(g).bbox() == bbox_ref[g]); + mln_assertion(group(g).component_ids().nelements() == comp_ids_count_ref[g]); + + for_all_elements(e, group(g).component_ids()) + mln_assertion(group(g).component_ids()[e] == comp_ids_ref[g][e]); } - + // Checking group_of() + for_all_comps(c, comps) + mln_assertion(group.group_of(c).id() == comp_to_group_ref[c]); } -- 1.5.6.5