OpenCV 3 - Python's detectMultiScale3 fails in clipObjects
Using OpenCV 3.0.0 and Python 3.4.3, I'm getting an error running detectMultiScale3
. Specifically the error is:
cascadedetect.cpp:1597: error: (-215) a->size() == n in function clipObjects
Which appears to simply be an assertion check in the C++ source for clipObjects
, though I don't know why it would be failing. I'm testing it with the code found at the "Face Detection using Haar Cascades" OpenCV tutorial, but simply changing which version of the detectMultiScale
is being used. Anyone know why I might be getting this error and how I can fix it? Thank you much.
detectMultiScale3 Documentation
Code:
import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
img = cv2.imread('face.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces, rejectLevels, levelWeights = face_cascade.detectMultiScale3(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[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.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
problem is reproducable in c++ :
can't tell exactly what the bug is, - that clipObjects expects a null pointer if the rejectLevels are absent, or that the address of empty vectors is fed into clipObjects , disregarding the outputRejectLevels flag in line 1665, or that this flag is set to false by default, - probably all of them ;)
tl:dr; - you will have to set outputRejectLevels to true, if you want to use detectMultiScale3, like:
btw, i think, you should make an official issue here
@berak: That fixes the problem for me! Thanks for the help! I'll look into logging an issue some time in the near future.
again, the problem is not at the python level, but already at the c++ one. and yes, please let them know about it !