视频捕捉(Markus Gritsch) http://videocapture.sourceforge.net/
我用过很多视频捕捉(Markus Gritsch) http://videocapture.sourceforge.net/这也许是做你想做的事最简单、最快的方法。
from VideoCapture import Device
from numpy import *
from PIL import Image
cam = Device(devnum=0, showVideoWindow=0) #devnum=0 means you are using the device set in 0 position probably your webcam
blackimg= cam.getImage() #this return a PIL image but I don't know why the first is always black
#blackimag.show()#try to check if you want
image=cam.getImage() #this is a real image PIL image
imgarray = asarray(image) #convert the image into a matrix
#imgarrayfloat = imgarray.astype('float') # in many cases of processing you have to convert to a float matrix because can occur overflow (e.g. for average images summing pixels values of 255 and 3 of two images and divide by 2 gives you 1/2 for imgarray and 258/2 for imgarrayfloat
#recovertedimage=processedimage.astype ("uint8")#if you use the previous you have to reconvert to unit8. Note processedimage is the name of the variable of your image.
Python OpenCV:cv2 和 cv http://opencv.org/
您可以使用 Python 绑定来完成OpenCV http://opencv.org/也。至少有两种方法可以做到这一点。我发现了this http://jayrambhia.wordpress.com/2012/05/10/capture-images-and-video-from-camera-in-opencv-2-3-1/ and this http://codeplasma.com/2012/12/03/getting-webcam-images-with-python-and-opencv-2-for-real-this-time/教程很有趣。
视频截取 http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#VideoCapture
from cv2 import *
cam = VideoCapture(0) #set the port of the camera as before
retval, image = cam.read() #return a True bolean and and the image if all go right
cam.release() #Closes video file or capturing device.
在这种情况下,你有一个numpy.ndarray
(不再有 PIL 图像)因此要在 shell 中显示图像类型:
import matplotlib.pyplot as plt
plt.imshow(image)
使用 CaptureFromCAM 的旧方法
import cv2.cv as cv
import numpy as np
Capture = cv.CaptureFromCAM(0)
image = cv.QueryFrame(Capture) #here you have an IplImage
imgarray = np.asarray(image[:,:]) #this is the way I use to convert it to numpy array
你可以像上面那样显示它。