milena r1645: Update extract character

URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena ChangeLog: 2008-01-09 Guillaume Duhamel <guillaume.duhamel@lrde.epita.fr> Update extract character. * sandbox/nivault/extract_character.cc: Update. --- extract_character.cc | 110 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 99 insertions(+), 11 deletions(-) Index: trunk/milena/sandbox/nivault/extract_character.cc =================================================================== --- trunk/milena/sandbox/nivault/extract_character.cc (revision 1644) +++ trunk/milena/sandbox/nivault/extract_character.cc (revision 1645) @@ -30,6 +30,7 @@ # include <mln/core/image2d.hh> # include <mln/io/pbm/load.hh> # include <mln/io/pgm/save.hh> +# include <mln/io/ppm/save.hh> # include <mln/debug/println.hh> # include <mln/logical/not.hh> # include <mln/logical/or.hh> @@ -62,6 +63,12 @@ # include <mln/level/stretch.hh> +# include <mln/core/image_if_value.hh> +# include <mln/core/sub_image.hh> +# include <mln/level/paste.hh> +# include <mln/literal/all.hh> +# include <mln/value/rgb8.hh> + using namespace mln; int @@ -114,15 +121,63 @@ vec_card[label_image(p)].take (p); } -// for (unsigned i = 0; i <= nb_labels; ++i) -// { -// if (vec_card[i].to_result () > 200) -// ; -// std::cout << i << " = " << vec_card[i].to_result () << std::endl; -// std::cout << i << " = " << vec_bbox[i].to_result () << std::endl; -// } + I_LABEL text_ima (label_image.domain()); + + for (unsigned i = 0; i <= nb_labels; ++i) + { + float ratio = 0; + unsigned rows = vec_bbox[i].to_result().nrows(); + unsigned cols = vec_bbox[i].to_result().ncols(); + unsigned size = rows * cols; + unsigned card = vec_card[i].to_result(); + +// if (rows < cols) +// ratio = cols / rows; +// else +// ratio = rows / cols; + +// if (ratio > 3) +// continue; + +// if (vec_card[i].to_result () /*rows * cols*/ < 200) + +// if (size / card < 0.3) +// continue; + +// if (((float)card / (float)size) > 0.7) +// continue; + +// if (((float)card / (float)size) < 0.3) +// continue; + + + if (cols < 5) + continue; + + if (cols > 20) + continue; + + + { + typedef sub_image<I_LABEL, box2d> I_SUB; + typedef image_if_value<I_SUB> I_VAL; + + I_SUB sub_ima = (label_image | vec_bbox[i].to_result()); + I_VAL val_ima = (sub_ima | i); + + mln_piter_(I_VAL) p(val_ima.domain()); + + for_all (p) + text_ima(p) = val_ima(p); + +// /// Hack +// level::paste (val_ima, text_ima); + } + } + + + -// std::cout << path_output << " generated" << std::endl; /// Generation of the graph. @@ -132,10 +187,43 @@ // I_LABEL gr_image (label_image.domain ()); // draw::mesh(gr_image, m, 255, 128); -// image2d<int_u8> out (label_image.domain ()); -// level::stretch (zi_image, out); + I ref = io::pbm::load ("ref_text.pbm"); + image2d<value::rgb8> mask (ref.domain()); + mln_piter_(I_LABEL) p_out (text_ima.domain ()); + + unsigned cpt = 0; + unsigned ok = 0; + + for_all (p_out) + { + if (text_ima(p_out)) + if (ref(p_out)) + mask(p_out) = literal::red; + else + { + mask(p_out) = literal::white; + ++ok; + } + else + if (ref(p_out)) + { + ++ok; + mask(p_out) = literal::black; + } + else + mask(p_out) = literal::green; + ++cpt; + } + + std::cout << "Reussite : " << (float)ok / (float)cpt * 100 << "% (" + << ok << "/" << cpt << ")." << std::endl; + + image2d<int_u8> out (label_image.domain ()); + level::stretch (text_ima, out); + io::pgm::save(mask, "rgb.ppm"); + io::pgm::save(out, "out.pgm"); -// io::pgm::save(out, "out.pgm"); + std::cout << path_output << " generated" << std::endl; }
participants (1)
-
Guillaume Duhamel