Experimental Image::BoxFind module: Image/t/12-scan_for_edgey_pixpat.t
# Test file created outside of h2xs framework.
# Run this like so: `perl 12-scan_for_edgey_pixpat.t'
# doom@kzsu.stanford.edu 2007/11/03 00:26:05
use warnings;
use strict;
$|=1;
my $DEBUG = 1;# TODO zero out
use Data::Dumper;
use Test::More;
BEGIN { plan tests => 10 };
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.");
# 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}
# Need to feed in a starting point, and have an expected end point for it,
# These will vary for each image. more complicated data structure than
# image list, I think.... TODO
my @test_cases =
( [], [], [], # dummies to sync up test numbering with array index
[
"roughly_raster via_pixpat pixpat_threshold 500 fuzz 5 min w&h 10",
{
# edge_detect => 1, # not needed, and reduces accuracy
pixpat_delta_method => 'has_pixpat_changed_past_threshold',
allow_pixpat_drift => 1,
pixpat_threshold => 500,
rectangle_finder => 'boxfind_downward_via_pixpat',
forward_horizon => 3,
transverse_horizon => 4,
# looks_like_edge => 10, # TODO play with this?
# edge_contrast_cutoff => 10,
edge_contrast_cutoff => 100,
# 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 @image_cases =
( {
image_file => "$Bin/dat/images/firefox_save_as.png",
start => [350,100],
fin => 125,
},
{
image_file => "$Bin/dat/images/firefox_save_as.png",
start => [200,0],
fin => 10,
},
{
image_file => "$Bin/dat/images/rhythmbox_prefs.png",
start => [200,5],
fin => 14,
},
{
image_file => "$Bin/dat/images/rhythmbox_prefs.png",
start => [245,50],
fin => 77,
},
{
image_file => "$Bin/dat/images/gimp_open_dialog.png",
start => [470,330],
fin => 358,
},
{
image_file => "$Bin/dat/images/gimp_open_dialog.png",
start => [330,0],
fin => 11,
},
{
image_file => "$Bin/dat/images/gimp_open_dialog.png",
start => [500,1],
fin => 11,
},
{
image_file => "$Bin/dat/images/firefox_save_as.png",
start => [485,0],
fin => undef,
},
);
my $method = 'scan_for_edgey_pixpat';
foreach my $i ( 3 .. $#test_cases ) {
my $case = $test_cases[ $i ];
my $test_name = $case->[0];
my $object_attributes = $case->[1];
foreach my $image_case ( @image_cases ) {
my $image_file = $image_case->{image_file};
my $basename = ( fileparse($image_file, qr{\.png} ) )[0];
# my $expected = define_expected_via_eyeball( $basename );
my $start_point = $image_case->{start};
my $expected_y = $image_case->{fin};
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 $x0 = $start_point->[0];
my $y0 = $start_point->[1];
my $result = $bf->$method( $x0, $y0 );
# is( $result, $expected_y, "$test_name $basename start: ($x0, $y0)" );
my $tolerance = 3;
delta_within( $result, $expected_y, $tolerance,
"$test_name $basename start: ($x0, $y0)" );
}
}
Joseph Brenner,
Tue Nov 27 17:40:02 2007