What's the best library for video capture in Python on linux? [closed]
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
开发者_JAVA百科 Improve this questionI want to write an application to video capture from web-cams in linux. Is there a python library to do that?
You should look at Gstreamer and its Python bindings. Here http://pygstdocs.berlios.de/pygst-tutorial/webcam-viewer.html is some sample code to display video from a webcam. To record the video you would have to change the pipeline definition from autovideosink
to an encoder and filesink.
You could look into WebCamsPy, which appears to do what you are asking.
Also, see a related question, which asks more generally for windows and Linux but might still help you.
OpenCV is the easiest thing I've seen. Take a look at this post: http://www.jperla.com/blog/2007/09/26/capturing-frames-from-a-webcam-on-linux/
You can $ sudo apt-get install python-opencv
(I believe), as well as pygame and PIL if you haven't already installed them. Once you have those libraries you can start viewing/saving images - technically if you just want to capture you don't need to use pygame, but it does allow you to also view the images. Technically speaking, the "meat" of the work is done with PIL and opencv, so you can use any type of graphical framework (gtk, tk, wx, qt, etc) that you're familiar with.
I've been trying to do something like this with mine, and I've been getting a crash course in PIL, and it's actually a pretty easy library to use, though I think I'll really need to include numpy for processing in that mix...
Anyway, opencv+PIL == super easy.
If you have a favorite video capture C library, you can probably write a simple facade to it using the ctypes module.
there is a lib called open-cv. Try that. It has a lot of features for handling images as well.
精彩评论