Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

JAPHoto.pl!

by fundflow (Chaplain)
on Oct 22, 2000 at 05:08 UTC ( [id://37817]=CUFP: print w/replies, xml ) Need Help??

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.

Replies are listed 'Best First'.
(bbq) RE: JAPHoto.pl!
by BBQ (Curate) on Oct 23, 2000 at 21:28 UTC
    Way cool!! But I didn't quite get the purpose of the output PPM. What was that again? (and on a side note: my out.ppm came out with little specs on them, or maybe this is intentional?)

    #!/home/bbq/bin/perl
    # Trust no1!
      The speckles are intentional and "support the analysis" :)

      Some people, probably non spiritual ones, would say that what the program does is to find the string 'Just Another Perl Hacker' in your photo. Each speckle in the output image corresponds to one letter of the string.

      But according to the rule "The simple solution is the right one", the correct explanation is that these are sun spots that reflect your personality :)

      "Perl, is it in you?" (if so, what percent?)

      Glad you like it,

RE: JAPHoto.pl!
by b (Beadle) on Oct 22, 2000 at 17:28 UTC
    This is a 5-hacker!
    Perl is 2.55% of his personality

RE: JAPHoto.pl!
by the_slycer (Chaplain) on Oct 24, 2000 at 22:50 UTC
    Interesting..

    My baby is a 52-hacker, 22.76% of her personality - that bodes well for the future. However, my baby and me turns out to be a 32-hacker, which is 25.24% of our personality. So, I guess I'm somewhere around 2.5%... :-)
Re: JAPHoto.pl!
by steveAZ98 (Monk) on Nov 21, 2000 at 02:54 UTC
    Very cool, this is the output I got.
    Just Another Perl HackerJust Another Perl HackerJust Another Perl Hack +erJust Another Perl HackerJust Another Perl HackerJust Another Perl HackerJust Another Per +l HackerJust Another Perl HackerJust Another Perl HackerJust Another P This is a 9-hacker! Perl is 9.20% of his personality
    Another boring afternoon at work :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://37817]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-23 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found