Commit d4ca44ab authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Compilation related fixes in Scribo.

	* core/line_info.hh: Rename hidden as is_hidden.

	* core/object_links.hh: Add duplicate().

	* filter/object_links_bbox_ratio.hh: Use object_links::duplicate.

	* debug/links_decision_image.hh,
	* src/debug/show_info_median_inter_characters.cc,
	* src/debug/show_info_x_height.cc,
	* src/debug/show_links_bbox_h_ratio.cc,
	* src/debug/show_links_left_right_links_validation.cc: Make
	compile again.

	* tests/unit_test/unit-tests.mk: Regen.

	* text/extract_lines.hh: Update with latest changes.

	* text/recognition.hh: Check whether a line is hidden or not.
parent 2ae99ffe
2010-07-06 Guillaume Lazzara <z@lrde.epita.fr>
Compilation related fixes in Scribo.
* core/line_info.hh: Rename hidden as is_hidden.
* core/object_links.hh: Add duplicate().
* filter/object_links_bbox_ratio.hh: Use object_links::duplicate.
* debug/links_decision_image.hh,
* src/debug/show_info_median_inter_characters.cc,
* src/debug/show_info_x_height.cc,
* src/debug/show_links_bbox_h_ratio.cc,
* src/debug/show_links_left_right_links_validation.cc: Make
compile again.
* tests/unit_test/unit-tests.mk: Regen.
* text/extract_lines.hh: Update with latest changes.
* text/recognition.hh: Check whether a line is hidden or not.
2010-07-06 Guillaume Lazzara <z@lrde.epita.fr>
Add new debug routines.
......
......@@ -138,7 +138,7 @@ namespace scribo
/// computing data over lines.
///
/// @{
bool hidden() const;
bool is_hidden() const;
void set_hidden(bool b);
/// @}
......@@ -268,10 +268,9 @@ namespace scribo
{
// Id MUST NOT change except if this instance have no id.
if (! is_valid())
{
id_ = other.id();
hidden_ = other.hidden_;
}
hidden_ = other.hidden_;
tag_ = other.tag();
bbox_ = other.bbox();
......@@ -620,7 +619,7 @@ namespace scribo
template <typename L>
bool
line_info<L>::hidden() const
line_info<L>::is_hidden() const
{
return hidden_;
}
......@@ -923,6 +922,7 @@ namespace scribo
<< ", orientation=" << info.orientation()
<< ", reading_orientation=" << info.reading_orientation()
<< ", indented=" << info.indented()
<< ", hidden=" << info.is_hidden()
<< ", text=" << info.text()
<< ")" << std::endl;
}
......
......@@ -92,6 +92,8 @@ namespace scribo
void init();
object_links<L> duplicate() const;
private:
mln::util::tracked_ptr<data_t> data_;
};
......@@ -219,6 +221,18 @@ namespace scribo
data_->comp_to_link_(i) = i;
}
template <typename L>
inline
object_links<L>
object_links<L>::duplicate() const
{
object_links<L> output;
output.data_ = new data_t();
*(output.data_.ptr_) = *(data_.ptr_);
return output;
}
template <typename L>
std::ostream&
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of Olena.
//
......@@ -31,15 +32,11 @@
/// Save a color image showing the difference between to object groups.
# include <mln/core/concept/image.hh>
# include <mln/accu/center.hh>
# include <mln/data/convert.hh>
# include <mln/value/rgb8.hh>
# include <mln/literal/colors.hh>
# include <mln/util/array.hh>
# include <mln/norm/l1.hh>
# include <scribo/core/object_groups.hh>
# include <scribo/draw/bounding_boxes.hh>
# include <scribo/core/object_links.hh>
namespace scribo
......@@ -53,14 +50,6 @@ namespace scribo
/// FIXME: DOC!
template <typename I, typename L>
mln_ch_value(I,value::rgb8)
links_decision_image(const Image<I>& input_,
const object_links<L>& links,
const object_links<L>& filtered_links,
unsigned max_link_length);
/// \overload
template <typename I, typename L>
mln_ch_value(I,value::rgb8)
links_decision_image(const Image<I>& input_,
const object_links<L>& links,
const object_links<L>& filtered_links);
......@@ -71,74 +60,45 @@ namespace scribo
mln_ch_value(I,value::rgb8)
links_decision_image(const Image<I>& input_,
const object_links<L>& links,
const object_links<L>& filtered_links,
unsigned max_link_length)
const object_links<L>& filtered_links)
{
trace::entering("scribo::debug::links_decision_image");
const I& input = exact(input_);
const object_image(L)& objects = links.object_image_();
const component_set<L>& comps = links.components();
mln_precondition(input.is_valid());
mln_precondition(objects.is_valid());
mln_precondition(comps.is_valid());
mln_precondition(links.is_valid());
mln_precondition(filtered_links.is_valid());
mln_precondition(links.size() == filtered_links.size());
mln_precondition(links.object_image_() != filtered_links.object_image_());
/// Fixme: check that objects has been computed from input.
image2d<value::rgb8>
links_decision_image = data::convert(value::rgb8(), input);
for_all_components(i, objects.bboxes())
mln::draw::box(links_decision_image, objects.bbox(i), literal::blue);
// Computing mass centers.
mln::util::array<mln_result(accu::center<mln_psite(I)>)>
mass_centers = labeling::compute(accu::meta::center(),
objects, objects.nlabels());
for_all_comps(i, comps)
mln::draw::box(links_decision_image, comps(i).bbox(), literal::blue);
for (unsigned i = 1; i < links.size(); ++i)
{
if (links[i] != i)
for_all_links(i, links)
if (links(i) != i)
{
value::rgb8 value = literal::green;
if (links[i] != filtered_links[i])
if (links(i) != filtered_links(i))
value = literal::red;
mln_site(I)
p1 = mass_centers[i],
p2 = p1 + mln::right; // FIXME: not generic
while (objects(p2) != links[i] && objects.domain().has(p2))
++p2.col();
p1 = comps(i).mass_center(),
p2 = comps(links(i)).mass_center();
if (norm::l1_distance(p2.to_vec(), p1.to_vec()) < max_link_length)
mln::draw::line(links_decision_image,
p1,
p2,
value);
mln::draw::line(links_decision_image, p1, p2, value);
}
}
trace::exiting("scribo::debug::links_decision_image");
return links_decision_image;
}
template <typename I, typename L>
mln_ch_value(I,value::rgb8)
links_decision_image(const Image<I>& input_,
const object_links<L>& links,
const object_links<L>& filtered_links)
{
return links_decision_image(input_,
links,
filtered_links,
mln_max(unsigned));
}
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace scribo::debug
......
......@@ -78,7 +78,7 @@ namespace scribo
const component_set<L>& components = links.components();
object_links<L> output(links);
object_links<L> output = links.duplicate();
for (unsigned i = 1; i < links.nelements(); ++i)
if (links(i) != i)
{
......
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of Olena.
//
......@@ -30,58 +31,26 @@
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
#include <mln/io/pbm/load.hh>
#include <mln/io/ppm/save.hh>
#include <mln/math/min.hh>
#include <mln/literal/colors.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/label_16.hh>
#include <mln/value/int_u16.hh>
#include <mln/draw/box.hh>
#include <mln/draw/line.hh>
#include <mln/extension/adjust.hh>
#include <mln/accu/stat/median_h.hh>
#include <scribo/draw/bounding_boxes.hh>
#include <scribo/primitive/extract/objects.hh>
#include <scribo/primitive/link/merge_double_link.hh>
#include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh>
#include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
#include <scribo/primitive/group/apply.hh>
#include <scribo/primitive/group/from_double_link.hh>
#include <scribo/primitive/group/from_single_link.hh>
#include <scribo/filter/object_links_bbox_h_ratio.hh>
#include <scribo/filter/objects_small.hh>
#include <scribo/filter/objects_thin.hh>
#include <scribo/filter/objects_thick.hh>
#include <scribo/filter/object_groups_small.hh>
#include <scribo/debug/decision_image.hh>
#include <scribo/debug/save_bboxes_image.hh>
#include <scribo/debug/save_bboxes_image.hh>
#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/text/extract_lines.hh>
#include <scribo/debug/char_space_image.hh>
#include <scribo/debug/usage.hh>
#include <scribo/make/debug_filename.hh>
const char *args_desc[][2] =
{
{ "input.pbm", "A binary image. 'False' for objects, 'True'\
for the background." },
{ "debug_dir", "Output directory for debug image" },
{0, 0}
};
......@@ -91,15 +60,12 @@ int main(int argc, char* argv[])
using namespace scribo;
using namespace mln;
if (argc != 3 && argc != 4)
if (argc != 3)
return scribo::debug::usage(argv,
"Find text lines using left/right validation and display x-height in a binarized article.",
"input.pbm out.ppm <debug_dir>",
args_desc,
"A color image. The following colors are used : dark blue for object bboxes, orange for single object bboxes, purple for group bboxes and light blue for x-height.");
"input.pbm out.ppm",
args_desc);
if (argc == 4)
scribo::make::internal::debug_filename_prefix = argv[3];
trace::entering("main");
......@@ -109,148 +75,10 @@ int main(int argc, char* argv[])
typedef image2d<value::label_16> L;
/// Finding objects.
std::cout << "Finding objects..." << std::endl;
value::label_16 nobjects;
object_image(L)
objects = scribo::primitive::extract::objects(input,
c8(),
nobjects);
/// First filtering.
std::cout << "Filtering objects..." << std::endl;
object_image(L) filtered_objects
= scribo::filter::objects_small(objects, 6);
/// Linking potential objects
std::cout << "Linking objects..." << std::endl;
object_links<L> left_link
= primitive::link::with_single_left_link_dmax_ratio(filtered_objects);
object_links<L> right_link
= primitive::link::with_single_right_link_dmax_ratio(filtered_objects);
// Validating left and right links.
object_links<L>
merged_links = primitive::link::merge_double_link(filtered_objects,
left_link,
right_link);
#ifndef NOUT
if (argc == 4)
{
image2d<value::rgb8> output = data::convert(value::rgb8(), input);
scribo::draw::bounding_box_links(output,
merged_links,
literal::green);
util::array<bool> drawn(objects.nlabels(), 0);
for_all_components(i, objects.bboxes())
if (merged_links[i] == i && ! drawn(i))
{
mln::draw::box(output, objects.bbox(i), literal::orange);
drawn[i] = true;
}
else
{
mln::draw::box(output, objects.bbox(i), literal::blue);
mln::draw::box(output, objects.bbox(merged_links[i]), literal::blue);
drawn[i] = true;
drawn[merged_links[i]] = true;
}
io::ppm::save(output, scribo::make::debug_filename("links.ppm"));
}
#endif
// Remove links if bboxes have too different sizes.
object_links<L> hratio_filtered_links
= filter::object_links_bbox_h_ratio(filtered_objects,
merged_links,
2.0f);
#ifndef NOUT
if (argc == 4)
{
image2d<value::rgb8>
hratio_decision_image = scribo::debug::decision_image(input,
merged_links,
hratio_filtered_links);
io::ppm::save(hratio_decision_image,
scribo::make::debug_filename("hratio_links_decision_image.ppm"));
}
#endif
// FIXME: from_single_link should return a packed object_groups?
//
//######
object_groups<L>
groups = primitive::group::from_single_link(filtered_objects,
hratio_filtered_links);
value::label_16 n_groups;
mln::fun::i2v::array<value::label_16>
groups_packed = mln::make::relabelfun(groups,
filtered_objects.nlabels(),
n_groups);
//######
std::cout << "Grouping objects..." << std::endl;
object_image(L)
grouped_objects = primitive::group::apply(filtered_objects, groups);
// Display median character space.
{
image2d<value::rgb8> output = data::convert(value::rgb8(), input);
typedef mln::value::int_u<8> median_t;
typedef mln::accu::stat::median_h<median_t> accu_t;
util::array<accu_t>
lspace_med(static_cast<unsigned>(grouped_objects.nlabels()) + 1);
for_all_components(i, filtered_objects.bboxes())
if (groups_packed(i) != 0)
{
if (hratio_filtered_links(i) != i)
{
unsigned
space = filtered_objects.bbox(i).pmin().col() - filtered_objects.bbox(hratio_filtered_links(i)).pmax().col();
lspace_med(groups_packed(i)).take(space);
}
}
for_all_components(i, filtered_objects.bboxes())
if (groups_packed(i) != 0 && lspace_med(groups_packed(i)).card() > 1)
{
unsigned med = lspace_med(groups_packed(i)).to_result();
mln::draw::box(output, grouped_objects.bbox(groups_packed(i)),
literal::purple);
point2d
beg = filtered_objects.bbox(i).pmax(),
end = beg;
beg.row() = filtered_objects.bbox(i).pmin().row();
mln::draw::line(output, beg, end, literal::cyan);
beg.col() += med;
end.col() += med;
mln::draw::line(output, beg, end, literal::cyan);
}
io::ppm::save(output, argv[2]);
line_set<L> line = scribo::text::extract_lines(input, c8());
}
image2d<value::rgb8> output = scribo::debug::char_space_image(input, line);
io::ppm::save(output, argv[2]);
trace::exiting("main");
}
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of Olena.
//
......@@ -30,58 +31,22 @@
#include <mln/core/image/image2d.hh>
#include <mln/core/alias/neighb2d.hh>
#include <mln/io/pbm/all.hh>
#include <mln/io/pbm/load.hh>
#include <mln/io/ppm/save.hh>
#include <mln/math/min.hh>
#include <mln/literal/colors.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/label_16.hh>
#include <mln/value/int_u16.hh>
#include <mln/draw/box.hh>
#include <mln/draw/line.hh>
#include <mln/extension/adjust.hh>
#include <mln/accu/stat/median_h.hh>
#include <scribo/draw/bounding_boxes.hh>
#include <scribo/primitive/extract/objects.hh>
#include <scribo/primitive/link/merge_double_link.hh>
#include <scribo/primitive/link/with_single_left_link_dmax_ratio.hh>
#include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
#include <scribo/primitive/group/apply.hh>
#include <scribo/primitive/group/from_double_link.hh>
#include <scribo/primitive/group/from_single_link.hh>
#include <scribo/filter/object_links_bbox_h_ratio.hh>
#include <scribo/filter/objects_small.hh>
#include <scribo/filter/objects_thin.hh>
#include <scribo/filter/objects_thick.hh>
#include <scribo/filter/object_groups_small.hh>
#include <scribo/debug/decision_image.hh>
#include <scribo/debug/save_bboxes_image.hh>
#include <scribo/debug/save_bboxes_image.hh>
#include <scribo/debug/save_linked_bboxes_image.hh>
#include <scribo/text/extract_lines.hh>
#include <scribo/debug/line_info_image.hh>
#include <scribo/debug/usage.hh>
#include <scribo/make/debug_filename.hh>
const char *args_desc[][2] =
{
{ "input.pbm", "A binary image. 'False' for objects, 'True'\
for the background." },
{ "debug_dir", "Output directory for debug image" },
{0, 0}
};
......@@ -91,15 +56,11 @@ int main(int argc, char* argv[])
using namespace scribo;
using namespace mln;
if (argc != 3 && argc != 4)
if (argc != 3)
return scribo::debug::usage(argv,
"Find text lines using left/right validation and display x-height in a binarized article.",
"input.pbm out.ppm <debug_dir>",
args_desc,
"A color image. The following colors are used : dark blue for object bboxes, orange for single object bboxes, purple for group bboxes and light blue for x-height.");
if (argc == 4)
scribo::make::internal::debug_filename_prefix = argv[3];
"input.pbm out.ppm",
args_desc);
trace::entering("main");
......@@ -109,173 +70,10 @@ int main(int argc, char* argv[])
typedef image2d<value::label_16> L;
/// Finding objects.
std::cout << "Finding objects..." << std::endl;
value::label_16 nobjects;
object_image(L)
objects = scribo::primitive::extract::objects(input,
c8(),
nobjects);
/// First filtering.
std::cout << "Filtering objects..." << std::endl;
object_image(L) filtered_objects
= scribo::filter::objects_small(objects, 6);
/// Linking potential objects
std::cout << "Linking objects..." << std::endl;
object_links<L> left_link
= primitive::link::with_single_left_link_dmax_ratio(filtered_objects);
object_links<L> right_link
= primitive::link::with_single_right_link_dmax_ratio(filtered_objects);
// Validating left and right links.
object_links<L>
merged_links = primitive::link::merge_double_link(filtered_objects,
left_link,
right_link);
#ifndef NOUT
if (argc == 4)
{
image2d<value::rgb8> output = data::convert(value::rgb8(), input);
scribo::draw::bounding_box_links(output,
filtered_objects.bboxes(),
merged_links,
literal::green);
util::array<bool> drawn(objects.nlabels(), 0);
for_all_components(i, objects.bboxes())
if (merged_links[i] == i && ! drawn(i))
{
mln::draw::box(output, objects.bbox(i), literal::orange);
drawn[i] = true;
}
else
{
mln::draw::box(output, objects.bbox(i), literal::blue);
mln::draw::box(output, objects.bbox(merged_links[i]), literal::blue);
drawn[i] = true;
drawn[merged_links[i]] = true;
}
io::ppm::save(output, scribo::make::debug_filename("links.ppm"));
}