OpenCV: ошибка при распознавании в реальном времени (Anaconda,Spyder4)

вот ошибка

error: OpenCV(4.0.1) C:\ci\opencv-suite_1573470242804\work\modules\objdetect\src\cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'
error: OpenCV(4.0.1) C:\ci\opencv-suite_1573470242804\work\modules\objdetect\src\cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'


[ WARN:0] terminating async callback
[ WARN:1] videoio(MSMF): OnReadSample() is called with error status: -1072873821
[ WARN:1] videoio(MSMF): async ReadSample() call is failed with error status: -1072873821
[ WARN:0] terminating async callback
[ WARN:2] videoio(MSMF): OnReadSample() is called with error status: -1072873821
[ WARN:2] videoio(MSMF): async ReadSample() call is failed with error status: -1072873821
[ WARN:0] terminating async callback
[ WARN:2] videoio(MSMF): OnReadSample() is called with error status: -1072873821
[ WARN:2] videoio(MSMF): async ReadSample() call is failed with error status: -1072873821
[ WARN:0] terminating async callback

вот код:

import cv2

cascPath = "/usr/local/lib/python3.7/site-packages/cv2/data/haarcascade_frontalface_default.xml"
eyePath = "/usr/local/lib/python3.7/site-packages/cv2/data/haarcascade_eye.xml"
smilePath = "/usr/local/lib/python3.7/site-packages/cv2/data/haarcascade_smile.xml"

faceCascade = cv2.CascadeClassifier(cascPath)
eyeCascade = cv2.CascadeClassifier(eyePath)
smileCascade = cv2.CascadeClassifier(smilePath)

font = cv2.FONT_HERSHEY_SIMPLEX
video_capture = cv2.VideoCapture(0)

while True:

    ret, frame = video_capture.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(200,200),
        flags = cv2.CASCADE_SCALE_IMAGE
    )



                                         


    # рисование прямоугольника 
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 3)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = frame[y:y+h, x:x+w]
        cv2.putText(frame,'Face',(x, y), font, 2,(255,0,0),5)

    smile = smileCascade.detectMultiScale(
        roi_gray,
        scaleFactor= 1.16,
        minNeighbors=35,
        minSize=(25, 25),
        flags=cv2.CASCADE_SCALE_IMAGE
    )

    for (sx, sy, sw, sh) in smile:
        cv2.rectangle(roi_color, (sh, sy), (sx+sw, sy+sh), (255, 0, 0), 2)
        cv2.putText(frame,'Smile',(x + sx,y + sy), 1, 1, (0, 255, 0), 1)

    eyes = eyeCascade.detectMultiScale(roi_gray)
    for (ex,ey,ew,eh) in eyes:
        cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
        cv2.putText(frame,'Eye',(x + ex,y + ey), 1, 1, (0, 255, 0), 1)

    cv2.putText(frame,'Number of Faces : ' + str(len(faces)),(40, 40), font, 1,(255,0,0),2)      

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
      break


video_capture.release()
cv2.destroyAllWindows()

Ответы (0 шт):