A day with .Net

My day to day experince in .net

Archive for July, 2011

Face Capture and Face Detection in c# using webcam PART 1

Posted by vivekcek on July 14, 2011

Hi Friends your friend vivek is here.The past month was very tough lots of emotional issues.Each days with .NET giving me new knowledge.
This time i was planning to develop an image based authentication system.My plan was to implement this system with in one day.

    Vivek’s Targets

1. Capture your face from your web cam.
2. Store that image and your information to a database.
3. Next time when you came to system,the system will check your face against the image stored in database.

In this article i just wanna implement the first step,that is how to capture image using a web cam.A small image of the application is given below.Hi hi i haven’t put my face on the application
because some of my friends always complain that i am writing blog for impressing girls.I don’t want that impression went to waste box.So put a match box in my hand.


    OpenCV is a tool developed by Intel in C++.OpenCV can do almost all image processing operations.Initially i planned to use OpenCV.Then i changed my mind because OpenCV
    is C++ oriented.After some Google search i found EMGU CV wrapper for .NET and c#.

    1. Capture your face from your web cam.

a. Download EmguCv and install it.
b. The installation folders bin folder contain all DLL’s for our development(C:\Emgu\emgucv-windows-x86\bin).
c. Create a windows form project and add reference to Emgu.CV.dll,Emgu.CV.UI.dll,Emgu.Util.dll
d. Copy all OpenCV dll’s from Emgu’s bin folder(C:\Emgu\emgucv-windows-x86\bin) to your applications Bin folder
e. Add Emgu controls to your visual studio toolbox from Emgu.CV.dll
f. Put an Emgu ImageBox in your form,in which we show captured image.
g. Put 2 buttons one to start capture image and next one to store that image to a database.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.Util;
namespace WebCamCapture
    public partial class Form1 : Form
        private Capture _VivekCapTure;
        private bool _captureInProgress;

        public Form1()

        private void button1_Click(object sender, EventArgs e)
            #region if capture is not created, create it now
            if (_VivekCapTure == null)
                    _VivekCapTure = new Capture();
                catch (NullReferenceException excpt)
            if (_VivekCapTure != null)
                if (_captureInProgress)
                {  //stop the capture
                    //captureButton.Text = "Start Capture";
                    Application.Idle -= ProcessFrame;
                    //start the capture
                    //captureButton.Text = "Stop";
                    Application.Idle += ProcessFrame;

                _captureInProgress = !_captureInProgress;
        private void ProcessFrame(object sender, EventArgs arg)
            Image<Bgr, Byte> frame = _VivekCapTure.QueryFrame();
            captureImageBox.Image = frame;

Posted in c#.net | 3 Comments »