|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def detect(filename):
img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 检测正脸
front_face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
faces0 = front_face_cascade.detectMultiScale(gray, 1.022, 5)
print("共检测到%d张人的正脸" %len(faces0))
# 检测侧脸
profile_face_cascade = cv2.CascadeClassifier('haarcascade_prodileface.xml')
faces1 = profile_face_cascade.detectMultiScale(gray, 1.2, 6)
print("共检测到%d张人的侧脸" %len(faces1))
if len(faces0) > 0:
for faceRect in faces0:
x, y, w, h = faceRect
# 将当前人脸保存为图片
img_name = '%s.jpg' %(filename)
image = img[y-10:y+h+10, x-10:x+w+10]
cv2.imwrite(img_name, image)
if len(faces1) > 0:
for faceRect in faces1:
x, y, w, h = faceRect
# 将当前人脸保存为图片
img_name = '%s.jpg' %(filename)
image = img[y-10:y+h+10, x-10:x+w+10]
cv2.imwrite(img_name, image)
img = detect("Aaron_Peirsol_0001.jpg")
我想问下为啥我没显示保存的片啊 |
|