我想知道有没有一种方法可以模糊已经被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)

但我想模糊人们的脸,这样他们就不能被认出来。

你知道怎么做吗?

谢谢你的帮助

阿诺

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐