【发布时间】:2013-08-06 13:24:29
【问题描述】:
我想知道是否有一种方法可以对 haarcascade 人脸分类器自动识别的人脸进行模糊处理。
使用下面的代码,我可以检测人脸、裁剪这张人脸周围的图像或在其上绘制一个矩形。
image = cv2.imread(imagepath)
# Specify the trained cascade classifier
face_cascade_name = "./haarcascade_frontalface_alt.xml"
# Create a cascade classifier
face_cascade = cv2.CascadeClassifier()
# Load the specified classifier
face_cascade.load(face_cascade_name)
#Preprocess the image
grayimg = cv2.cvtColor(image, cv2.cv.CV_BGR2GRAY)
grayimg = cv2.equalizeHist(grayimg)
#Run the classifiers
faces = face_cascade.detectMultiScale(grayimg, 1.1, 2, 0|cv2.cv.CV_HAAR_SCALE_IMAGE, (30, 30))
print "Faces detected"
if len(faces) != 0: # If there are faces in the images
for f in faces: # For each face in the image
# Get the origin co-ordinates and the length and width till where the face extends
x, y, w, h = [ v for v in f ]
# Draw rectangles around all the faces
cv2.rectangle(image, (x,y), (x+w,y+h), (255,255,255))
sub_face = image[y:y+h, x:x+w]
for i in xrange(1,31,2):
cv2.blur(sub_face, (i,i))
face_file_name = "./face_" + str(y) + ".jpg"
cv2.imwrite(face_file_name, sub_face)
但我想模糊人脸,使他们无法被识别。
你知道怎么做吗?
感谢您的帮助
阿尔诺
【问题讨论】:
-
使用these 函数之一并传入包含人脸的图像子区域
-
嗨,Hammer,我想过,但我不知道如何仅模糊检测到面部的图像部分。谢谢。
-
我终于成功地做我想做的事了。为此,请按照您的建议应用 gaussianblur:
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 -
对不起,我应该更明确一点。很高兴你明白了:)
-
@ArnaudGeotribu,请将您的解决方案放入答案并接受它,以便搜索相同问题的人可以使用它。
标签: python opencv computer-vision face-recognition haar-classifier