Pixelating an Image with Aforge.NET

I have been working on an interesting kiosk solution recently which has had a requirement to capture CCTV footage for when the kiosk is not in use.  The solution is going to be used in Germany, and bizarrely the data protection laws in Germany state that when capturing CCTV footage citizens are not allowed to be clearly identifiable.

The client that we are building the solution for wants this functionality to see how people observe and interact with the physical hardware and the environment that the solution is installed in.

To achieve this requirement I used Aforge.Net’s C# Framework library at http://www.aforgenet.com to quickly and easily apply a filter over a captured image.  (The issue of using motion detection was handled separately).

The following sample shows just how easy it is to apply a filter over an image with Aforge.Net Framework:


//Define the Filter
var pixFilter = new Pixellate(8);

//Get the Image you wish to apply the filter to
var bmp = videoSourcePlayer.GetCurrentVideoFrame();

//Apply the filter to the image
bmp = pixFilter.Apply(bmp);

The following shows the output of a sample application I wrote to demonstrate this:

pixelate_sample

Here is the full example code for the above example:


using System;
using System.Drawing;
using System.Windows.Forms;
using AForge.Imaging.Filters;

namespace Pixelate_Filter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BtnFilter_Click(object sender, EventArgs e)
        {
            //Define the Filter
            var pixFilter = new Pixellate(8);

            //Get the Image you wish to apply the filter to
            var bmp = ImgBefore.Image;

            //Apply the filter to the image
            bmp = pixFilter.Apply((Bitmap) bmp);

            ImgAfter.Image = bmp;
        }
    }
}