人脸识别
import cv2
faceModel = cv2.CascadeClassifier('./haarcascade_frontalface_alt.xml')
capture = cv2.VideoCapture(0)
while True:
ret,image = capture.read()
gray = cv2.cvtColor(image,cv2.COLOR_RGB2GRAY)
faces = faceModel.detectMultiScale(
gray,
scaleFactor=1.15,
minNeighbors=5,
minSize=(5, 5),
)
print("发现{0}个人脸!".format(len(faces)))
for(x,y,w,h) in faces:
cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,255),2)
cv2.imshow('人脸识别摄像头',image)
if cv2.waitKey(5) & 0xFF == ord('q'):
break
capture.release()
cv2.destroyAllWindows()