Experimental Image::BoxFind module:    Image/t/26-smart_sweep_for_squarish_shapes.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 = 0;
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

    [
    "smart_sweep_for_squarish_shapes horizon: 3x4",
    {
#     edge_detect => 1,
     pixpat_delta_method => 'has_pixpat_changed_past_threshold',
     allow_pixpat_drift  =>  1,
     pixpat_threshold    =>  500,
     rectangle_finder    =>  'boxfind_downward_recenter',
     direction          => 'y_plus',
#     spotsize_x         => 3,
#     spotsize_y         => 4,
     refocus_factor     => 4,

     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 'smart_sweep_for_squarish_shapes'
#     beware => 0,             ### TODO NEXT
#     step_x => 25,
#     step_y => 10,
     step_x => 5,
#     step_y => 3,

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



my $method = 'smart_sweep_for_squarish_shapes';

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