按书本敲代码遇到的问题
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
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
cv2.imwrite(img_name, image)
img = detect("Aaron_Peirsol_0001.jpg")
我想问下为啥我没显示保存的片啊 有报错吗? 11
页:
[1]