usa la libreria OpenCV (Open Source Computer Vision)
Código
from opencv.cv import * from opencv.highgui import * cvNamedWindow("w1", CV_WINDOW_AUTOSIZE) captura = cvCreateCameraCapture(0) def calcular( image ): escala = cvCreateImage(cvSize(image.width, image.height), 8, 1) cvCvtColor(image, escala, CV_BGR2GRAY) storage = cvCreateMemStorage(0) cvClearMemStorage(storage) cvEqualizeHist(escala, escala) cascade = cvLoadHaarClassifierCascade( 'haarcascade_frontalface_default.xml', cvSize(1,1)) caras = cvHaarDetectObjects(escala, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(25,25)) ret = [] if caras: for cara in caras: vertices_imagen = {} vertices_imagen['x1'] = cara.x vertices_imagen['y1'] = cara.y vertices_imagen['x2'] = cara.x+cara.width vertices_imagen['y2'] = cara.y+cara.height ret.append( vertices_imagen ) return ret def bucle(): global captura ancho = 160 alto = 120 frame = cvQueryFrame(captura) imagen = cvCreateMat(alto, ancho,cvGetElemType( frame )) cvResize(frame, imagen) vertices = calcular( imagen ) for vertice in vertices: cvRectangle( imagen, cvPoint( int(vertice['x1']), vertice['y1']), cvPoint(int(vertice['x2']), int(vertice['y2'])), CV_RGB(0, 255, 0), 3, 8, 0) cvShowImage("w1", imagen) c = cvWaitKey(2) while True: bucle()
dejo link donde lo encontre http://www.retronet.com.ar/?p=474