Ask Your Question
2

OpenCV 3 - Python's detectMultiScale3 fails in clipObjects

asked 2015-06-29 10:33:14 -0600

jackwayneright gravatar image

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()
edit retag flag offensive close merge delete

Comments

1

problem is reproducable in c++ :

CascadeClassifier cascade(cascadeName);
Mat img = imread("im/lena.png");
vector<Rect> rects;
vector<int> rejects;
vector<double> levels;
cascade.detectMultiScale(img,rects,rejects,levels);

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:

 face_cascade.detectMultiScale3(gray, 1.3, 5, outputRejectLevels=True)
berak gravatar imageberak ( 2015-06-29 11:08:31 -0600 )edit

btw, i think, you should make an official issue here

berak gravatar imageberak ( 2015-06-29 11:15:28 -0600 )edit

@berak: That fixes the problem for me! Thanks for the help! I'll look into logging an issue some time in the near future.

jackwayneright gravatar imagejackwayneright ( 2015-06-29 15:34:01 -0600 )edit

again, the problem is not at the python level, but already at the c++ one. and yes, please let them know about it !

berak gravatar imageberak ( 2015-06-29 15:41:30 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-10-24 09:29:07 -0600

supra56 gravatar image

updated 2019-10-24 09:30:24 -0600

This will merely worked for python 3 or later and opencv 3 or later.

 faces, w, n = face_cascade.detectMultiScale3(gray, scaleFactor=1.3,
                                                     minNeighbors=5,
                                                     minSize=(100, 100),
                                                     flags=cv2.CASCADE_SCALE_IMAGE,
                                                     outputRejectLevels=True)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-06-29 10:33:14 -0600

Seen: 2,624 times

Last updated: Oct 24 '19