Experimental Image::BoxFind module:    Image/t/25-roughly_raster-boxfind_downward_recenter.t


     # Test file created outside of h2xs framework.
# Run this like so: `perl Image-BoxFind.t'
#   doom@kzsu.stanford.edu     2007/10/22 04:50:12

use warnings;
use strict;
$|=1;
my $DEBUG = 1;
use Data::Dumper;

use Test::More;
BEGIN { plan tests => 5 };
use Test::Number::Delta;

use File::Basename qw( basename fileparse);

use FindBin qw( $Bin );
use lib "$Bin/../..";
use lib "$Bin/lib";

BEGIN { #1
  use_ok( 'Image::BoxFind' );
}
use Image::BoxFind::Testing::Eyeballs ':all';

#2
ok(1, "Traditional: If we made it this far, we're ok.");


my @image_files =
  (
   "$Bin/dat/images/firefox_save_as.png",
   "$Bin/dat/images/rhythmbox_prefs.png",
   "$Bin/dat/images/gimp_open_dialog.png",
  );

# test cases are an array of two elements:
# 0: the test name
# 1: href of object attributes (not including image_file).

# Expected values for each image are retrieved from the
# library of values in Image::BoxFind::Testing::Eyeballs

my @test_cases =
  ( [], [], [],   # dummies to sync up test numbering with array index

    [
    "roughly_raster boxfind_downward_recenter horizon: 3x4",
    {
#     edge_detect => 1,
     pixpat_delta_method => 'has_pixpat_changed_past_threshold',
     allow_pixpat_drift  =>  1,
     pixpat_threshold    =>  500,
#     pixpat_threshold    =>  200,
     rectangle_finder    =>  'boxfind_downward_recenter',
     direction          => 'y_plus',
#     spotsize_x         => 3,           # set_direction makes determine_pixpat_* horizon conscious
#     spotsize_y         => 4,           # and set_direction is now *always* called by sub init.
#     refocus_factor     => 4,
     refocus_factor     => 2,

     forward_horizon    =>  3,
     transverse_horizon =>  4,

#     looks_like_edge    =>  10, # TODO play with this?
#     edge_contrast_cutoff => 10, # note default is being lowered. Needs to be 1 for 13*.t
     edge_contrast_cutoff => 2, # TODO BOOKMARK

     # used by 'looks_rectangular'
     fuzziness   => 5,
     minimum_height => 10,
     minimum_width  => 10,

     # used by 'roughly_raster'
#     beware => 0,
#     step_x => 25,
#     step_y => 10,
     step_x => 10,
     step_y => 10,

    },
     ],
   ### TODO can add more if need be...
  );



my $method = 'roughly_raster_for_rectangular_regions';

foreach my $i ( 3 .. $#test_cases ) {
  my $case = $test_cases[ $i ];
  my $test_name         = $case->[0];
  my $object_attributes = $case->[1];
  my $expected_coderef  = $case->[2];

  foreach my $image_file ( @image_files ) {
    my $basename = (  fileparse($image_file, qr{\.png} ) )[0];
    my $expected = define_expected_via_eyeball( $basename );

    my $extra_attributes =
      {
       image_file  => $image_file,
       DEBUG       => $DEBUG,
      };
    my @keys = (keys %{ $extra_attributes });
    @{ $object_attributes }{ @keys }  = @{ $extra_attributes }{ @keys };

    my $bf = Image::BoxFind->new( $object_attributes );

    my $results = $bf->$method;  ### The Call

    my $tolerance = 7; # similar to "fuzziness"
    delta_within( $results, $expected, $tolerance, "$test_name - $basename")
      or do {
        my $results_text  = $bf->dump_boxes_to_string( $results );
        my $expected_text = $bf->dump_boxes_to_string( $expected );
        print "results:\n" . $results_text . "\nexpected:\n" . $expected_text;
      };

    $bf->draw_rects( $results ); # generates a marked up version of the image with suffix "rex"
  }
}

foreach my $image_file ( @image_files ) {
#  my $basename = (  fileparse($image_file, qr{\.png} ) )[0];
  my ($basename, $image_path, $suffix) = fileparse($image_file, qr{\.png});

  chdir( $image_path );
  my $image_rex = $image_path . $basename . '-rex.png';
  my $cmd = "gthumb $image_rex";
  ($DEBUG) && print STDERR "cmd: $cmd";
  system($cmd);
}

     

Joseph Brenner, Tue Nov 27 17:40:02 2007