image = cv2.imread(imagepath)
result_image = image.copy()
face_cascade_name = './haarcascade_frontalface_alt.xml'
face_cascade = cv2.CascadeClassifier()
face_cascade.load(face_cascade_name)
grayimg = cv2.cvtColor(image, cv2.cv.CV_BGR2GRAY)
grayimg = cv2.equalizeHist(grayimg)
faces = face_cascade.detectMultiScale(grayimg, 1.1, 2, 0 | cv2.cv.
    CV_HAAR_SCALE_IMAGE, (30, 30))
print('Faces detected')
if len(faces) != 0:
    for f in faces:
        x, y, w, h = [v for v in f]
cv2.rectangle(image, (x, y), (x + w, y + h), (255, 255, 0), 5)
sub_face = image[y:y + h, x:x + w]
sub_face = cv2.GaussianBlur(sub_face, (23, 23), 30)
result_image[y:y + sub_face.shape[0], x:x + sub_face.shape[1]] = sub_face
face_file_name = './face_' + str(y) + '.jpg'
cv2.imwrite(face_file_name, sub_face)
cv2.imwrite('./result.png', result_image)
How to use opencv (python) to blur faces?