import cv2
# 定义人脸检测的分类器
face_cascade = cv2.CascadeClassifier(r'G:\\data\\haircare_eye_tree_eyeglasses.xml')
# 读取图片
img = cv2.imread("G:\\One face.jpg")
# 灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 检测人脸
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
print("发现{0}个人脸!".format(len(faces)))
for (x, y, w, h) in faces:
# cv2.rectangle(img,(x,y),(x+w,y+w),(0,255,0),2)
cv2.circle(img, (int((x + x + w) / 2), int((y + y + h) / 2)), int(w / 2), (0, 255, 0), 2)
cv2.imshow("Find Faces!", img)
cv2.imwrite("G:\\123.jpg", img)
cv2.waitKey(0)
报错: faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: OpenCV(4.5.4-dev) D:\a\opencv-python\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'