# coding:utf-8
import os
import cv2
from PIL import Image
#选择分类器模型(下载地址:https://github.com/opencv/opencv/tree/master/data/haarcascades)
classifier = cv2.CascadeClassifier(r'./opencv-master/data/haarcascades/haarcascade_frontalface_default.xml')
#加载文件中的所有图片
def load_images_from_folder(folder):
imgs = []
for filename in os.listdir(folder):
img = cv2.imread(os.path.join(folder,filename))
if img is not None:
imgs.append(img)
return imgs
#将所有图片进行面部截图
def get_images_faces(imglist):
imgs = []
for i in range(len(imglist)):
faces = classifier.detectMultiScale(imglist[i],minNeighbors=5,minSize=(30, 30))
for (x, y, w, h) in faces:
imgs.append(imglist[i][y:y+h,x:x+w])
return imgs
#重置图片大小
def images_resize(imgl