我的detectMultiScale报错,不知道是哪里的问题
这是代码
import cv2 as cv
def face_detect_demo(img):
#将图片灰度
gray=cv.cvtColor(img,cv.COLOR_BGR2GRAY)
#加载特征数据
face_detector = cv.CascadeClassifier('D:\\下载的软件\\OpenCV\\opencv-4.6.0-vc14_vc15\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml')
faces = face_detector.detectMultiScale(gray)
for x,y,w,h in faces:
print(x,y,w,h)
cv.rectangle(img,(x,y),(x+w,y+h),color=(0,0,255),thickness=2)
cv.circle(img,center=(x+w//2,y+h//2),radius=w//2,color=(0,255,0),thickness=2)
#显示图片
cv.imshow('result',img)
#加载图片
img=cv.imread('face.jpg')
#调用人脸检测方法
face_detect_demo(img)
cv.waitKey(0)
cv.destroyAllWindows()
这个是显示的错误
OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
File "D:\新建文件夹\opencv人脸识别\6多个人脸识别.py", line 7, in face_detect_demo
faces = face_detector.detectMultiScale(gray)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\新建文件夹\opencv人脸识别\6多个人脸识别.py", line 18, in <module>
face_detect_demo(img)
cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'