Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detecting small faces in large photos using OpenCV and Python

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!

Detecting small faces in large photos using OpenCV and Python

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!