File Exchange Pick of the Week

Our best user submissions

Detecting Faces in Images

Brett's Pick this week is more of a challenge than a "Pick".

If I were to search the MATLAB Central File Exchange for "face detection" (with the quotation marks) I would get a dazzling--and somewhat overwhelming--array of 44 hits. Trying to detect faces (or anything else*) in images seems to me a reasonable thing to want to do, and in my mind typifies the challenges that the Computer Vision System Toolbox was made to address. In fact, I shudder to think of what classical "image processing" code designed to detect faces might look like.

But how do we navigate the 44 files on the File Exchange that facilitate that detection process? Where do we start? I can sort the results by number of downloads, by rating, by relevancy, ....

Some of those downloads seem to have great potential. But where does one start?

For this post, I'm going to go "out-of-model" and focus not on a submitted File Exchange file, but on core capabilities of the Computer Vision System Toolbox. This Toolbox has a "Cascade Object Detector" that facilitates out-of-the-box detection of faces, eyes, noses, mouths, and upper bodies. In fact, there are two in-product face detectors, and "FrontalFaceCART" (frontal face detection using "Classification And Regression Tree" analysis) is the default tool behavior.

Using the detectors in the Computer Vision System Toolbox is stunningly simple; we simply instantiate an instance of the cascade object detector and, for visualization purposes, a vision.ShapeInserter:

faceDetector = vision.CascadeObjectDetector;
shapeInserter = vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[0 255 255]);

We then read input image:

I = imread('visionteam.jpg');

Then we simply "step" the instantiated objects on the image of interest. The CascadeObjectDetector returns the bounding boxes of the detected objects, and the ShapeInserter delimits them in the image:

bbox = step(faceDetector, I);
% Draw boxes around detected faces and display results
I_faces = step(shapeInserter, I, int32(bbox));
imshow(I_faces), title('Detected faces');

Detecting faces using MathWorks' functionality is trivially easy. It requires MATLAB, the Image Processing Toolbox, and the Computer Vision System Toolbox, and a few readily reproducible lines of code.

Swag to the first person who shows me how to detect faces in "visionteam.jpg" with a File Exchange submission!

By the way, you can readily train MATLAB to find objects that are not in the "pre-trained" list above. For that, you might find these tools useful:

Comments welcome!

Published with MATLAB® R2014a

  • print
  • send email


댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.