目录
一、人脸识别
1、初级版
默认使用HOG算法
import os
os.chdir('C:/Users/Administrator/AppData/Local/Programs/Python/Python37/Lib/site-packages')
import cv2
import matplotlib.pyplot as plt
def detect(filename):
face_cascade=cv2.CascadeClassifier('C:/Users/Administrator/AppData/Local/Programs/Python/Python37/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml')
img=cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=face_cascade.detectMultiScale(gray,1.1,5)
for (x,y,w,h) in faces:
img=cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),4)
plt.imshow(img)
plt.axis('off')
plt.show()
detect('disanzhang.jpg')
运行结果: