Print Page | Close Window

Face Detection and Recognition in dot net



Printed From: ProjectsQA
Category: Projects Forum
Forum Name: Computer/IT Projects
Forum Discription: Projects in any Programming language, Software, Networking, Final Year Projects, Mini Projects etc.
URL: http://projectsqa.com/forum_posts.asp?TID=515
Printed Date: 18-Nov-2017 at 4:09pm


Topic: Face Detection and Recognition in dot net
Posted By: sris269
Subject: Face Detection and Recognition in dot net
Date Posted: 26-Mar-2012 at 7:34pm
Can you please help me i'm stuck in my project. I'm doing Secure Online Examination Using Cryptography. In that when a student registers for an exam through online with his details even a snap of him/her must be taken and stored into sql server and then while the student logs in a picture must be taken and it shoul be compared with the earlier picture for authentication. Please help me out soon. I'm using VS2010 asp.net. SQL 2008



Replies:
Posted By: Roopa
Date Posted: 29-Mar-2012 at 5:33pm
You might have to do an image comparison in asp.net I suppose


Posted By: Krishna_Sridhar
Date Posted: 29-Mar-2012 at 5:38pm
Hey sris, this might help you out....

Comparing Two Images In Asp.Net

Introduction:
               This article explain how you can compare two images are same or not. You can compare the images from database also. DataBases not support the binary data comparision.
               For comparing two images Iím taking both of images from outside but you can replace that with database also. Itís take lots of conversion process like byte array to image and image to bitmap. In this article Iím comparing each pixel of bitmap.
               Image comparison is not possible in any Database because the binary data may not be same. You can try it with Data length also but it will not give exact result.


Using Code:
               Firstly we have convert our uploaded images into byte array for converting this byte array into images again and then this byte array are again converted into bitmap for comparison.
    byte[] _barray1;
    byte[] _barray2;
      Next we have to read the bytes of uploaded images into our byte arrays like bellow.Here only you can go for database field also means here we can read the database binary data into our byte array. Here instead of reading bytes from Upload control you can read it from database.
//Reading Bytes From Uploaded Images
           
            if (FileUpload1.HasFile && FileUpload2.HasFile)
            {
               using(BinaryReader reader1=new BinaryReader(FileUpload1.PostedFile.InputStream))
               {
                   using (BinaryReader reader2=new BinaryReader(FileUpload2.PostedFile.InputStream))
                   {
                      _barray1 = reader1.ReadBytes(FileUpload1.PostedFile.ContentLength);
                      _barray2 = reader2.ReadBytes(FileUpload2.PostedFile.ContentLength);
                   }
               }
            }
      Passing this two byte array to our compare method is not possible for that we have to convert this byte array to images and then this images to Bitmap and pass this two bitmap to our compare method and showing results.
//Converting Byte Array To Image And Then Into Bitmap
            ImageConverter ic = new ImageConverter();
            Image img = (Image)ic.ConvertFrom(_barray1);
            Bitmap bmp1 = new Bitmap(img);
            Image img1 = (Image)ic.ConvertFrom(_barray2);
            Bitmap bmp2 = new Bitmap(img1);
            //Calling Compare Function
            if (Class1.Compare(bmp1,bmp2)==Class1.CompareResult.ciCompareOk)
            {
               Label1.Visible = true;
               Label1.Text = "Images Are Same";
            }
            else if (Class1.Compare(bmp1,bmp2)==Class1.CompareResult.ciPixelMismatch)
            {
               Label1.Visible = true;
               Label1.Text = "Pixel not Matching";
            }
            else if (Class1.Compare(bmp1,bmp2)==Class1.CompareResult.ciSizeMismatch)
            {
               Label1.Visible = true;
               Label1.Text = "Size Is Not Same";
            }


The Compare Method:
      This method will perform the actuall task of image comparision. This method compare each and every pixel using SHA256Managed.And stored the result in enum.
public enum CompareResult
    {
        ciCompareOk,
        ciPixelMismatch,
        ciSizeMismatch
    };

    public static CompareResult Compare(Bitmap bmp1, Bitmap bmp2)
    {
        CompareResult cr = CompareResult.ciCompareOk;

        //Test to see if we have the same size of image
        if (bmp1.Size != bmp2.Size)
        {
            cr = CompareResult.ciSizeMismatch;
        }
        else
        {
            //Convert each image to a byte array
            System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
            byte[] btImage1 = new byte[1];
            btImage1 = (byte[])ic.ConvertTo(bmp1, btImage1.GetType());
            byte[] btImage2 = new byte[1];
            btImage2 = (byte[])ic.ConvertTo(bmp2, btImage2.GetType());

            //Compute a hash for each image
            SHA256Managed shaM = new SHA256Managed();
            byte[] hash1 = shaM.ComputeHash(btImage1);
            byte[] hash2 = shaM.ComputeHash(btImage2);

            //Compare the hash values
            for (int i = 0; i < hash1.Length && i < hash2.Length && cr == CompareResult.ciCompareOk; i++)
            {
               if (hash1 != hash2)
                    cr = CompareResult.ciPixelMismatch;
            }
            shaM.Clear();
        }

        return cr;
    }


Conclusion:
               This compare the two images either from uploaded images or database binary data.


Posted By: TnagarSharath
Date Posted: 29-Mar-2012 at 5:44pm
Its better you save the image in binary format as the image datatype will be removed from SQL Server.


Posted By: sris269
Date Posted: 29-Mar-2012 at 6:36pm
Thank you :)



Print Page | Close Window