Static Face and Eye detection in Python [closed]

asked 2013-03-24 19:35:03 -0500

Chymera gravatar image

updated 2013-03-24 19:57:19 -0500

Hello guys, I know this is a rather popular question to ask - but none of the cases I found particularly addressed my issue. I am using opencv via the python bindings and I am using this script to autorotate and mask face pictures

I am using haar cascades for face and eye detection.

I use the cascades like this:

def Load(picture):
    pic = cv2.imread(picture)
    faceCasc = cv2.CascadeClassifier('/usr/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml')
    leyeCasc = cv2.CascadeClassifier('/usr/share/OpenCV/haarcascades/haarcascade_lefteye_2splits.xml')
    reyeCasc = cv2.CascadeClassifier('/usr/share/OpenCV/haarcascades/haarcascade_righteye_2splits.xml')
    eyesCasc = cv2.CascadeClassifier('/usr/share/OpenCV/haarcascades/haarcascade_mcs_eyepair_small.xml')
    return(pic, faceCasc, leyeCasc, reyeCasc, eyesCasc)

and call them like this:

leye = leyeCasc.detectMultiScale(smallimg, haar_scale_eye, min_neighbors_eye, haar_flags_eye, min_size_eye, max_size_eye)

Sadly I have to play with the parameters a LOT to get the cascades to work at all - and even when they do ~2/3 of my pics get false negatives/positives. My pictures are very sharp and very high resolution (~3k x 5k - the faces are ~1/9 of that).

I recently came across this article

Which seems really great, but sadly I could not figure out how/whether these methods can be used to give me a simple square (maybe even circle/ellipse?) delineating the features I am looking for. Also, is there anything similar for eye detection? Or will I have to continue relying on haar cascades for that?


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-19 15:27:59.024339



i think, you should first find a face, and then restrict the eye-search to that region, you seem to do the eye-search on the whole img, and then an independant face search afterwards

berak gravatar imageberak ( 2013-03-25 02:11:56 -0500 )edit

can I set a ROI for the face area while still getting coordinates relative to the entire picture?

Chymera gravatar imageChymera ( 2013-03-25 14:19:03 -0500 )edit

if you're using ROIs, you'll get coords relative to that, but to get the coords for the 'whole' picture, it's just adding the x,y offset from the ROI, right ?

berak gravatar imageberak ( 2013-03-25 14:25:36 -0500 )edit

True--- but I've checked m eye detection again, and what you suggest would probably only improve m speed (which I have no issues with). I'm not getting any off-face eye detection - it's just that I either get the same eye multiply detected or left/right eye cross-detection. Any idea what I can do about that? how come haar cascades don't have rule for merging overlapping feature detects?

Chymera gravatar imageChymera ( 2013-03-25 16:32:32 -0500 )edit