Simple Face Detection for Windows Phone (4/5)

Simple Face Detection for Windows Phone (4/5)

Simple Face Detection for Windows Phone (4/5)

To explain simple face detection, I wrote 5 posts with each another technique in the face detection process. When you combine all 5 steps, you will be able to detect faces in pictures or video streams.

The steps described in these posts are:

Now the blobs are marked, it’s time to get some information about are blobs. For each blob we want to know at what x and y coordinates they begin and what the width and height is. For this we have a collection with custom objects, it’s not really fast but I didn’t really had the time to optimize this yet. If you have a better solution, please post it as a reply!

public class BoundingBox
{
    public int X, Y, Width, Height;
    public uint Color;
}

public static Collection<BoundingBox> GetBoundingBoxes(int[] pixels, int width, int height)
{
    Collection<BoundingBox> output = new Collection<BoundingBox>();
	for (int x = 0; x < width; x++)
		for (int y = 0; y < height; y++)
			if ((uint)pixels[y * width + x] != 0xFF000000 && pixels[y * width + x] != 0)
			{
				bool match = false;
				foreach (BoundingBox box in output)
				{
					if (box.Color == (uint)pixels[y * width + x])
					{
						match = true;
						if (box.X > x)
							box.X = x;
						if (x - box.X > box.Width)
							box.Width = x - box.X;
						if (box.Y > y)
							box.Y = y;

						if (y - box.Y > box.Height)
							box.Height = y - box.Y;

					}
				}
				if (!match)
					output.Add(new BoundingBox() { X = x, Y = y, Width = 1, Height = 1, Color = (uint)pixels[y * width + x] });
			}
	return output;
}

Download Download the whole demo project

4 thoughts on “Simple Face Detection for Windows Phone (4/5)”

Leave a Reply

Your email address will not be published. Required fields are marked *