import cv2
# 引入人像识别训练库“haarcascade_frontalface_default.xml
face_patterns = cv2.CascadeClassifier(r'D...haarcascade_frontalface_alt.xml')
# 读取图片
image = cv2.imread('C:/Users/x230/Desktop/DSCF9093.JPG')
# 获取识别到的人脸...faces = face_patterns.detectMultiScale(image, scaleFactor=1.1, minNeighbors=4, minSize=(40, 40))
# 将识别到的人脸框出来...for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
# 生成一张新的图片保存识别结果