please help in my code cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1698: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'

asked 2018-09-30 07:22:32 -0500

updated 2019-02-12 14:54:58 -0500

LBerger gravatar image

my code is

import cv2

faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

cap=cv2.VideoCapture(0)

while True: ret, frame = cap.read()

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(gray, scaleFactor = 1.05, minNeighbors = 5)

for (x,y,w,h) in faces:
    cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),2)

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

cap.release() cv2.destroyAllWindows()

edit retag flag offensive close merge delete

Comments

it means, your cascade xml file was not loaded. check the path, again.

berak gravatar imageberak ( 2018-10-01 01:41:06 -0500 )edit