ytrewq
ytrewq

Reputation: 3930

opencv face detection parameter setup

I'm running opencv's face detection using haar cascade on the frames from videos.

Each frame is 256x256, and most of them have faces whose sizes vary.

I've noticed that current setup fails to detect many faces, and it detects about one face on average for every 20~50 frames.

cscPath='haarcascade_frontalface_default.xml'
faceCascade=cv2.CascadeClassifier(cscPath)
image=cv2.imread(file)
faces=faceCascade.detectMultiScale(
    image,
    scaleFactor=1.2,
    minNeighbors=5,
    minSize=(10,10),
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)

What would be the optimal setting for parameters in this situation?

Should I just trial-and-error trying different parameter setups?

Upvotes: 3

Views: 989

Answers (1)

Aphire
Aphire

Reputation: 1652

The lower the scale factor, the more precise of a search your classifier will take, however this will also take longer. It determines how much it resizes the image by, every time it runs a pass on the image looking for faces. If you find your faces are varying in scale alot, it may be worth lowering this value to 1.1 (the lowest) and see if that improves your results.

Also min neighbours may be tripping you up, lowering this from 5 to say, 3 might improve results, however you may also get some false positives (picking up a wall, or funny shaped object), this really is something you can tweak until you get the results you like.

I doubt any of your faces will be < 10 pixels across, so your minSize variable is probably alright.

With flags, it may be easier to use "flags = 0" as I think they are becoming deprecated (however I may be wrong)

Also i'm assuming your frames are grayscale? as the cascade is designed to work with gray images and I noticed you are not doing any BGR2GRAY functions before passing the image to the classifier, you can also do this by changing your imread line to:

image = cv2.imread(file, 0)

Also it may be worth even using a different classifier .XML altogether, there are a few face classifiers available with opencv eg.:

haarcascade_frontalface_alt

haarcascade_frontalface_alt_tree

haarcascade_frontalface_alt2

Hope this helps.

Upvotes: 3

Related Questions