OpenCV tutorial 7: Face and Eye Detection with Emgu CV

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome back everybody in this video we're going to perform face and eye detection on still images using the horror face and I xml files that are included with OpenCV and MgO CV in our project today we're going to use MgO CV and visual basicnet in Visual Studio 2010 Express however if you prefer a different environment for open CV or M blue CV the code that we're going to go through today should translate pretty easily to the environment of your preference if you haven't had a chance already please see the previous videos for installation and configuration of open CV and m vu CV going forward in this video we're going to presume the knowledge from the prior videos let's go alright so before we actually get started making our project today let's take a look at the hard detection I am face files that ship with open CV and MgO CV and again they fun if you follow the previous tutorials for installations you're going to have an MgO installed here and glue x86 a two point four point zero and then from the third open CV tutorial you'll have this M glue or rather open CV installed two point three point one so what you're going to find in each of these if we go through a few directories let's see here open CV data and then our Cascades you're going to find these two files here harp cascade I XML and our Cascade frontal face default XML so what these are is these are huge XML files that contain these data larger large amounts of data and what's going to happen is we're going to call a OpenCV function within our program and it essentially reads in this data and parses through the picture with a tree like logic that allows it to determine if there's a face present or not and if so aware but these files are made by a really complicated machine learning process which we're not going to get into in this video as you can see from the progress part right here these files are very very long but rather than making our own today we're simply going to take the default our Cascade XML files that ship with either open CV or my CV and then perform face and eye recognition with those so with the younggu install you'll see there's only two distributed the heart cascade IA carcass in frontal face if we go into the open CV to point 3.1 open CV data and the park Cascades there's substantially more options here for example we have I and then we have frontal Facebook we also have from this alternate tree alternate to I believe there's a left eye there's a left eye and a right eye that are separate divided slightly more accurate I detection but that's not really necessary for a simple example today we'll just stick with the two that ship with n blue CV our cascade I XML and our cascade frontal face that XML you all right so now our forms I'm looking nice so let's go ahead and add our references actually we probably should have done this first but that's okay as long as we do it before we get to the code so we can go to project add reference browse and then we're going to go till RM go install windows x86 then and then we're going to choose our 8 DLLs okay just a moment wall as those and then we're going to go back to project and an existing item and then once again we're going to navigate to RM go install only this time we're going to go into bin and x86 show files and then everything starting OpenCV and ending diello next in the solution Explorer we have to show all files so we can see our references and then we're going to highlight our dll's here and then go to properties and change copy to output director to copy always alright so now we're ready to start writing our code so we're going to have the environment to generate the beginning of four of our functions for us so let's highlight our form here and then we're going to go to events and then form one resize and double click on that and there we go and now return to design view and then for each of the three text boxes we're going to have the environment start to write the click event there's one of three and 2/3 and this will be three of three and now we're ready to move into our code editor you all right so now our codes all set up and ready to go I didn't realize that I forgot one thing in design view here and bring tool box back up and we're going to include three Open File dialog boxes you so here's our six functions and now we're ready to enter our code so what I'm going to do to save some time is I'm going to fast forward through the member variable section in the constructor section and also the form resize section since that's going to simply be declaring variables and then the constructor in form 1 resize events are really just going to deal with resizing the form and then also I'm going to fast forward through the three functions here to deal with when the text files are clicked those are simply going to bring up the Open File dialog boxes we just added and then allow the user to choose the file and then towards the end when we get to the load and process image function which is actually going to be the MVC be part of it then I'll slow the video back down we can kind of go through it line by line when we get to the opencv functions you so now to the last function in our program lowly in process image where we're actually going to make our m gu CV function calls but before we start writing that let's go back up to the number variable section and take a look at some of the variables we declared earlier so we have three images original grain blank and then two managed CV average comp objects faces and eyes and then to hard cast eight objects face detector and I detector and then three variables for timekeeping stopwatch time span in elapsed time now we can scroll back down start writing our function so the first thing we're going to do is assign to image original so image original is going to be assigned new image and the syntax and visual basic is going to be of EGR right and we're going to pass in only one parameter to declare the image and that's going to be the location of the file for the image which we're going to get directly from the text box on our form so that's going to be text image file dot txt space to work with here the next thing we're going to do is we're going to get the gray image and that's going to simply be image gray is going to be assigned and here we can simply convert from the color image so it's going to be image original deputy Burton so again same syntax of gray comma question and we don't need an examiner for that and now we're going to assign to our to our cascade objects so we're going to have our cascade face detector is going to be assigned in our cascade and here's where we're going to put the string that contains that face detector XML file which again we're going to get directly from the text box so it's going to be text our face file dot txt and then the same thing for I our Cascade our detector is the sign new SKU text RI file dot txt now we're ready to set up tracking our processing time so we're going to assign the label processing time that we're processing and then we're going to make the image by image box blank and we're simply to do that we're going to assign to its image property the blank image then we're going to call it do events so that the operating system can update the form for the processing in the label and then also for the image box and then we're going to start our stopwatch so now we're to the point where we're going to call the detection and the detection that's actually going to detect the faces and eyes in image is a member of the Harr cascade object and that produces a result that we're going to assign to the average cop objects but before we actually get to that call recall from our forum earlier that we have under speed versus accuracy we have these three options here fastest least accurate balanced and slowest the most accurate so what we're going to do is we're going to have some conditional statements here to choose the faces and eyes / those 3 checkboxes you so now we're ready to finally call our detection and in each of these three conditionals we're going to have two calls one for face in one for eyes so let's get started with the baseball here so average count faces is assigned our Cascade face detector that detect and now there's quite a few parameters to this function let's go ahead and enter first and then we'll go over what they are so the first is the internship so that's going to be the grayscale image in 1.2 and more on that in a moment that too and feel free to read the comments that pop up in the autocomplete area here within embassy V those are very helpful for learning about the function that's what we're going to have the constant our detection type dot do candy pruning and then to use the defaults in the XML file the last two parameters we're going to simply make size empty and there's our six parameters so for the first parameter that's going to be the image where the objects are to be detected from and the next crack the parameter is going to be the factor by which the window is scaled between subsequent scans what we're going to do in the next two conditional statements is for a slightly slower but more accurate detection we're going to make this one point one but here we're going to keep this one point two and our next number is the minimum number of neighbor rectangles higher we make this the more accurate the detection is going to be but it's also going to take a little bit longer so for the fastest possible detection we're going to start out with a relatively low number of two and now the next parameter is a constant do candy pruning currently this is the only option available for the function and for the last two parameters if we use size dot empty that will specify the size and the XML files if we specify that anything else this would be the minimum window size and maximum window size of what we're trying to detect either the faces or eyes and now we're essentially going to do the same thing for eyes and then we're going to do the same thing in the remaining two conditional blocks only with slightly different parameters to balance the speed versus accuracy trader you okay so after having copied and pasted from the first conditional statement we're simply going to change the factor by which the window a scale between subsequent scans and the minimum number of neighboring rectangles to sacrifice speed a little bit more for the benefit of more accurate detection so we'll go with one point one and then three and great and then for the sauce but most accurate detection will go up 1.1 and 10 and four-eyes will go with 1.1 225 now note if you were doing a live stream from webcam you pretty much have to go something that would be really quick such as the one point two and two this would take way too long it might take a full second or more as we're going to see momentarily when we test their program so that that completes our detect calls and at that point the time I should stop so we'll put our end time code for the stopwatch you so now we've found our faces and eyes and those are in the average count faces anti objects so we're going to do is for each of those we're going to have a for loop that's going to step through each face and eye and then draw a rectangle at the applicable point in the original image and then we're going to display the original image you so it's going to complete our program now when you go ahead and do a compile and that's a good time one succeeded so let's go ahead and fire it up and we'll maximize the window and so the first thing that we can take a look at is choose how face file and choose har I file so for example if we click on the heart face file text box then we can navigate to by default when we set up the form code we put the text box text to MU windows x86 OpenCV data and our Cascades and to go to this our Cascade frontal face default XML file what we could choose a different one if so desired for example you could go to open CV two point three point one open CV data and our Cascades and then you could choose front of face front face alt tree alt - or default and then same for the eyes there are other options also but for our example today was to stick with the default so we'll go back to the M GU CV windows x86 OpenCV data are cascades in our cascade frontal face default so once you might have left the our face and i xml files as the defaults or chosen ones you prefer then we can click on choose image file and then you can navigate to the image file of your choice i just happen to have a few sample images here in this pics directory and let's take a look at some of the results so you're going to see the default our files work pretty well for example here we have two very nice face detects and six my side detects nudes jacket here we have one false face detective this next scene doesn't work all that great because a lot of the faces are kind of pointed at an angle so we only have to face detects and no eye detects that's understandable though this person the back here has their hats covering their face slightly that's kind of shaded so that's a difficult scene this next image here of lieutenant Gorman is a very good picture we do have one false I detect but we do have a good face detecting two good eye detects and in this next image here we have some good detects for Ripley some of the other folks in scene art detected quite as well here we have a false eye detect and a missing hi detects put a good face detected - good idea text at the center and generally speaking the better lighting is the better the result here we have an outside image and a very good face detected - good idea Tex another good face detect in the background here we're missing some eye detects but it's understandable because dudes eyes are largely are closed there and here's an this next images as an example the left eye and great eye functions would probably work better here we're missing an eye because of the lighting on the side here but we do have at least one that I detect in a very good face detect and this next image this is a reasonable result all things considered of course the lighting in this picture is a little bit awkward because we're pleased burning the alien eggs with a flamethrower but even with delay being kind of odd was still have a very good face detect although we are missing the idea text now this next image works out pretty well background noise can kind of be a hit or miss thing there's some noise in the background as far as the snowplow on the truck but even so we still have a very good face detect on cue here and - good eye detects with no false detects this next image is one where the background noise didn't work out quite as well on TJ here we have a very good face detecting - good eye detects but we have multiple false ID detects and even a false face detect on TJ's jacket so that wasn't the greatest of results now here's one where it's outside these generally seem to work better than inside in my experience with these algorithms we have a very good face detect on a liqu see - good eye detects and no false detects and then back to an inside seen here with the dispatcher good face detect missing 2i detects but it's understandable because the glasses are slightly shaded and the eyes are not really closed with not all the way open invisible and the second image here we have a good face detected to it I detects one false I detect one false face detect and in this image here despite all the background noise and the jacket and so on we still have two very good idea texts and a good face detect and no false the text and this image of Linda here is the image that ships with the samples for open CV and MgO CV by default of course with the algorithms provided the example of the torques well so we have a good face detect and two good eye congratulations you now know how to perform face and eye detection on still images using the art face and hide XML files that are included with open CV and MgO CV I've got some more open CV videos planned for the near future as well some other videos so please stay tuned to 18f 4550 videos
Info
Channel: Chris Dahms
Views: 47,332
Rating: undefined out of 5
Keywords: OpenCV, tutorial, Face, and, Eye, Detection, with, Emgu, CV, Haar
Id: E7LrsoyqATE
Channel Id: undefined
Length: 32min 20sec (1940 seconds)
Published: Fri Aug 31 2012
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.