| 1 | #!/usr/bin/perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use Imager; |
| 6 | use Image::ObjectDetect; |
| 7 | |
| 8 | my $file = '2.jpg'; |
| 9 | #my $file = 'input.jpg'; |
| 10 | my $image = Imager->new->read(file => $file); |
| 11 | |
| 12 | my @cascades = ( |
| 13 | #'/usr/share/opencv/haarcascades/haarcascade_frontalface_default.xml', |
| 14 | #'/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml', |
| 15 | '/usr/share/opencv/haarcascades/haarcascade_frontalface_alt2.xml', #less sensitive |
| 16 | #'/usr/share/opencv/haarcascades/haarcascade_frontalface_alt_tree.xml', |
| 17 | #'/usr/share/opencv/haarcascades/haarcascade_profileface.xml', |
| 18 | |
| 19 | #'/usr/share/opencv/haarcascades/haarcascade_upperbody.xml', |
| 20 | #'/usr/share/opencv/haarcascades/haarcascade_lowerbody.xml', |
| 21 | #'/usr/share/opencv/haarcascades/haarcascade_fullbody.xml', |
| 22 | |
| 23 | #'/usr/share/opencv/haarcascades/haarcascade_mcs_eyepair_small.xml', |
| 24 | #'/usr/share/opencv/haarcascades/haarcascade_mcs_eyepair_big.xml', |
| 25 | ); |
| 26 | |
| 27 | my @faces; |
| 28 | foreach(@cascades) { |
| 29 | push (@faces, detect_objects($_, $file)); |
| 30 | } |
| 31 | |
| 32 | for my $face (@faces) { |
| 33 | my $file2 = 'paroubek.jpg'; |
| 34 | my $image2 = Imager->new->read(file => $file2); |
| 35 | $image2 = $image2->scale(xpixels => $face->{width}, ypixels => $face-> |
| 36 | {height}); |
| 37 | $image->paste(left => $face->{x}, top => $face->{y}, src => $image2); |
| 38 | } |
| 39 | |
| 40 | $image->write(file => 'output.jpg'); |
| 41 | |
| 42 | print "Content-type: text/html\n\n"; |
| 43 | print "<head>\n"; |
| 44 | print "<TITLE>face detect</TITLE>\n"; |
| 45 | print "</HEAD>\n"; |
| 46 | print "<BODY>\n"; |
| 47 | print "<br>\n"; |
| 48 | print "<img src='input.jpg'>\n"; |
| 49 | print "<img src='face.jpg'>\n"; |
| 50 | print "<img src='output.jpg'>\n"; |
| 51 | print "</BODY>\n"; |
| 52 | print "</HTML>\n"; |