Monday, February 2, 2009

Face Detection in Webapplication asp.net c#

Hi,
Here is the web application to detect the face on the image .Face Detection is does by open CV (open source Computer vision).

It is a library programming unit aimed at facial Recognition, motion detection . Download open CV here http://www.brothersoft.com/opencv-20868.html and install it Here is the link for face detection in windows application .http://www.codeproject.com/KB/library/eyes.aspx?fid=990485&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=51&select=2502155.The code that Modified from window application to web application.
To execute the application
Create Images Folder in the path of your website , place sample image as test.jpg .

Here is the code for aspx page
Add the following controls : file upload , Button,Image , HiddenField

Here is the code for aspx.cs page
public partial class _Default : System.Web.UI.Page
{
private string fileName;
private Guid imageId;
private Bitmap lastPic;
private clsFaceDetectionWrapper objFaceDetector = null;
private Pen myPen = new Pen(Color.Red, 2.0f);
Graphics picGraphics;
Graphics g;
private string filePath;
protected void Page_Load(object sender, EventArgs e)
{
objFaceDetector = clsFaceDetectionWrapper.GetSingletonInstance();
detectedImage.ImageUrl = Server.MapPath("./images/output.jpg");
}

void DrawRectangle(int lx, int ly, int rx, int ry)
{
g.DrawRectangle(myPen, lx, ly, rx - lx, ry - ly);
}
void DrawCross(int x, int y)
{
}

protected void detectButton_Click(object sender, EventArgs e)
{
imageId = new Guid();
imageId = Guid.NewGuid();
if (imageUpload.HasFile)
{
fileName = imageUpload.FileName.ToString().
Substring(imageUpload.FileName.ToString().LastIndexOf("."));
}
if (fileName.ToLower() == ".jpg" || fileName == ".gif" || fileName == ".jpeg" ||fileName == ".bmp" || fileName == ".png" || fileName == ".tif")
{
if (imageUpload.FileName != "")
{
pathHiddenField.Value = Server.MapPath("./images/" + imageId + "_" + imageUpload.FileName);
imageUpload.PostedFile.SaveAs(Server.MapPath("./images/" + imageId + "_" + imageUpload.FileName));
}
}
lastPic = new Bitmap(pathHiddenField.Value);
g = Graphics.FromImage(lastPic);
// here is the path to plave the cascade folder in the specified path.If Possible place the path cascade file in the execution path else modiy the face locatormethod and its coressponding dependabale method to get the path as arguments
String path = Server.MapPath("./XML/");
if (lastPic != null)
{
int faces = objFaceDetector.WrapDetectFaces(lastPic,path);

unsafe
{
int lx, ly, rx, ry, res;
for (int f = 0; f < faces; f++)
{
objFaceDetector.WrapGetFaceCordinates(f, &lx, &ly, &rx, &ry); g.DrawRectangle(myPen, lx, ly, rx, ry);
}
Response.ContentType = "image/jpeg";
lastPic.Save(Server.MapPath("./Images/Test.jpg"), ImageFormat.Jpeg); } detectedImage.ImageUrl = Server.MapPath("./Images/Test.jpg"); detectedImage.DataBind();
g.Save();
lastPic.Dispose();
g.Dispose();
}
}

22 comments:

varun said...

hey nice code but can you gimme the clsFaceDetectionWrapper class.....?????i need it

Unknown said...

Hello,

I am trying to lots of things but did not find solution, i know what problem occuring. When i build the application i can't do that, i go through this article this file does not find clsFaceDetectionWrapper.

how to use clsFaceDetectionWrapper file in my web app ?

If you have any idea please let me know

Thanks in advance

Revelly said...

Hi,

Code is looking fine, but i could not make suitable to my requirement. Can you make me more clear? pls

Anil said...

This is very good piece of code. I am searching for this code from hours and finally your code helped me thank you.

Anil
Developer

Anonymous said...

Code is looking nice. But where's clsFaceDetectionWrapper class? I can't find.

Will any one give me the class?

Shumaila said...

Hi,

I was finding this code... here i found it :)
But the problem is, article does not contain description about clsFaceDetectionWrapper...
Can u please let me know about it... i really need it.

Thanks in advance !

Anonymous said...

how to use clsFaceDetectionWrapper file in my web app ?
kindly reply

sathish said...

Hi,
I am finding this code.. here it is there. could you mind please send this project with solution file my mail id is rangasathish1@gmail.com

Unknown said...

please can you send the face recognition project to my mail id ashk0587@gmail.com,

its really very urgent..

I hope it.. I will be great thankful to u.

have a nice day..

Sikander said...

I'm working on face cognition in my final project but i can't find most of the code :( i'm really halpless , Could you help me please , i shall be very thankful to you, Sikander.khani21@gmail.com thats my id

Anonymous said...

can you send me source code mossyelropy@gmail.com

nakira said...

can you send me clsFaceDetectionWrapper code nakira2008@gmail.com

Unknown said...

please can you send the face recognition project to my mail id
subenekurian@gmail.com

its really very urgent..

Jai Prakash said...

Mam...Please send me the copy of your face recognition project. I need to know the working of it.
My EmailId is:
jplko.simt@gmail.com

Thanks

Jai Prakash said...
This comment has been removed by the author.
Unknown said...

please send the complete code to taofeeq80@gmail.com

Unknown said...

Ma'am plz tell us using which code you compare two faces....

Anonymous said...

can you please send me full code to mike9paul@gmail.com

Unknown said...
This comment has been removed by the author.
Unknown said...

Podría enviarme el código completo a carlosaospina89@outlook.com muchas gracias

Unknown said...

Send me your ALL code of Face detection...
Thanks in advance

Unknown said...

tilekarsumit1@gmail.com