File Coverage

blib/lib/Image/libsiftfast.pm
Criterion Covered Total %
statement 15 50 30.0
branch 0 4 0.0
condition 1 2 50.0
subroutine 5 7 71.4
pod 3 3 100.0
total 24 66 36.3


line stmt bran cond sub pod time code
1             package Image::libsiftfast;
2 4     4   1881 use strict;
  4         9  
  4         142  
3 4     4   23 use warnings;
  4         7  
  4         154  
4 4     4   4460 use File::Which qw(which);
  4         5389  
  4         298  
5 4     4   6022 use Imager;
  4         266148  
  4         33  
6              
7             our $VERSION = '0.03';
8              
9             sub new {
10 3     3 1 39 my $class = shift;
11 3   50     22 my $self = bless {
12             siftfast_path => which("siftfast") || undef,
13             imager => Imager->new,
14             @_,
15             }, $class;
16 3         951 return $self;
17             }
18              
19             sub convert_to_pnm {
20 0     0 1   my $self = shift;
21 0           my $file = shift;
22              
23 0           my $imager = $self->{imager};
24 0 0         $imager->read( file => $file ) or die $imager->errstr;
25 0           my $new = $imager->convert( preset => 'grey' );
26 0           $file =~ s/jpg/pnm/;
27 0 0         $new->write( file => $file, type => "pnm", pnm_write_wide_data => 1 )
28             or die($!);
29 0           return $file;
30             }
31              
32             sub extract_keypoints {
33 0     0 1   my $self = shift;
34 0           my $pnm_file = shift;
35              
36 0           my $siftfast_path = $self->{siftfast_path};
37 0           my @stdout = `$siftfast_path < $pnm_file 2>&1`;
38              
39 0           my $stderr_message = shift @stdout;
40 0           $stderr_message .= shift @stdout;
41 0           my ($image_size)
42             = $stderr_message =~ /Finding keypoints \(image ([^\)]+)\).../g;
43 0           my ( $keypoint_num, $elapsed )
44             = $stderr_message =~ /(\d+) keypoints found in ([0-9.]+) seconds./g;
45              
46 0           my @array = map { chomp $_; $_ } @stdout;
  0            
  0            
47 0           shift @array; # remove first line;
48 0           my $return_string = join( "\n", @array );
49              
50 0           my @keypoints;
51 0           for ( split "\n\n", $return_string ) {
52 0           my @rec = split "\n", $_;
53 0           my @array;
54 0           for (@rec) {
55 0           my @f = split " ", $_;
56 0           push @array, @f;
57             }
58 0           my $X = shift @array;
59 0           my $Y = shift @array;
60 0           my $scale = shift @array;
61 0           my $orientation = shift @array;
62 0           my $vector = \@array;
63              
64 0           push @keypoints,
65             {
66             frames => {
67             X => $X,
68             Y => $Y,
69             scale => $scale,
70             orientation => $orientation,
71             },
72             vector => $vector,
73             };
74             }
75              
76             return {
77 0           keypoint_num => $keypoint_num,
78             elapsed => $elapsed,
79             image_size => $image_size,
80             keypoints => \@keypoints,
81             };
82             }
83              
84             1;
85             __END__