views:

525

answers:

2

I'm trying to write a program to control a robot by interpreting frames from a webcam and happened upon GStreamer.

I've been able to stream video in Python from the webcam with GStreamer with help from this page: http://www.ndeschildre.net/2008/04/04/python-power/

However, I don't know how to ask for a single RGB-encoded frame from the Pipeline, and while I've managed to find and read some of the documentation, I've found no obvious answer.

Does anyone have any ideas?

EDIT: I've attempted to use OpenCV to solve this problem first, but the buffer isn't staying put or something, and is causing successive images to not start at the top left corner of the buffer. (operating system is Ubuntu Linux)

+1  A: 

Look at the source code for cheese, the Gnome photobooth application.

You could also try the usersink.

joeforker
Could you elaborate on using the usersink?
Raceimaztion
The usersink basically lets your code process raw gstreamer frames. Alas, I can't elaborate on using it for video. The cheese application can take stills from a webcam and is full of useful example code.
joeforker
Thanks for this, I think I've got a handle on it thanks to Cheese's source. (not officially solved, but you've pointed my in the right direction)
Raceimaztion
+1  A: 

I've heard of some success with OpenCV's Python bindings. Here is one of those successes: http://blog.jozilla.net/2008/06/27/fun-with-python-opencv-and-face-detection/

timv
I started out using OpenCV's Python bindings, but had to upgrade the OS version to get the webcam to work, and it suddenly didn't work anymore.(the picture wasn't reliably being copied from the buffer, so I've given up on it)
Raceimaztion
Did you looked at Willow Garage's OpenCV bindings http://opencv.willowgarage.com/wiki/PythonInterface? There are many "home-brewed" Python bindings which I'm not sure about...
timv
What OS? if you're on Ubuntu you can get an old version (not version 2.0) of OpenCV and python bindings via "apt-get install python-opencv", I was able to get that to work with out hacking around here is an example script I worked on a bit a few months ago:http://www.cs.umass.edu/~timv/opencv-example.py It's based I found online, but I lost the reference.. apologies to the original author. There is a fair amount of "irrelevant" code in there because I wanted to convert to the OpenCV Images to PIL Images.. this also makes it pretty slow.
timv
One more thing. There is another project which might interest you: http://code.astraw.com/projects/motmot/fview.html I bookmarked it a while ago and haven't really look into it too much.
timv
Unfortunately, the problem lies in OpenCV, not how it's used. Something about the buffer not getting indexed properly between frames. Your code seems to be doing the same thing that opencv.adapters.Ipl2PIL() does, but also much more slowly.This is why I'm trying to use GStreamer.
Raceimaztion