Do you often find yourself inteviewing someone for your
next big perl project and just can't tell how good is he?
If so, this code is for you!
It uses the most sophisticated computer vision techniques.
All you need to do is supply the program with a picture of
the person in question.
Run this code with a picture of the candidate, and see
if he is Just Another Perl Hacker or not.
Be warned! this code uses hyper-trancedental ether waves to
make the psychologycal analysis.
Usage: JAPHoto.pl candidate.ppm out.ppm
(sorry, only .ppm is supported.
Use 'convert candidate.jpg candidate.ppm' or 'xv' to convert it)
output image is optional, just to support the analysis :)
For example:
>JAPHoto.pl merlyn.ppm
This is a 8-hacker!
Perl is 8.78% of his personality
How much do you get? Enjoy!
#!/usr/bin/perl -w
my ($image, $h, $w)=&load_ppm($ARGV[0]);
my $s=3*$h*$w;
my @A=unpack("C$s", $image);
my $l="AnREaHTtEePZahPZcarJsWPZ";
my $p=0;
my $i;
$l=~tr/PoZuTsEcRalnAeJhMHktrW/eMrEnctls ZuJhaPTARoHk/;
for($i=0; $i<$s-3; $i++) {
if(chr($A[$i]) eq substr($l, $p%24, 1)) {
my $i=$i - $i%3;
print substr($l, $p%24, 1); #chr($l[$p]);
$p++;
$A[$i] = $A[$i]>127?0:255; $i++;
$A[$i] = $A[$i]>127?0:255; $i++;
$A[$i] = $A[$i]>127?0:255;
}
}
printf "\nThis is a %d-hacker!\nPerl is %.2f%% of his personality\n",
int($p/24), 100*$p/$s*3*24;
if ($ARGV[1]) {
$image = pack("C$s", @A);
&write_ppm($ARGV[1], $image, $h, $w);
}
0;
# Thanks to Corion,jcwren,tilly
sub load_ppm {
my $name=shift || die;
my $image;
open(F, "<$name") || die;
$_=<F>;
die "$name is not a PPM file, (header=$_)\n" unless($_ eq "P6\n");
do { $_=<F> } while ( m/^\#/ ); # skip comments
my ($w, $h) = m/(\d+)\D+(\d+)/;
$_=<F>;
die "Can't deal with this type of PPM\n" unless ($_==255);
binmode(F); # just in case
$_=read(F, $image, 3*$h*$w) or die;
close(F);
return ($image, $h, $w);
}
sub write_ppm {
my ($name, $image, $h, $w) = @_;
open(F, ">$name") or die;
binmode F;
$_=sprintf "P6\n$w $h\n255\n";
print F "$_$image";
close(F);
}
(THIS what happens when you work on weekends :)
Seriously though, it's been a while that i wanted to write some
image-processing code with perl, mostly for fun, and this
code can be used to input/output images fairly efficiently
for further processing.