Experimental Image::BoxFind module:    Image/t/10-boxfind_downward_via_pixpat-firefox_save_as.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 }; # TODO change to 'tests => last_test_to_print';

use Data::Dumper;
use File::Basename qw( basename );
use Test::Number::Delta;

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

BEGIN { #1
  use_ok( 'Image::BoxFind' );
}

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

{#3
  my $test_name = "boxfind_downward_via_pixpat";
  my $image_file = "$Bin/dat/images/firefox_save_as.png";
  my $basename = basename( $image_file );
  $basename =~ s{\.png$}{}x;
  my $bf = Image::BoxFind->new( { image_file => $image_file,
                                  DEBUG      => $DEBUG,
                                } );

  my ($forward_horizon, $transverse_horizon) = (3, 4);
  $bf->set_forward_horizon(    $forward_horizon );
  $bf->set_transverse_horizon( $transverse_horizon );
  my $spot_str = $forward_horizon . 'x' . $transverse_horizon;

  my ($x0, $y0, $corners, $expected);

  # starting location above the 'Name' box.
  ($x0, $y0) = (190, 6);

  $corners = $bf->boxfind_downward_via_pixpat($x0, $y0);

  $expected = [
                  [ 111, 12 ],
                  [ 478, 11 ],
                  [ 478, 32 ],
                  [ 111, 32 ]
                 ];

#  is_deeply( $corners, $expected,
#               "Testing $test_name on $basename $spot_str ($x0,$y0) above the 'Name' box" );

  my $tolerance = 2;
  delta_within( $corners, $expected, $tolerance,
     "Testing $test_name on $basename $spot_str ($x0,$y0) above the 'Name' box" )
      or do {
        my $results_text  = $bf->print_box_to_string( $corners );
        my $expected_text = $bf->print_box_to_string( $expected );
        print "results:\n" . $results_text . "\nexpected:\n" . $expected_text;
      };

  #4
  $bf->set_pixpat_delta_method('has_pixpat_changed_past_threshold');
  $bf->set_pixpat_threshold( 8500 ); # Note: must be fairly large

  # starting location above the 'Name' box.
  ($x0, $y0) = (325, 126);

  $corners = $bf->boxfind_downward_via_pixpat($x0, $y0);

  $expected = [
          [ 303, 129 ],
          [ 387, 128 ],
          [ 387, 154 ],
          [ 303, 154 ]
                 ];

#  is_deeply( $corners, $expected,
#       "Testing $test_name on $basename $spot_str ($x0,$y0) above the 'Cancel' button" );

  $tolerance = 2;
  delta_within( $corners, $expected, $tolerance,
     "Testing $test_name on $basename $spot_str ($x0,$y0) above the 'Cancel' button" )
      or do {
        my $corners_text  = $bf->print_box_to_string( $corners );
        my $expected_text = $bf->print_box_to_string( $expected );
        print "results:\n" . $corners_text . "\nexpected:\n" . $expected_text;
      };



  #5
  $bf->set_pixpat_delta_method('has_pixpat_changed_past_threshold');
  $bf->set_ignore_subtle_pixpat_change( 1 );
  $bf->set_pixpat_threshold( 500 );

  # starting location above the 'Name' box.
  ($x0, $y0) = (325, 126);

  $corners = $bf->boxfind_downward_via_pixpat($x0, $y0);

  # print Dumper( $corners ), "\n";

  $expected = [
          [ 303, 129 ],  # a little odd, 129/128?
          [ 387, 128 ],
          [ 387, 154 ],
          [ 303, 154 ]
                 ];

#  is_deeply( $corners, $expected,
#       "Testing $test_name on $basename $spot_str ($x0,$y0) above 'Cancel': ignore_subtle_pixpat_change " );

  $tolerance = 2;
  delta_within( $corners, $expected, $tolerance,
     "Testing $test_name on $basename $spot_str ($x0,$y0) above 'Cancel': ignore_subtle_pixpat_change " )
      or do {
        my $corners_text  = $bf->print_box_to_string( $corners );
        my $expected_text = $bf->print_box_to_string( $expected );
        print "results:\n" . $corners_text . "\nexpected:\n" . $expected_text;
      };


}

     

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