Experimental Image::BoxFind module:    Image/t/23-bang_along-look_up_for_rect_via_pixpat.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;             # TODO set to 0 before ship
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 three elements:
# 0: the test name
# 1: href of object attributes (not including image_file).
# 2: coderef of sub to define result string, i.e. \&{define_expect_1}
#    Note: if omitted, simply dumps the result (do that to start)

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

    [
    "bang_along look_above pixpat w/ threshold 500 fuzz 5 min w&h 10",
    {
#     edge_detect => 1,
     pixpat_delta_method => 'has_pixpat_changed_past_threshold',
     allow_pixpat_drift  =>  1,
     pixpat_threshold    =>  500,
#     rectangle_finder    =>  'boxfind_downward_via_pixpat',
     rectangle_finder    =>  'boxfind_upward_via_pixpat',
     forward_horizon    =>  3,
     transverse_horizon =>  4,
#     looks_like_edge    =>  10, # TODO play with this?
#     edge_contrast_cutoff => 10,
     edge_contrast_cutoff => 10,

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

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

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

# my $method = 'look_for_rect_edgy_and_pixpat';
# my $method = 'boxfind_upward_via_pixpat';
# my $method = 'roughly_raster_for_rectangular_regions';
my $method = 'bang_along_from_below_for_boxes';

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;

    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;
      }

  }
}

     

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