Roomba Robot Upgrade

Building Robots and Engineers

Controlling the Creative Live! Motion Cameras

  • December
  • 18

The pan/tilt cameras used in this project are Creative Live! Motion cameras which connect to the host machine via a USB connection. They are capable of caturing video, still frames, and mechanically panning and tilting. The goal is to snap two images of the same view, one with a laser line and one without. The two images can then be processed, and by discovering where the laser line lies in the image, we can tell how far away an object is in the camera’s view.
Controlling these cameras proved to be much more of a task than origninally anticipated. Since the development environment chosen was Java, some research was done to find existing code and libraries used to control webcams. Snapping an image was relatively straightforward. It involves installing the Java Media Framework (aka JMF or javax.media) package onto the host machine (available at http://java.sun.com/products/java-media/jmf/2.1.1/download.html). This provides the software libraries needed to discover and send commands to the webcam. Once the software is installed, you might need to connect the webcam and run the included “JMF Registry” application and ensure that the camera is listed under discovered devices. In my experience, the camera was not listed, and I had to manually attempt to discover new media devices. When this was performed on my computer, the discovery process took quite a substantial amount of time (approx 15 minutes) during which the computer gave little or no signs of progress—be patient, as it does work!
The JMF library will allow you to discover the camera as a media device and use it to snap images; however it does not provide any framework to manipulate the pan/tilt features of the camera. The only way to access these controls is via the operating system’s DirectShow SDK interface. Unfortunately, Java does not directly support DirectShow and this presents a great problem if one wishes to control pan/tilt using Java. There are two solutions that I have discovered, and there may possibly be more, especially in the months to come since this is a new feature that is just becoming popular.
The first solution is one that I personally recommend against. It is a software library called “DSJ”, or DirectShow Java wrapper. It is a sparsely-documented 3rd-party Java package that is supposed to provide DirectShow implementation to Java (website: http://www.humatic.de/htools/dsj.htm). I have been 100% unsuccessful in figuring out how to implement this software to control the camera, however it is supposed to be possible, so this may be worth taking a closer look at.
The second solution is one that I recommend over the first, however it will require some coding in C++ and some more complex forms of integration between two completely separate threads running on the host machine. There is an open-source software program that I discovered, designed for Logitech QuickCam devices (another line of pan/tilt/zoom, or PTZ, cameras), which seems to control the Live!Motion camera just fine. It uses DirectShow (since in C++ you can interface with it directly) and seems relatively straightforward. Currently, the provided C++ code simply opens a console window and attempts to grab control of the camera, pans it right, left, up, and down, and then exits. The code should be quite easy to modify to suit our needs, however the main problem will be to integrate this code to make it controllable by our Java code.
The Java code that I have so far begins with an example program I found online called JWebCam.java (http://vase.essex.ac.uk/software/ecj-imaging/code/ac/essex/ooechs/imaging/commons/apps/webcam/JWebCam.java.html). Several parts of the code were modified, most notably the MySnapshot class and the toolbarHandler method, where the code currently grabs two images, approximately 10 seconds apart (for testing purposes) and stores them as Java Image objects. Buttons were also added to this toolbar to control pan/tilt but are as of yet non-functioning. The two Image objects can be quite easily converted to bitmaps, at which point they can be subtracted and processed to discover where the laser-line is located.
Overall, controlling this camera proved to be quite more complicated than originally estimated, and much was learned through weeks of research and discovering that little information was available, especially with respect to controlling the PTZ features of a webcam in Java. Included in the accompanying .zip file are the DSJ and JMF packages, the C++ code and executable that seems to control the webcam just fine “out-of-the-box”, and the JWebCam.java source file I was working with. It should be relatively straightforward to use this provided software and continue working towards our final goal of panning, tilting, snapping an image, turning on the laser, snapping a second image, turning off the laser, and processing the two images to come up with a calculated distance.

Click here to download the .zip file containing all source files and packages used during the F07 semester portion of this project!

Leave a comment!


e-mail (required, but will not be published)


Message

 

© 2007 Roomba Robot Upgrade. Blog theme by blogstheme.com, debt consolidation.