Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

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

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

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

cv2.CascadeClassifier('data/haarcascade/haarcascade_frontalface_alt2.xml') cap = cv2.VideoCapture(0)

cv2.VideoCapture(0) while True:

True: ret, frame = cap.read()

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

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

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 
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