Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
face_detection:torch3vision [2009/05/26 10:55] – gerald | face_detection:torch3vision [2024/02/29 13:36] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 2: | Zeile 2: | ||
{{tag> | {{tag> | ||
+ | |||
+ | jpegtopnm is obsolete under debian. Use djpeg instead | ||
+ | < | ||
[[http:// | [[http:// | ||
- | Quelle((http:// | + | Quelle |
- | You will need the C++ Compiler ' | + | You will need the C++ Compiler ' |
+ | < | ||
* Download Torch3Vision and un-tar it: tar -zxf Torch3vision2.1.tgz | * Download Torch3Vision and un-tar it: tar -zxf Torch3vision2.1.tgz | ||
Zeile 15: | Zeile 19: | ||
* Build the vison examples for face detection: cd vision2.1/ | * Build the vison examples for face detection: cd vision2.1/ | ||
| | ||
+ | |||
+ | |||
+ | Jetzt 3 Programme in neuen Unterverzeichnis '' | ||
+ | * haarscan - Schnelle, zuverlässige Erkennung | ||
+ | * mlpcascadescan - Sehr zuverlössige Erkennung, bei ganz kleinen Bildern geht es nicht richtig, grosse (> | ||
+ | * mlpscan - Seh keinen rechten Unterschied zum vorherigen. | ||
+ | |||
+ | Jedes dieser 3 Programme braucht eine Modeldatei zur Gesichtererkennung. Diese 3 Dateien liegen unter '' | ||
Zeile 25: | Zeile 37: | ||
</ | </ | ||
This command takes about 20s to run on my creaky old laptop, and creates two files. | This command takes about 20s to run on my creaky old laptop, and creates two files. | ||
+ | |||
+ | [[http:// | ||
+ | |||
+ | Parmaters (as far as i found out): | ||
+ | * -minWsize n: min size n in pixel to recognize a face | ||
+ | * -nbest n : save the best n results only | ||
+ | * -dir < | ||
+ | * -savepos | ||
+ | * -draw -> draw ppm image with detections | ||
+ | * -savejpg | ||
+ | * -verbose: tell a little bit more what you doing... | ||
+ | |||
+ | The other file ‘andy.pos’ contains the results of face detection. Line one is the number of detections, then each line has format x y w h, very easy to parse. | ||
+ | < | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ | ||
+ | I played around with the step-factors in the x and y directions to shave a second or so off the face detection routine, the values I chose were 0.1 and 0.2 respectively (I don’t need any accuracy in the y direction really, since my use is to cut the face down the middle). | ||
+ | |||
+ | Then, since these are portrait photographs, | ||
+ | < | ||
+ | WIDTH=`identify -format “%w” “andy.jpg”` | ||
+ | | ||
+ | </ | ||
+ | So now here’s the final face detection command | ||
+ | < | ||
+ | mlpcascadescan “$ppm” -dir /tmp/ -savepos -model $MODEL \ | ||
+ | | ||
+ | </ | ||
+ | And finally, as promised, I’ll tell you how to blank-out one side of the face: of course, using Image Magick. Using the ‘chop’ or ‘crop’ commands didn’t work for this purpose, where I wanted the image to keep it’s dimensions but have one half just be white. So I decided to draw a white rectangle over half of the picture. | ||
+ | < | ||
+ | convert -fill white \ | ||
+ | -draw “rectangle $FACE_CENTER, | ||
+ | | ||
+ | </ | ||
+ | |||
+ | Whole script: | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | |||
+ | . ~/ | ||
+ | |||
+ | DRAW=" | ||
+ | STEPX=" | ||
+ | STEPY=" | ||
+ | MODEL=" | ||
+ | |||
+ | # Find the center of the face in the image. Crop the image along the center of | ||
+ | # the face. | ||
+ | |||
+ | # Requirements: | ||
+ | which mlpcascadescan > /dev/null || \ | ||
+ | die " | ||
+ | |||
+ | [ -e " | ||
+ | |||
+ | FACE_CENTER="" | ||
+ | |||
+ | # Find the center of the face. Takes a jpeg and finds the face. | ||
+ | function find_center() { | ||
+ | jpeg=" | ||
+ | temp="/ | ||
+ | ppm=" | ||
+ | pos=" | ||
+ | echo " | ||
+ | jpegtopnm $jpeg > $ppm | ||
+ | if [ -e " | ||
+ | rm " | ||
+ | fi | ||
+ | HEIGHT=`identify -format " | ||
+ | WIDTH=`identify -format " | ||
+ | MIN_FACE_WIDTH=`echo $WIDTH / 6 | bc` | ||
+ | echo " | ||
+ | echo " | ||
+ | -minWsize $MIN_FACE_WIDTH -stepxfactor $STEPX -stepyfactor $STEPY" | ||
+ | mlpcascadescan " | ||
+ | -minWsize $MIN_FACE_WIDTH -stepxfactor $STEPX -stepyfactor $STEPY | ||
+ | [ -e " | ||
+ | FACE_POS=`head -n 2 " | ||
+ | FACE_X=`echo $FACE_POS | awk ' | ||
+ | FACE_W=`echo $FACE_POS | awk ' | ||
+ | FACE_CENTER=`echo $FACE_X + $FACE_W/2 | bc` | ||
+ | echo " | ||
+ | } | ||
+ | |||
+ | function crop_image() { | ||
+ | jpeg=" | ||
+ | ext=${jpeg## | ||
+ | base=`basename " | ||
+ | crop=" | ||
+ | HEIGHT=`identify -format " | ||
+ | WIDTH=`identify -format " | ||
+ | echo " | ||
+ | convert -fill white -draw " | ||
+ | } | ||
+ | |||
+ | |||
+ | for file in $@; do | ||
+ | echo " | ||
+ | find_center $file | ||
+ | crop_image $file | ||
+ | done | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ |