python+opencv之视频人脸识别
2010年06月30日
import sys
from CVtypes import cv
def detect(image):
image_size = cv.GetSize(image)
# create grayscale version
grayscale = cv.CreateImage(image_size, 8, 1)
cv.CvtColor(image, grayscale, cv.BGR2GRAY)
# create storage
storage = cv.CreateMemStorage(0)
cv.ClearMemStorage(storage)
# equalize histogram
cv.EqualizeHist(grayscale, grayscale)
# detect objects
cascade = cv.LoadHaarClassifierCascade('haarcascade_frontalface_alt.xml', cv.Size(1,1))
faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2, cv.HAAR_DO_CANNY_PRUNING, cv.Size(350, 350))
print faces
if faces:
print 'face detected!'
for i in faces:
cv.Rectangle(image, cv.Point( int(i.x), int(i.y)),
cv.Point(int(i.x + i.width), int(i.y + i.height)),
cv.RGB(0, 255, 0)