A day with .Net

My day to day experince in .net

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;

3 Responses to “Face Capture and Face Detection in c# using webcam PART 1”

  1. Maulik Dusara said

    nice article here.
    when will you post part-2

  2. Akash Tripathi said

    dude i wanna know the code to store image in database
    and which database to use???

  3. sing said

    i have complete using ur code but my imagebox show nothing is it need another connection code to my web camera?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s