My target is make a program which take a webcam live video and save only extracted image of faces from that video.
So i use a very strong dotnet library name emguCV . what u can get from here. in short emgucv is
Emgu CV is a cross platform .Net wrapper to the Intel OpenCV image processing library. Allowing OpenCV functions to be called from .NET compatible languages such as C#, VB, VC++, IronPython etc. The wrapper can be compiled in Mono and run on Linux / Mac OS X
So first step is download the emgucv dll files because we are going to use it in our code. After download just add the dll in reference of ur project solution.
Now we need a very important file which is used as template to detect face we called it face_template, It is a xml file, u can get it from here . secondary link is here.
After download the xml file saved in “bin” folder and named it “face_template.xml” .
Now prepare a simple gui, A windows from, two picture box and a timer which is enabled at interval not less than 100.
first step is declare the library just add following
using Emgu.CV; using Emgu.CV.Structure; using Emgu.CV.CvEnum;
second step is initialize the web cam and load my detection template. U can just write this simple code for that
private Capture webcamvideo; private HaarCascade facedetection; public Form1() {InitializeComponent(); webcamvideo = new Capture(0); facedetection = new HaarCascade("face_template.xml"); }
Now timerclick event which will take the webcam captured image one after one. first see the full function code then analyze it.
private void timer1_Tick(object sender, EventArgs e) { using (Image<Bgr, byte> Frame = webcamvideo.QueryFrame()) { if (nextFrame != null) { Image<Gray, byte> grayframe = Frame.Convert<Gray, byte>(); var faces =grayframe.DetectHaarCascade(facedetection , 1.4, 4,HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,new Size(Frame.Width/8, Frame.Height/8))[0]; foreach (var face in faces) { Frame.Draw(face.rect, new Bgr(Color.Red), 3); Bitmap c = Frame.ToBitmap(); Bitmap bmp = new Bitmap(face.rect.Width, face.rect.Height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(c, 0, 0, face.rect, GraphicsUnit.Pixel); pictureBox2.Image = bmp; bmp.Save("myface"+DateTime.Now.Second.ToString() + ".jpeg"); } pictureBox1.Image = nextFrame.ToBitmap(); } } }
Now see what code does
using (Image<Bgr, byte> Frame = webcamvideo.QueryFrame())
it takes a frame from current web cam video stream. after .1 seconds it gets another frame because of timer function interval set to 100, if we want to fastened it we have to use threading.
if (Frame != null)
by this code we certain that we get a picture and can start analysis.
This analysis can divide in two steps.
- detact face
- extract the face
In detect face step we first make the image in greyscale using the following code
Image<Gray, byte> grayframe = Frame.Convert<Gray, byte>();
Now we take a special variable ‘var’ which a special type of Emgu.cv.ml. it can takes all the face location . and we use grayframe.DetectHaarCascade() function which take our template file , edggedetection algorithom type, scale factor and size of the part to except . So the code is like
var faces =grayframe.DetectHaarCascade( facedetection , 1.4, 4,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(Frame.Width/8, Frame.Height/8)
)[0];
now we have to create extracted image of face. “faces” has all of faces information if multiple face have. To extract we use
foreach (var face in faces) { Frame.Draw(face.rect, new Bgr(Color.Red), 3); Bitmap c = Frame.ToBitmap(); Bitmap bmp = new Bitmap(face.rect.Width, face.rect.Height); Graphics g = Graphics.FromImage(bmp); g.DrawImage(c, 0, 0, face.rect, GraphicsUnit.Pixel); pictureBox2.Image = bmp; bmp.Save("myface"+DateTime.Now.Second.ToString() + ".jpeg"); }
here frame.draw() draw the rectangle in the main frame.Graphics g is used to draw the extracted face in new image file which is bmp.
So using this way we can extract the face from live video like this image
hope, u find it cool. this is the most easiest way to detect and extract faces using web-cam or cc-cam
This article is very good, but may I ask for code …??? thanks a lot …..
i am sending the code in ur yahoo mail adresss.
hope it will useful.
u need visual c++ 2008 redistribute and .net framework 4
hi,
can you mail me the code? it would be very useful for my project. I am working on recorded videos.
sownload from here
thanks
Sir pls send the report for “Detect and Track Objects in Live Webcam Video based on Color and Size by C#”
hi!,I like your writing very much! share we communicate more about your article on AOL? I require a specialist on this area to solve my problem. May be that’s you! Looking forward to see you.
can u plzz e mail the code???
http://www.multiupload.com/JURWRD609T
download from there.
thank u
isnt there any way to convert ur code to aforge library??? m trying to implement facial machine learning using pixel by pixel mapping..(not very much efficient method)
the only this i left with is face detection…i want to do exactly the same thing as u did..bt nt able to do so..can u plz help
before using emgu, i made skin color tracing by aforge. not good as emgu but worked well.
just use pixellete filter then a euclidean color(skin) filtering. u can try that.
a certain range it gives good result.
my current thesis depending on that
Pingback: Recognize face orientation using a new approach based on eye position and size by c# | Kishordgupta's Blog
thanks for your source code..it’s very useful for me…
can you send me source code??
thanks
Sir, could u pls convrt the code into vb.net. If, send to my mailbox pls..
Avdvancd thanx!
sorry, i dont know vb
Itz oK.
Could u pls send to me the c# code?
http://www.multiupload.com/JURWRD609T
code is here
pls send how do extract facial image from video
Sir pls send the report for “Detect and Track Objects in Live Webcam Video based on Color and Size by C#”
Sir,
Will you please send me the source code.
Sir, the download link is not available, do you mind upload it in another link ?
Hi Kishore Can I get a copy of your code? I want to detect two color objects instead of face.
can u send me c# code. given link is not working. e-mail : mangalauwu@gmail.com
Thank You very Much Sir……Its very Useful for me
Sir the link is invalid. May your send the source code to me? Your help can greatly improve my understanding.
My email is smcivan@hotmail.com thx !!
SIr plz send the code at moizaj@yahoo.com ..
i need help ..
May you send me a source code? Thank for your help.
I’m so happy to read this. This is the kind of manual that needs to be given and not the
accidental misinformation that is at the other blogs. Appreciate your sharing this best doc.
Hi Kishordgupta
Can you please send me the code at ahhew2006@gmail.com. I had tried for your download link and it is not available, and also lot advertising here and there.
However, i would give a big thanks for your sharing. Lot people are looking for it and hope to learn OpenCV like me.
Thanks
Desmond
Good site you have got here.. It’s hard to find good quality writing like yours these days. I honestly appreciate people like you! Take care!!
Hmm is anyone else encountering problems with the images on this blog
loading? I’m trying to determine if its a problem on my end or if it’s the blog.
Any suggestions would be greatly appreciated.
My spouse and I absolutely love your blog and find the majority of your post’s to be exactly I’m
looking for. Do you offer guest writers to write content to suit your needs?
I wouldn’t mind publishing a post or elaborating on most of the subjects you write regarding here. Again, awesome blog!
I would like to show thanks to this writer for rescuing me from such a challenge.
Just after scouting throughout the internet and coming across recommendations which were not productive, I assumed my entire life was over.
Living minus the approaches to the problems you’ve fixed by means of the report is a crucial case, and the ones which could have in a wrong way damaged my entire career if I had not come across the website. Your own personal mastery and kindness in handling a lot of stuff was crucial. I’m not sure what I would’ve done if I had not come across such a thing like this. I can at this moment relish my future. Thanks a lot very much for this impressive and effective help. I won’t hesitate to suggest
the blog to anyone who would like care on this subject.
please send this code to my email id pavan.srs4@gmail.com