def process_image(img = list()):
"""
Extracts faces from the image using haar cascade, resizes and applies filters.
:param img: image matrix. Must be grayscale
::returns faces:: list contatining the cropped face images
"""
face_cascade = cv2.CascadeClassifier('/Users/mehul/opencv-3.0.0/build/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml')
faces_location = face_cascade.detectMultiScale(img, 1.3, 5)
faces = []
for (x,y,w,h) in faces_location:
img = img[y:(y+h), x:(x+w)]
try:
img = cv2.resize(img, (256, 256))
except:
exit(1)
img = cv2.bilateralFilter(img,15,10,10)
img = cv2.fastNlMeansDenoising(img,None,4,7,21)
faces.append(img)
return faces
评论列表
文章目录