我正在尝试为opencv中的基本面部识别程序编写代码。这是我第一次尝试,但不断出现此错误,我不知道如何解决。它说 OpenCV(4.0.0)C:\ projects \ opencv-python \ opencv \ modules \ objdetect \ src \ cascadedetect.cpp:1658:错误:(-215:断言失败)函数'cv :: CascadeClassifier中的!empty(): :detectMultiScale'
face_c = cv2.CascadeClassifier(r'C:\Users\Srujan Deshpande\Desktop\IO\CV\harrcascade_frontalface_default.xml')
eyes_c = cv2.CascadeClassifier(r'C:\Users\Srujan Deshpande\Desktop\IO\CV\harrcascade_eye.xml')
def detect(gray,frame):
face = face_c.detectMultiScale(gray,1.3,5)
for (x,y,w,h) in face:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h,x:x+w]
roi_color = frame[y:y+h,x:x+w]
eyes = eyes_c.detectMultiScale(roi_gray,1.1,25)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
return frame
video_capture = cv2.VideoCapture(0)
while(1):
_,frame = video_capture.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
canvas = detect(gray,frame)
cv2.imshow('Video',canvas)
if cv2.waitKey(1) & 0xFF == ord('q'): break
video_capture.release()
cv2.destroyAllWindows()
我已经放置了.xml文件的整个文件路径,但似乎没有什么区别。