2

So I made a little script which tracks the face, then search for the two eyes, then for each eye, left and right.

The problem is, even with left and right it overlaps both.

i = Camera().getImage()
face = i.findHaarFeatures("face.xml")
if face != None:
    face =  face[0].boundingBox()
    face = i.crop(face)
    twoeyes = face.findHaarFeatures("two_eyes_big.xml")
    if twoeyes != None:
        righteye = face.findHaarFeatures('right_eye.xml')
        lefteye = face.findHaarFeatures('lefteye.xml')
        if righteye != None and lefteye != None:
            print righteye,lefteye
            righteye = righteye[0].draw()
            lefteye = lefteye[0].draw()
            face.show()

findHaarFeatures Two eyes overlapping

the print shows that:

[SimpleCV.Features.Detection.HaarFeature at (61,67)] [SimpleCV.Features.Detection.HaarFeature at (60,65)]

I tried cropping the face with the face.boundingBox(twoeyes) and them search for the left and right but it always gives me (None, None).

Also I'm having a problem with findHaarFeatures("face.xml") when it gives me more than 1 face, I overcome this by just picking the first one in the list, but I would like to pick the biggest of them, how can I compare the size of two Features?

And at last, is there a better way to do the find of a features inside other instead of using the crop and the if-statement 'something != None'?

Btw, I'm using the raw image from the camera, is it better to treat it with some contrast, saturation, findedges or anything else to better find features?

f.rodrigues
  • 3,499
  • 6
  • 26
  • 62

1 Answers1

0

The following code will work to detect the eyes in with a reduced ROI (region of interest) that is the face.

I too am using the cropping technique to make the ROI smaller.

img = Camera().getImage()
face = img.findHaarFeatures("face.xml")

    if face: #checks for non empty feature set
        face = face.sortArea() #sorting all detected faces by area
        face = face[-1] #picking the largest face
        face = img.crop(face) #crops face from the image

        leftEye = face.findHaarFeatures("lefteye.xml")
        leftEye.draw()

        rightEye = face.findHaarFeatures("right_eye.xml")
        rightEye.draw()
        face.show()

The detection of right eye and left eye both give overlapping results because both end up detecting both right and left eyes.

To use this to advantage you can take the mean of both the results to produce one pair of eyes.

I have tried the above in a raw video stream from the webcam, it yields decent results with untreated stream.

Nakul
  • 11
  • 1