I would like to access my webcam from Python.
I tried using the VideoCapture extension (tutorial), but that didn't work very well for me, I had to work around some problems such as it's a bit slow with resolutions >320x230, and sometimes it returns None
for no apparent reason.
Is there a better way to access my webcam from Python?
The only one I've used is VideoCapture, which you've already mentioned you don't like (although I had no problems with it; what bugs did you encounter?)
I was unable to find any alternatives in the past or now, so you might be stuck either using VideoCapture, or finding a nice C library and writing a Python wrapper for it (which might be more work than you're willing to put into it).
gstreamer can handle webcam input. If I remeber well, there are python bindings for it!
This should have been a comment to @John Montgomery, but my rep does not allow me to make comments. Your answer is great, but at least on Windows, it is missing the line
before
Without it, the camera resource is locked, and can not be captured again before the python console is killed.
OpenCV has support for getting data from a webcam, and it comes with Python wrappers by default, you also need to install
numpy
for the OpenCV Python extension (calledcv2
) to work.At the time of writing (January 2015) there is no Python 3 support yet, so you need to use Python 2.
More information on using OpenCV with Python.
An example copied from Displaying webcam feed using opencv and python: