Ask Your Question
3

Detecting small faces in large photos using OpenCV and Python

asked 2013-08-09 11:11:25 -0500

Salvar gravatar image

updated 2013-08-12 09:19:39 -0500

Hi!

I'm currently working on a project where I need to analyze thousands of high-resolution photos, detect visible faces and blur them out. I've read quite a bit about OpenCV (and spent a day building and playing around with it), and I feel that it's the right direction to solve this problem.

Currently, I have gotten pretty far along with OpenCV, to the point where I can process a photo, pass it to the detectMultiScale() function and use one of the provided Haar cascade files to detect a good number of faces.

However, the hit rate is still pretty abysmal no matter how I play around with the function parameters, or which cascade file I use (frontalface_default vs. frontalface_alt vs. frontalface_alt_tree). I'm perfectly fine with some false positives and false negatives, but I'm nowhere near the rate I'd call acceptable.

What I think might be causing my problems is that most of the faces in my photos are quite small, usually around 20x20 pixels. From what I've read, the default face cascade files expect larger faces (but I might very well be wrong about that). I therefore wanted to explore the option of creating my own Haar cascade classifier for the faces that appear in our photos.

However, before I start walking down that road which might take days or even weeks to travel, I have some questions that hours and hours of Googling haven't really answered for me yet. I'd appreciate any input you have on this.

My questions are:

  • How small of a face can the provided Haar cascade classifiers reliably detect (to a reasonable degree)?
  • What are best practices when it comes to building a custom haar cascade classifier for a use case such as this?
    • The use case being: Small faces in large photos of an outside environment in good lighting, ranging from profile to frontal.
  • And finally: What kind of hit detection can I reasonably expect if I go through the entire process of grabbing say, 2,000 small face positives with anywhere from 1,000 to 4,000 negatives, and build a classifier from that?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
6

answered 2013-08-11 12:51:54 -0500

I can only answer the first question. I you would look at haarcascade_frontalface_alt.xml you would notice the line <size>20 20</size> which means the minimal size of face is 20X20 (if I'm not mistaken, It actually means the smallest feature size is 20X20, which in turn means that you can only detect object at size at least 20X20).

Why not just upscale the images?

In any case, when I tried V&J on small faces, I upscaled the images. I used the frontal xml and it gave nice results on frontal images, but when the the person rotated it's head, the detector stopped detecting (couldn't handle even slightly non-profile images).

If your'e also willing to consider solutions outside OpenCV, I can recommend this following post which summarizes 48 face detection API's. Some of the are packages that you can download:

http://blog.mashape.com/post/53379410412/list-of-40-face-detection-recognition-apis

Regarding your other questions - I'm really not sure, but I (and this is my opinion only) would try other existing packages before trying to train my own cascade classifier. This is just from a ROI on "invested time" point of view.

Good Luck.

edit flag offensive delete link more

Comments

I completely support his approach! There is the Viola&Jones face detection model, wich works perfectly, and by upscaling images, also works on smaller regions. However, if they really get too small, like 10x10 pixels, the change will be that your upscalings will not contain enough info anymore to have a positive detection. In that case training own classifiers will be the way to go ... but for robust detection, you need a lot of faces, in a lot of random scene conditions! Good luck!

StevenPuttemans gravatar imageStevenPuttemans ( 2013-08-12 06:43:34 -0500 )edit
1

Thanks for the answer! Most of the faces are at least 20x20, so I think this should work. I've been going through most of the APIs in the post you linked, and some look very promising. I think I'll tinker a bit with some of them before I start the weeks-long process of training my own classifier (and then maybe finding out that they don't work well). Thanks!

Salvar gravatar imageSalvar ( 2013-08-14 08:46:09 -0500 )edit

I am tackling now the same problem and I'd be very interested to know if this approached worked for you. I tried creating my own classifier using 13000 positives and 5000 negatives and the result was worse than the default opencv frontal_face classifier.

tnoel gravatar imagetnoel ( 2014-02-19 02:36:25 -0500 )edit

@tnoel It kind of all depends on your data, setup, ... please create a new topic and place as much info as possible in it. We cannot solve this problem in this topic only.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-19 03:25:57 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-08-09 11:11:25 -0500

Seen: 4,121 times

Last updated: Aug 12 '13