Saturday, May 16, 2015

Using a PS3 eye toy with OpenCV

I was looking for a USB webcam that I could use for doing some openCV/digital control systems projects. The PS3 Eye seems like a great product for this!
  • $7 on Amazon!!
  • Standard USB interface
  • 640 x 480 resolution. Not great but...
  • 60 fps framerate, up to 120 fps with lower resolution (320x240)
  • Did I mention...$7?!

So I tried this out with a simple program I wrote in OpenCV, and after actually writing a frame-rate counter I realized that I actually wasn't running it at 60fps! Hmmm. Turns out you need to do a little bit of work to get the settings just right.

Video for Linux (libv4l2

You can get access to the more advanced features of camera by using a library called video for linux. On ubuntu, I installed an application called qv4l2 and all the necessary dependencies. It looks like this(when I first start it up, it shows my video0 device, which is my laptop's webcam)

Now, you need to open up the PS3 Eye. Usually this is under the device /dev/video1:

The "open file" dialog is a little strange because it doesn't show the device until you acutally type in the full name.

Once the PS3 Eye is open, you have access to all the settings that can be changed through the USB protocol! In addition to the screen above, there are more parameters that can be changed:


Manual exposure and gain are especially handy if you're trying to track some objects and you don't want the camera to be adjusting the brightness/contrast if bright objects are entering the scene. Also, a darker exposure will have less motion blur, and a lower gain will have less grain/noise, at the cost of brightness.

Here are some examples below from my tests waving a laser around:

Auto exposure, 30fps

60fps, manual exposure

Using the Eye with OpenCV

On my system using Ubuntu, I didn't need to do anything special to get the Eye to work with OpenCV. I just needed to pass the video device ID (in my case 1) to the VideoCapture.open() command.

The exposure settings and the framerate can be changed from qv4l2 while your openCV app is running. However, you can also have your openCV app change the settings directly. Additionally, some settings, like the capture frame size cannot be set in qv4l2 while openCV is running.

The VideoCapture object in OpenCV has the method set(propID, value) which lets you change any of the settings above. However, I've had trouble actually getting it to work. I have read something about needing to compile openCV with v4l2 support, so I am going to give that a shot.

6 comments:

  1. Hey, I was interested in this post, (excited to see its quite recent one).
    I had one qury what is final FPS you got by appling all tuned settings?

    ReplyDelete
  2. I got mine for playing with voice recognition, hearing the Eye had one of the better room mics out there. Haven't done much with it yet.

    ReplyDelete
  3. 120 fps for $7 is great! Is it also working with Windows?

    ReplyDelete
  4. these cameras are great. very low latency unlike regular webcams. For windows you nee dthe driver. now behind a paywall. but worth it IMHO. $3. from here: https://codelaboratories.com/products/eye/driver/

    ReplyDelete
  5. Thank you so much for this blog post Henry! I spent a long time trying to get the PS3 Eye working on Ubuntu 14.04 and this finally did the trick.

    ReplyDelete
  6. Hi, thanks this post. This is what i need right now and i can worked it thanks to you. But ı have a problem. I can set up to 240x320-187fps but I cant see over 60fps. Do you have an idea about my problem? Thanks again.

    ReplyDelete