I got an error message when I execute the python code mentioned below:
Traceback (most recent call last):
File "C:\Users\smart-26\Desktop\예제\face.py", line 28, in
faces = face_cascade.detectMultiScale(grayframe, 1.1, 3, 0, (30, 30))
cv2.error: D:\Build\OpenCV\opencv->
3.2.0\modules\objdetect\src\cascadedetect.cpp:1681: error: (-215) !empty() in
function cv::CascadeClassifier::detectMultiScale
I don't understand this message:
error: (-215) !empty() in function cv::CascadeClassifier::detectMultiScale
Here is my code so far:
import cv2
CAM_ID = (0)
cap = cv2.VideoCapture(CAM_ID)
if cap.isOpened() == False:
print ('Can\'t open the CAM(%d)' % (CAM_ID))
exit()
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
while(True):
ret, frame = cap.read()
grayframe = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
grayframe = cv2.equalizeHist(grayframe)
faces = face_cascade.detectMultiScale(grayframe, 1.1, 3, 0, (30, 30))
for (x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3, 4, 0)
cv2.imshow('Face',frame)
if cv2.waitKey(10) >= 0:
break;
cv2.namedWindow('Face')
cap.release()
cv2.destroyWindow('Face')
empty
method of theCascadeClassifierImpl
. That hints at the classifier XML not loading correctly. | Your code lacks any kind of error checking. Both loading of the XML as well as reading frames can fail. You need to handle that. – Dan Mašek