Experimental Image::BoxFind module:    Image/t/13-boxfind_downward_purely_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 Test::Number::Delta;

use Data::Dumper;
use File::Basename qw( basename );

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_purely_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_purely_via_pixpat($x0, $y0);

  $expected = [
                  [ 111, 12 ],
                  [ 478, 10 ],
                  [ 478, 32 ],
                  [ 111, 33 ]
                 ];

  my $tolerance = 3;
  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 'Cancel' button
#  ($x0, $y0) = (325, 126);
  ($x0, $y0) = (325, 125);

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

  $expected = [
          [ 303, 129 ],
          [ 388, 129 ],
          [ 388, 154 ],
          [ 303, 155 ]
                 ];

  $tolerance = 4;
  delta_within( $corners, $expected, $tolerance,
     "Testing $test_name on $basename $spot_str ($x0,$y0) above the 'Cancel' button" )
      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;
      };



  #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);
  ($x0, $y0) = (325, 125);

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

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

  $tolerance = 4;
  delta_within( $corners, $expected, $tolerance,
     "Testing $test_name on $basename $spot_str ($x0,$y0) above 'Cancel': ignore_subtle_pixpat_change ")
      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;
      };

}

     

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