Eye Tracking – The Eye Camera

Photo of a camera lens in an eye

In this post I’ll be describing how I made a head mounted IR camera for tracking where a person is looking. I’ve been working on getting low-cost home brew eye tracking running on my Mac. I want the computer to know where I’m looking on the screen and to be able to interact with my gaze. My first attempt uses a head mounted IR camera to determine the pupil position and a second remote camera to detect the head position relative to the screen.

Picture Rachel Chapman.

I was inspired by the OpenEyes project which provides open-source software and hardware for constructing low cost real-time eye tracking. Their hardware designs are focused on mobile eye tracking – that is eye tracking whilst a person is freely moving around. They use two head mounted cameras: a scene camera and an eye camera. I’m only interested in where someone is looking on a fixed screen so I only use one head mounted camera focused on the pupil.

The eye camera

I converted a cheap webcam to be used as the head mounted eye camera. The webcam was modified in two major ways: firstly it was converted into an IR web cam by swapping the infrared filter for an visual light filter; secondly I swapped the standard lens for a telephoto lens. As ever the usual disclaimer applies.

I’m using “dark pupil” tracking which requires an image of the eye under IR light. Under these conditions the pupil is dark and strongly contrasts with the surrounding iris. I experimented with an old Apple iSight web cam. I had several problems with it  though. Firstly it was big and heavy so it obscured the user’s view of the screen and was difficult to fix to the head. The iSight has a nice autofocus glass lens, which gives you lovely crisp images. However, the autofocus mechanism would sometimes get confused and would get into cycles of focusing on the eye then trying to focus further away. Since the camera is going to be fixed relative to the eye a manual focus camera seems more approprate. Note that the focus of the iSight can be set by software using either comercial products like iGlasses or programmatically though IIDC (see iSight Programming Guide).

I bought a manual focus Logitech QuickCam Deluxe. Here’s how I removed the casing and got to the lens:

Logitech QuickCam Deluxe

Logitech QuickCam Deluxe

You just need a Phillips #00 Screwdriver to remove all the screws.

1) Undo the three screws on the back.

2) Gently pull the back away - note you need to disconnect the usb wire from the circuit board by pulling the white plug towards the top of the webcam.

3) Unscrew the two silver screws at the edges that hold the board onto the front of the case. The two black screws hold the lens mount onto the board - leave them for now.

The exposed web cam board. The microphone funnel in the middle just pulls straight off.

Undo the black screws on the back of the board to release the lens mount - the CCD chip is now very exposed: make sure you don't touch it or let it get dusty. The lens just unscrews from the mount. Tomake the camera only sensitive to IR light I cut out a piece of unexposed developed print film to act as a visual light filter. This film was placed in the lens mount (between the mount and lens - not between the mount and board).Â

The IR filter is on the back of the lens so you just need to rub it with a finger nail to scrape off the filter - this took a while. You needn't remove the lens elements if you are not going to use the telephoto lens. If you are going to use another lens you can just pick off the glued in plastic ring at the back and push the front of the lens to remove all the elements.

The element of the len after the filter was scratched off.

Changing the lens

To get the image of the eye to fill the frame using the regular lens required the camera to be only a few cm from my eye. The close placement obscured part of my view of the screen and made lighting the eye with the IR LED very challenging. By swapping the webcam lens for a telephoto lens I could position the camera further from the eye solving these two problems – and it only cost $3.25!

The telephoto lens on the left and the old lens casing on the right.

I bought a lens with a 12mm focal length for just $3 on eBay. The telephoto lens mount as M12 x 0.5 – this means that the diameter of the barrel of the lens in 12mm – unfortunately the webcam lens had more like an 8mm diameter. The proper lens would have been more expensive so I just spend 25c on some plastic hose with about a 10mm internal diameter. I used a 1cm long piece as a collar to attach the old lens housing (with the elements removed) to the telephoto lens.

The 25 cent hose I used to connect the new and the old lens cases.

Wrapping up

With the case off the webcam the CCD detected light that was coming through the circuit board. To block this light I wrapped it in a layer of plastic wrap, a layer of foil and then another layer of plastic wrap. I then attached two IR LEDs to it and it was ready to be attached to my head mount. I also tried to power the IR LEDs from the webcams “working” LED. I removed the blue surface-mount LED and connected an IR LED. The connections were very fiddly and fragile and LED only shone dimly. I’d not bother if I were to do it again. Instead I’m powering the LEDs from a separate USB port.

The completed eye camera in its clamp

2 thoughts on “Eye Tracking – The Eye Camera

  1. hi. I’m working on a similar project, tracking IR light patterns. I was wondering how you implemented your code looking for contrast for a usb webcam. did you write a new driver for the camera? or use a special program?

    hoping you can help. thanks

    • Hey,

      The contrast seems to be appropriately handled by the standard USB driver. I’m on Mac OS X which supports webcams using UVC. I’ve mostly been using OpenCV which allegedly allows you to directly control the contrast of your camera using the VideoCapture::set method. I say allegedly since I’ve been having trouble getting video capture timestamps from the OpenCV interface. I’ve been having all sorts of trouble getting the QTKit based VideoCapture to get me two synced video feeds – but thats another story.

      You can also adjust to contrast of an image received from the webcam programmatically using something like this algorithm.

Comments are closed.