Thursday, March 24, 2011

Detect eyes in an Image

In this article we discuss on how to detect eyes in an image using OpenCV.

Btw, My other programs in OpenCV will be posted here

I am sure that many of you have tried to use the OpenCV's eye detector. It doesn't really give you good performance. I've been looking out on the web for many good eye detector Haar cascade. I've found one at (site is a little slow be patient. I downloaded the file using wget:

The above file is also available at Google Code. You can download it using:

I would suggest you to go ahead and download the file. The zip file contains ojoD.xml (right eye), ojoI.xml (left eye). There is another haar classifier i.e. parojos.xml which works for both eyes. This work pretty decently(the ojoD.xml and ojoI.xml misinterpret left as right and vice-versa many a times so they'r not reliable in detecting a specific eye whereas, the other which detects both eyes works perfectly).

Basically we do it in OpenCV using the following:

  • declare haarcascade, storage, image, camera capture structures.
  • initialize haarcascade to the xml file (downloaded) and other declared structures.
  • Capture the stream from the camera, apply cascade and detect eyes.
  • Draw a rectangle around the eyes and show it.

The following is the code is in C++:

1 comment:

  1. This is weird! I don't think there is any error with the program. I checked it again on Linux. I'm using OpenCV 2.3