执行下面提到的 python 代码时收到错误消息:
回溯(最近一次通话最后):
文件“C:\Users\smart-26\Desktop\예제\face.py”,第 28 行,在
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: 错误: (-215) !empty() in
函数 cv::CascadeClassifier::detectMultiScale
我不明白这个消息:
错误:(-215) 函数 cv::CascadeClassifier::detectMultiScale 中的 !empty()
到目前为止,这是我的代码:
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')