Ask Your Question
0

how to solve cv2.error(-215:Assertion failed)

asked 2019-04-04 19:39:48 -0500

updated 2019-04-04 20:57:49 -0500

supra56 gravatar image

when i run the programme, it reveals cv2.error:
OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\objdetect\cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScales

my code is there:

import cv2

import numpy as np

face_cascade = cv2.CascadeClassifier('data/haarcascade/haarcascade_frontalface_alt2.xml')

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
    for (x, y, w, h) in faces:
        print(x,y,w,h)
        roi_gray = gray[y:y + h, x:x + w]  # (ycord_start, ycord_end)
        roi_color = frame[y:y + h, x:x + w]
        img_item = 'my-image.png'
        cv2.imwrite(img_item,roi_gray)
        cv2.imshow('frame',frame)
        color = (0,0,255)
        stroke = 2
        width = x + w
        height = y + h
        cv2.rectangle(frame,(x,y), (width, height, color, stroke))
if cv2.waitKey(20) & 0xFF == ord('q'):
    break

pls be specific.
Many Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-04-04 21:26:40 -0500

supra56 gravatar image

You forgot to add plural not singular. haarcascades

face_cascade = cv2.CascadeClassifier('data/haarcascades/haarcascade_frontalface_alt2.xml')
edit flag offensive delete link more

Comments

thanks, the problem has been solved because of the path error, thank you anyway for reminding me.

ouyoood gravatar imageouyoood ( 2019-04-05 06:42:40 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-04-04 19:39:48 -0500

Seen: 55 times

Last updated: Apr 04