通过opencv三方库进行图片人脸识别
face_zones中的参数可以自行调试,这三个data都可以用于人脸识别
- haarcascade_frontalface_default.xml
- haarcascade_frontalface_alt.xml
- haarcascade_frontalface_alt2.xml
import numpy as np
import cv2
img = cv2.imread('./2ren.jpg')
img.shape
#级联分类器 (多个小分类器共同工作,级联)
#haar:特征数据
face_detector = cv2.CascadeClassifier('./haarcascade_frontalface_default.xml')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
face_zones = face_detector.detectMultiScale(gray,scaleFactor=1.05,
minNeighbors=3,
minSize =(60,60),
maxSize =(110,110))
print(face_zones)
for x,y,w,h in face_zones:
# cv2.rectangle(img,pt1=(x,y),pt2=(x+w,y+h),color= [0,0,255],thickness=2,)
cv2.circle(img,center=(x+w//2,y+h//2),radius=w//2,color= [0,0,255],thickness=2,)
cv2.imshow('face',img)
cv2.waitKey(0)
cv2.destroyAllWindows()