OpenCVdetectMultiScale错误

时间:2018-07-09 12:21:17

标签: python opencv cascade-classifier

我想从相机中获取帧并检测面部,我使用了以下代码:

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

cap=cv2.VideoCapture(0)
while 1:
    ret, img = cap.read()
    gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray,1.3,5)
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)

但是方法 detectMultiScale 会引发如下错误:

OpenCV(3.4.1) Error: Assertion failed (!empty()) in cv::CascadeClassifier::detectMultiScale, file C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp, line 1698
Traceback (most recent call last):
  File "C:/~blabla~/untitled2/aabaci.py", line 12, in <module>
    faces = face_cascade.detectMultiScale(gray,1.3,5)
cv2.error: OpenCV(3.4.1) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1698: error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale

您对这个问题有任何想法吗?

0 个答案:

没有答案