级联分类器给出错误:
cv2.error: /Users/jenkins/miniconda/1/x64/conda-bld/work/opencv-3.1.0/modules/objdetect/src/cascadedetect.cpp:1639:
error: (-215) !empty() in function detectMultiScale()
代码:
imggray=cv2.imread('frame1.jpg',cv2.IMREAD_GRAYSCALE)
imgnew=cv2.equalizeHist(imggray)
print imgnew
# cascade_fn = args.get('--cascade',"../../data/haarcascades/haarcascade_frontalface_default.xml")
face_cascade = cv.CascadeClassifier('./../data/haarcascades/haarcascade_frontalface_default.xml')
print face_cascade
faces = face_cascade.HaarDetectObjects(imgnew)
for (x,y,w,h) in faces:
cv2.rectangle(imgnew,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = imggray[y:y+h, x:x+w]
roi_color = imgnew[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
# cv2.imwrite('Frame2.jpg',imgnew)
按照此博客文章中的步骤查找opencv中可用的功能
https://www.pyimagesearch.com/2015/08/31/how-to-find-functions-by-name-in-opencv/