This project is read-only.
Project Description
A library for performing face detection on windows phone 7. This library uses the same algorithms and detection models as OpenCV and is written in C# and built for the Windows Phone. Also includes a camera user control that supports automated taking of photos and showing camera preview.

Note: this library can actually detect objects of any type, provided you give it the correct model files, since all it does is read existing, learned models. You can find model files on OpenCV's website.

Bonus: User Control for interfacing with camera
I just wanted to let folks know that the latest release also includes a nice user control (under WP7Controls) that allows you to easily interface with the windows phone 7 camera. You can view the camera preview and easily save images to the camera roll using this control.

How to Use the Library
This library is built for Windows Phone 7 and is intended to be used only for Windows Phone 7.

To use the library:
  1. Download the FaceDetectionWinPhone solution from the Downloads page
  2. Either add the FaceDetectionWinPhone Project to your project or build/add the FaceDetectionWinPhone dll
  3. Add a models/ folder to your project and add xml model files as found under FaceDetectionWinPhone/Sample/models or in the downloads section. I would recommend using haarcascadefrontalfacealt.xml (this is the only one tested).
  4. Make sure you have a reference to System.Xml.Linq
  5. Create a detector: FaceDetectionWinPhone.Detector detector = new FaceDetectionWinPhone.Detector(XDocument.Load(MODEL_FILE));
  6. You can use the detector by passing in either a string (path to image file), a WriteableBitmap, or an int array, width and height. Here's how to detect faces by passing in an int array:

List<FaceDetectionWinPhone.Rectangle> faces = mdetector.getFaces(pixelDataInt, mcameraWidth / mdownsampleFactor, mcameraHeight / m_downsampleFactor, 2f, 1.25f, 0.1f, 1, false);

Sample Code
I've included a sample project which overlays the camera stream with rectangles represented recognized faces. The source code that's under version control is a solution that contains the library and the sample project.

Alternatively, if you don't want to use version control, you can go to the Downloads page and download the entire sample as well.

Running in Emulator
To get the sample to run in the emulator, you need to remove the following line of code:
mcamera.Resolution = mcamera.AvailableResolutions.First();

This library is largely based off of the Java-based library at Thank you very much for the developers of this library for making their code open source!

Special Request
If you built something cool using the toolkit, could you please post a link to what you made in the Discussions board? I would love to see what people have made with this.

More Info/Contact
You can read more about the project at, and contact me by posting a comment on that post.

Last edited Apr 18, 2012 at 9:08 PM by julenka, version 13