Face recognition, and smart attendance system using OpenCV python!!!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you from the channel learn from basics in this video we are going to make a really cool project using opencv in python and that project is basically a smart attendance system now you might be wondering what does a smart attendance system do well do you know how when you go to school your teacher takes about five minutes of the class calling out each and everyone's name in order to make sure that they're present in class well that takes five minutes of your class time which which in class is valuable because you can learn a lot of more cool things in school if you had those extra five minutes instead of taking attendance so that's where our smart attendance system program comes into play we are basically going to make a program that uses our webcam in order to recognize faces and whenever that face enters the class or whenever that person enters the class it's going to note down who entered the class and at what time they entered the class so in this way the attendance process is going to be it's going to be way faster and again yes this is just a fun project that we're going to do in python and we're actually going to learn a lot but the two main things we're going to be focusing on in this project is going to be number one recognizing and distinguishing faces from one another so this is basically face detection so we're gonna learn how to do face detection with opencv and python yeah isn't that cool then we are going to learn how to store who came to class and at what time they came to class in a folder in which later on in another video we're going to export to a website which shows all the data that's for another video so we're mainly going to focus on face detection and basically editing a file or a folder or a file in order to store who came to class and at what time so let's focus on face detection first shall we so where are fa where is face detection used well here are some examples that come to mind face detection can be used face detection is used in apple's famous face id now the technology apple uses in order to in order to detect faces is way different than the one we're going to use in fact they use infrared light and whatnot in different types of sensors in order to accurately detect your face and we're not we're obviously not going to do that but that's pretty cool and if you want to learn more about apple's face id i'll link an article down below then we have facebook's face detection and i'll tell you how facebook uses face detection later on in this course well after we complete the slide i'm going to tell you how face book uses face detection on its website and app and facebook's method of face detection is actually the method that we'll be using and last but not least we have face detection used in a camera now camera many camera apps and in fact cameras also use face detection or mild face detection in order to locate all the faces in the frame in order to make the picture quality better and again i'll link an article that shows how uh how this feature helps make pictures better so back to the facebook thing how does facebook use face detection in well it's application well we're going to learn that right now hey guys so now as you can see we are in an article that was written by adam gitguy i'm sorry if i read that wrong but um this basically explains how facebook uses face detection in um in its application and we're i'm going to briefly skim over this apple briefly skim over this um this text page in order to get a mild understanding of face detection so let's read this paragraph really quick have you noticed that facebook has developed an uncanny ability to recognize your friends in your photographs in the old days facebook used to make you tag your friends and photos by clicking on them and typing in their name now as you now as you upload a photo facebook tags everyone for you like magic so yes whenever you upload a photo or video on facebook do you know how facebook automatically tags all of your friends who are in the photo so they can check out the photo too well it uses face detection so it you it it uses face detection to detect all the faces in the photo and then it again it uses face detection to detect who each and every person are and then after it does that it basically tags them so how does how does it do that because we can recognize faces pretty easily but have you ever wondered how we recognize faces well we are going to learn about how computers recognize faces so again this um article says this technology is called face faced recognition or face detection and did you know that facebook can recognize faces with a 98 accuracy rate which is about pretty much as good as humans can do so let's so let's talk about how face detects how face detection works so over here they basically use an example of um will ferrell and chad smith uh two favorite um two famous celebrities and we're going to distinguish be between them so first here are all the steps that we do in face detection so first we look at the picture and filed find all the faces in it second we focus on each face and we'll be able to understand that even if a face is turned in a weird direction like it's turned to the right and it's in a bad lighting um with practice the ma the library that we'll be using is going to kind of guess or infer how the face is going to look and it's going to turn the face so it's kind of like in a perfect straight straight view where we can see each and every part of the face third we need to be able to pick out unique features of the face that you can use to tell it apart from other people like how big the eyes are how long the face is etc so if you think about this this is how we um also detect faces so some people have bigger eyes and smaller nose while other people have smaller eyes and maybe a smaller nose and maybe a bigger um mouth and the distance between one person's eyes and another person's eyes is also going to be different so there are many measurements that we can use in order to differ differentiate one person from another finally we're go we're going to have to compare all of the unique features of that face to tell all the people you already know to do with all the people that you already know in order to determine the person's name so as you can see we first find a really good image of the face and then we analyze the face features and then we compare it against the known faces and then we make predictions so as you can see this there is a really cool um here's a really cool like video short video so as you can see this is how face um recognition is used in um camera apps so it detects all the faces so what we're basically doing is i'm going to make this way shorter we're basically taking faces and then as i said each face has unique he has unique landmarks like the eyes nose mouth and etc so what we're going to what face detection does is it takes all of those unique landmarks it takes all the you those unique landmarks and what it does is it produces it produces almost uh so it's so as you can see it produces almost 128 measurements from the input image you gave and it basically it basically generates 128 measurements and no matter how that person is or how old that person is all of these 128 measurements will always be the same well most of the time so what we're basically going to do is we basically as i said we take all the all the main um landmarks on our face and then we produce 128 measurements from that face and then when we're in real time we again detect a phase we detect all of its landmarks and all of its measurements and then we compare all of these measurements to the new measurements we have and this process is basically called encoding our face so you can um you can learn more about this cool feature and this article by reading it i'll put i'll post the link down below but now let's get on to programming so the first thing we're going to do is we're going to open pycharm over here we're going to open pycharm that should take a second so again um if you don't know pycharm is the text editor that i use in order to write python code it's actually a really good text editor so if you don't have that go ahead and download pycharm and so we're going to create a new project and i'm going to name it smart underscore attendance on your score system and then we're basically going to create this project in this window now as you can see python's creating the virtual in my in my environment which will take a second or two so after the virtual environment is done well we'll ask we are actually going to download some libraries that we'll need in order to perform face detection and how this is going to go is first we're going to write a program that's basically going to detect faces and then in the second one we're going to finish our fun project of a smart attendant system so first let's delete all of this we don't need all of this and i'm going to rename this rename file to face underscore detection dot pi okay so now what we're going to do guys is we are going to add some add some libraries that we'll need in order to perform this so we're going to go we're going to go to file settings and now we're going to go to over here where it says project python interpreter and as you can see now we only have pip and setup tools so what we're going to do is we're going to click on this plus button over here and the first thing we're going to download is cmake so as you can see cmake we have cmake um c make by uh jean christoph or this name so we're going to install the package and these packages at first time take a bit of time to um install but cmake shouldn't take that much time to install so so as you can see package cmake it has been installed successfully so now we're going to move on to the next one dlib and i actually had a little bit of a problem with dlib version 21 so i would recommend going to specify version and typing in dliv 19.18 now we're going to install this package and if i'm not wrong this should take a long time to install because that's my prior experience so i'll skip to the part where where this has already been installed hey guys so my um my d-lib just got downloaded which i'll show you here in a second so as you can see it says packages d-lib just got downloaded 19.18 and i just noticed that first many people who are doing this project maybe you're going to get an error message and the reason you're going to get an error message is because you need to download visual studio so how are we going to do that well you simply type in visual studio downloader or installer over here then once you download that in a second or two there should be a platform that pops up as you can see and if you go to so i already have this installed but if you go to available you should have a an application called visual studio community 2019 version so i want you to go ahead and download that and when you download that in the process you're going to get a page that looks something like that that says workloads and then the workload you can choose you can choose multiple workloads but you have to choose the desktop development with c plus plus workload and after you do that you're pretty much good to go to download delay and again dlip takes a lot of time so i think it took me almost 30 minutes to download or something but maybe if you have a faster computer it's faster who knows now the next thing we're going to download is we are going to download the face recognition api so i mean not api the face recognition library so face recognition if we type in face and then recognition recognition so as you can see the author is adam him again so um you should be able to download this you don't have to specify the version this time so if you just click on install package i also think this should take a lot of time if i'm correct but i don't think it takes that much time so again just like last time i'll be back when this package gets installed hey guys so the face detection and um package didn't take that long as long as i thought to open or download so as you can see i have my facebook recognition package downloaded and to finish it off we just need two more packages opencv python which i already have downloaded so i'm not going to click on install package and finally numpy which again i already have downloaded so i'm not going to click on install packages so now what we're going to do next is we're going to click on ok and make sure that we have all the packages needed which are numpy cmake dlib face recognition numpy again opencv python and that's it so now let's write our code so first let's import all the libraries so i'm going to make my program me and i'm going to label everything importing libraries so this is the important library section so what's wrong with that one type highlight all problems yeah whatever so we're going to import all of the libraries which is going our first library is going to be import cb2 and then import numpy and since numpy is kind of long we're going to say as npy then we're going to say import open uh i mean we're going to import the face recognition package and we're going to say as face rec because again the face recognition is a long word to type now what we're going to do is we need to import an in test image or a basic input image that we're going to give the computer in order to like learn how our face looks like so you can just take a own photo of your face or something in general you can just take a snap of a snapshot of your pic face and that would be fine but if you're on a windows laptop this is how i recommend doing it so go to windows go to camera so go to camera and then you should pop up on the camera so that this is me hello so what we're going to do is we are basically going to um we're basically going to want to have the camera in a position where there's good lighting and it can see all of our facial facial landmarks like our nose eyes and mouth and we also want it to be to where it there is a bounding box or a square around our face so after we have both of those conditions done we're just going to take a normal picture now after we take the picture what we want to do is we want to go to the picture and then if you think the picture is fine what we want to do is we want to click on over here and then open folder now i already take that picture before we're going to delete that just delete delete that now what we're going to do is we're going to first we're going to go to the folder we where we have the smart attendant system and we're going to create a new folder and we are going to call it well we can call it anything but i'm going to say um sample underscore images so now what we're going to do is we're going to take this image control exit and control v it now we're going to rename this so it's easier to type i'm going to name it oh ctrl v oh so we're going to rename it and i'm going to name it joshua because that's my name and now we need a second image or a test image so in order to do that we're going to go back to the camera app and this time we're going to tilt our face a bit so to where you could kind of see your eye but you can't quite just to make sure that our camera has our face facial image right so we're gonna tilt our head a bit and then snap a picture okay so now after you have your picture snapped make sure that everything looks fine and then we are going to open this in the folder and then again we're going to do the same thing ctrl x go back to this sample images folder and now we're going to rename it and i'm going to take this joe shake test so my name underscore test now guys we're going to go back to the program and what we're going to do is we are going to import each one of these so how are we going to do that well first we're going to say image deck liberation and then what we're going to do is we're going to say we're going to name a variable so joshick equal to so this can joshua it can be your name or any variable name and then we can use the um cb2 that i am get i am read but i what i'm going to do is i'm going to use a method that face the face recognition packages gave us so we're going to say face rack dot load image file and then we're going to type the path for a file which is in this case sample images and then joshua jpeg so sample images slash joeshik.jpeg and then we're going to do the same thing for joshua test so we're going to say joshua test and over here the variable is also going to be joshua test now guys what we're going to do is um so we're basically going to print these images or show these images which is going to be easy we're going to use the cv2 method cv2.iamshow main underscore image and then joshick and then we're going to copy paste that and now we're going to say test image joeshik test and then we're going to add a weight key of cv2.weightkeyof0 and then we're going to say cv2.destroy all windows now um in a second we should have two images pop up so as you can see both of these image look weird don't they because you can see that like um my skin is blue and everything and they're just too big so we need to do two things well if your image is all right you don't have to do this next part but if your image is too big just like mine i would recommend doing this so we need to do two things number one we need to turn back this image into a normal image so the colors are not all distorted so let's do that first shall we so how are we going to do that well we're going to say joe ship equal to cv2 dot cvt color so convert color and then what do we want to convert the color of well we want to convert the color of josig and then we want it to go from that weird color scale which is btr to the regular color scale which is rgb so we're going to say cv2 dot color so this is all caps color underscore bgr which is the weird one to rgb and then we're going to copy this paste it right over here and we're going to say joshua test and we're also going to say joe test now if we display this you can see it's back to normal but it's still a bit too big isn't it so that's going to be our next task this image is a bit too big so as i said in our next task we're basically going to make the image smaller and if your image is already small you can skip this step again just um just skip like a minute or two and you should be good but if your image is really big then here's what we're going to do we are going to first declare a new section which is going to be image i mean um functions and we're going to make a function we're going to say define resize and we're going to take two parameters the frame or the image and the size now what we're going to do is we're going to write some simple code we're going to say the width of our image is going to be int our image times the side our image.shape of zero or of one which is the width times the size and then we're going to copy and paste that we're gonna make this zero so image.shape of zero is the height of the image and we're gonna make also this times the size and as you can see i spelled height from so we're gonna change that and now we're finally going to do is we are going to say are the dimensions final dimensions or dimensions are going to equal to a tuple of the width and the height and then we're going to return cb2 dot resize and then the source is going to be our main image and then we're going to say dimensions and then the interpolation is going to be cb2 dot intro area cv2 dot inter area so now we're going to use this property on both of our images and you can so we're going to say joe ship and then the size you can mess around so you can say 0.50 or 0.25 but if you use the method which i used which is using the camera app to snap your image i would say you say 0.50 but again you can you can use any any value that's under a 1 so 0.90 or something like that and it will slowly start decreasing your picture size so i would just recommend messing around until you have your preferred size so we're going to say joe chic test oh and i'll also say joe shake is equal to reset and over here we also have to say josec test is equal to resize so now if we run this we should have our images smaller so as you can see our images are smaller and they are in the right color so now let's start our face recognition shall we so the first thing we have to do in both of these images is we need to find where the face is we need to find the face location and we're just going to do this so we know if our uh if our program is detecting the right face so we're going to delete both of those stop the program and now we're going to say finding face location and now what we're going to do is we are going to say face location face location underscore shake because this is going to be the face location of the face in this image or our main image and we're going to say facerec dot face locations and now we're going to pass the image which is going to be josek and that's all we're going to do and since this is an image we're going to simply say zero now what what what we're going to do is you know how well you remember how um i said that do you remember how i said that our um the face recognition package that we just downloaded um makes up almost one um like brings up almost 126 or something measurements of our face and then we use that measurements to recognize uh if the face is my face or another person's face well again do you remember how i said that process is called encoding the face well that's what we're going to do next after we find the face location we're going to encode the face so we're going to encode my face so we can use that encoding data to recognize if i am in the frame or not so we're going to say encode and again this is going to be encoding my original face to encode joshic equal to face rack dot face underscore and coatings and then again we're basically going to say we're going to give the source of where my original face is which is going to be joshua and since this is just an image we're going to say 0. and now just to make sure that the computer is recognizing my face correct we're going to draw a rectangle around my face which is easy cb2 dot rectangle joe and then the points are going to be face location joe chick of three and face location joe chick of zero so the face location um function that we used gives us back uh four values so we're going to say that and then in our second um in our sec in our second point we're going to say face location joshick of one and face location joshikov two and then we're going to declare the color which i'm going to give two five five zero and two five five let's bring that down and then last but not least we're going to give the thickness which i'm gonna see three maybe now let's do this process over again for our test image which is jose test so all we're going to do is we're going to copy that paste that down here and now we're basically going to take change all the josek to joshua test so instead of face location joe ship we're going to see face location joe shake test and over here instead of joshic we're going to say underscore joe shake test same here joe should test and encode uh face location joe chick test and then we're going to say rectangle and we want to draw the rectangle on joshua test so now how about we show all of these images again so let's make sure that our faces or the computer is detecting our faces correctly so as you can see our computer is detecting the faces correctly yes this is off by a bit but that's okay that's really shouldn't make that much of a big difference now let's stop this and what we're going to do is just for fun let's display all of the encoding values so we're going to say print and we're going to first print encode joeshik and then we're going to print and code josec test so let's do that again again it takes some time to compile or yeah so now as you can see we have all of the values over here for joshua and all of the values over here for joshua test and if you can read each one of them they are actually similar so what we're going to do is we are basically going to since we have our encodings ready we are basically going to what we're going to compare both of our faces so let's delete this and comparing our faces is actually easy we're going to say results equal to face face rack dot and then we're going to say compare faces and now first we're going to give all of our source images or our main images so since we only have one main image which is going to be joseph we're going to pass that so joe sick oops joshua and now we have to tell the computer what we're going to compare joshik with which is going to be actually now this is in code joshik so remember in code joshik and we have to tell the computer what we're going to compare and code joshua with which is encode joshua test now we're going to say print the result please print results so let's run this test again and we should get it through so as you can see it says true yes so now just to make this a bit more fancy per se we are going to put some text cv2.put text cb2.put text joesticktest i mean cb2 dot put text and we're going to put this on joseph test and then the text is going to be f of results and then we're going to say 50 so we're going to say the we're going to say 50 50 which is the origin 5050 and then cv2.font which is going to be hershey's so you can choose anyone i'm just going to choose them hershey's complex and then we're going to choose a thickness of one and finally we're going to choose a color of maybe black so actually let's just choose blue 255 and then the thickness is going to be two and that should be it so that should take a second or two so as you can see it says true over here now just to test what we're going to do is we're going to go on to google and we're going to say we're going to say well on maybe a picture of a picture of elon musk why not so now we're going to go over here we're going to take one of elon musk's images we're going to save this image as so we're actually going to save this in so we're going to go to python project projects our smart attendance system and then sample images and we're going to save it there and we're going to name this just elon musk elon musk we're going to save it now over here where it says so let's stop this program first and now over here where it says um for the test image you know how i said joe shake test well over here instead of joshua test where say elon musk dot jpeg now we should get a result of false this should take a second or two so as you can see it says false because well i'm not elon musk unfortunately or fortunately i don't know but as you can see our face recognition works and isn't that fabulous so you can see how easy this code is we just we just completed a full on face recognition with just a simple 39 lines of opencv code or python code so this is how we do face recognition guys and in our next part we're basically going to use this and kind of combine this to another simple program to make a smart attendance system hey guys so we completed the face detection so the next thing we're going to do is we're going to move on to our main program or our main project which is the smart attendance system so before you do that what i want you to do is i want you to go to the smart attendance system folder or our main project folder and then i want you to create a subfolder that you can name it whatever you want but i'm going to name it student images and inside that subfolder what i want you to do is i basically want you to store a bunch of images of all the people that you want to detect so i have joe biden myself and obama so just uh snap a picture of all of the students or people that you want to be able to detect and make sure that you have their name dot jpeg because we're going to be using their name in a second and you'll i'll tell you'll probably figure out why we want to name the file of their picture with their name so the first thing we're going to do is we're going to create a new file we're going to name it python file and we're going to name it um smart attendance attendance system program yeah that should be good now we're going to import our main files which is import cb2 and then import numpy is important numpy and since that's long we can say npy and import face rack face recognition as face rack because again face recognition is just too long so guys the next thing we're going to do is first if all of your images are the size that you want and they're not too big then you can completely skip this step but i'm going to do this because i snapped again i snapped all of these images from my webcam so they're kind of too big so i want to make them small so we're basically going to go to face detection and then we're going to copy this function that we made and we're going to paste it over here and then guys the next thing we're going to do is we we need a way to well get all of the images from [Music] we need a way to get all of the images from this folder from the student images folder and we need to wait to get all of their encoding and to refer to each one of those pictures and we need a faster way to do that because in our previous example in the face detection we had to go in and manually say joe equal to face rack dot load image file now imagine you're a teacher and you have about 100 students this means that you have to repeat this pro you have to repeat this process so you have to write these three lines of code over 100 times so and we don't want to do that we want to find an easier way to get all of the images from this student images folder and basically store store the image convert it to from bgr to rgb and then resize it if they need to be resized so how are we going to do that well we're going to write a function for that too but before we do that we're going to write some simple variables so we can write that function we are going to number one write the path which is going to be the path to the folder that we have um that we have all of our uh student images in which is student images and then we're going to create an array called student image which as the name says all of the images of the students and we're going to create a list for that and then the student names student name so we need to get the names of each and every student too so we're going to create a list for that too and then we're also going to create a list for all the encodings but that's going to be in another function so what we're going to do is we are simply going to write my list is going to be equal to and before we do that we also need to import os um and i'll talk about what os means in everything towards the end of the video or when we um finish this snippet of code so we're gonna say we're gonna say my list equal to os dot o s dot list d i r and then we have to give the path which is just simply the pack and now we're gonna print my list so now oh yeah i spelled that wrong so that's a small m and a capital l so now if i yeah whatever so if i run this i should get the names of everyone on the page so oh yeah so i run the wrong so we're gonna say run smart attendance and we're gonna rerun it stop and rerun so as you can see it basically retrieves all of the images or the name of all of the images from my student images so it has joe joebiden.jpg joeshik.jpg and obama.jpg now what we're going to do is we are going to first comment this because we don't need this and we are going to we are going to simply write a for loop over here that that we're going to use in order to store all of the images because we just got the name of the images right and do you also see how it says over here dot jpeg so later on in this video we we're also going to write a small program to greet each one of these students so when we do the do that we don't want our program to say welcome joesheet.jpg to class because that just sounds weird so we're all in this for loop we're also going to get rid of the jpeg part so we're going to say for cl or classes in my list so for classes or cl in my list we want to say current image or c c u r for current and img for image is equal to and we're just going to use the cv2.iamreed instead of the other method we use which is facerect.loadimagefile so we're going to say cv2 dot i am read and the file name is well f and then we're going to say path then we're going to say slash and then co because as you can see the path is student images and the five in the class is whatever class we want to choose so it depends on the for loops so for example let me yeah for example imagine let me run this again to get the results what oh yeah i commented this so if we want to get the results again you will see that so how this loop basically works is you say for seal in my list so it's going to go to my list and it's going to retrieve the first um first object in my list which is joebiden.jpg and then over here our current image is going to be cv2.iamread and then what this basically means is f and then path as you can see is student images so what it's going to say is student images student images student under underscore images and then it's going to say slash and then as you can see co in in the first iteration of the group a loop is joebiden.jpg so over here it's going to say joe biden joespacebiden dot jpeg and then as you can see that's the exact path of our first image so that's how this basically works so we're gonna get the image and then we're going to add that image to our student image uh list so we're gonna say student image dot append append basically means to add on to the list and then we want to add on the current image current image now we're also going to have to we're also going to have to give all of these we also have to get rid of the dot jpeg at the end of each one of these names so how are we going to do that well first we're going to say student name dot append because we want to store all all of the names in the student name list and then we're going to say os dot path dot split text and then what text do we want to split well the cl or the class or joe biden.jpg and then we're gonna say zero so this is basically going to split joe biden from the dot jpeg part and it's only going to leave us with wall it's only gonna leave us with joe biden and isn't that what we want and after we do that what we can do is we can print so after we do this whole thing we can print student name now if we print that you can see it says joe biden joshua and obama instead of joebiden.jpg.jpg and obama.jpg so i hope you understand this simple for loop now the next thing we're going to do is we're going to find the encodings of each and every one of this image so let's go to that shall we so we're going to declare so we don't need this nor do we need this print function so we're going to label that or comment then and then we're going to say define or def find encoding of the image or find encoding that's going to be your function name and we're just going to have one parameter which is going to be the image images that we'll will receive or like in our case we're going to have to put in the student image or all the images that we want to encode then we are going to say we're going to create a list to store all of the encoding so encoding underscore list equal to that and then we're gonna we're gonna write a loop in order to get the encoding for each and every image so we're gonna see four image in images and then we're going to say first we're gonna resize the image and again you can skip this step if your image or your main image is just like the perfect size but if you used my method to get all these images which is taking a picture from the windows camera app they're going to be a bit big so we're going to say image equal to resize and then we're going to say image comma 0.50 or whatever whatever value you got from your last face detection um so whatever this value whatever this value you got you're going to put it in over here and if your image is just the right size you don't have to then we're gonna convert the image to like you can see like the last time we did this we before we converted the image they were like my skin tone was kind of weird and the colors were distorted so we're gonna cut we're gonna make that right so we're gonna say image equal to cv2 dot convert color and then our source is image and then we want to say cb2 dot and this is all caps color and then we want to convert from bgr to rgb or we want to convert from blue green red to red green b i mean red green blue which is the normal color palette now what we're going to do is we're going to encode the image so we're going to say encode in code image equal to encode image and we're going to say face wrap dot face encodings of the image image and then again we're going to add a zero to the end because this is just an image and not a video and then we're gonna say encode list dot append and then you guessed it encode image and then at the end we're gonna return the encoding encode list now we have the function where we get our encodings written so i just said fin encoding instead of finding coding now the next thing we're going to do is well we are simply going to plug this into a main video um we're going to plug this into a main video program or we're going to plug this into a while loop that will basically get the get the video and find all of the faces in the image and then compare all of those faces to the faces that we have so what are we going to do well first we're going to say while actually no first we're going to say encode list in code lit underscore list equal to encode i mean find encodings of well we're basically going to find the encoding of student image which as you can see which as you can see are all of the images of the students that we we retrieved from the file using this for loop then we're going to get our video from the webcam so we're going to save vid equal to cv2 dot capture video vid capture video capture and then we're going to say zero because zero basically tells the computer that with the source of our video is going to be your webcam and if this doesn't work that means you have an external webcam so you can either try one two three or four then we're gonna write a while loop so while true shoot and then we're gonna forget each frame individually so success and then frame equal to and then we're gonna say vid dot read so we're basically getting each and every individual frame from our live video then again you don't have to do this but i'm basically just resizing our our frame so our um program runs a bit faster so we're going to say frame frames equal to cv2 dot resize now this is a faster method of the resize function i put over here but i just use the resize function for these frames because like i just feel comfortable using it but in a while loop i recommend using this version which is resize and then frame and then we're going to say zero 0 and then none and then we're going to say 0.25 and 0.25 um why is the nun oh yeah it's a capital n and then an o-n-e now what we're going to do is we are going to we are actually going to convert the color so so how are you going to convert the color well i'm pretty sure you know this so i'm going to give you about five seconds to think think through it and convert the color because this is actually a really um useful command that you have you'll have to learn so about five seconds to memorize and if you need more time then well pause the video did you get it well if you didn't then that's perfectly fine because we're going to go over it right now we're going to say frames equal to cv2 dot convert color the short form for convert is cvt color and then our source is going to be frames and then we're going to say cv2 dot color color and then what do we want to convert it from what we want to convert it from bgr to rgb so that's what we're going to do now since we have all of our frames converted to the right position what we're going to do is we are now going to recognize all the faces in the frames because there could be multiple students entering the class at the same time so we need to be able to detect multiple people in a frame at the same time so in order to do that we need to detect all the faces in the frame so we're going to say faces underscore in underscore frame equal to and then again we're going to use the face recognition package we downloaded so face rec and then dot face locations and then our image source is going to be frames and this is and since this is a so now that's where we're that's how we're going to get the face locations and then we're going to encode all of the faces in the frame so we're going to say in code underscore in underscore frame and then we're going to again use the face recognition package and then we're going to say and then we're going to say face encoding facing coatings of frames and then over here you see how it says known face locations equal to none but we don't want that that's actually the default so we want to change that our known face tracks uh face locations in the frame our faces in frame now since we have all of her faces encoded our next step logically is to well detect all the faces and we're going to do that in our next part which i'm just going to cut to in three two one hey guys so so now as you can see we completed our face detection program which was pretty cool so we learned how to identify recognize and distinguish faces so we basically did a face detection program so now what we're going to do is we are going to write a simple program that basically completes our project of the video which is making a smart attendance system so you know before we do that i want you to do oh two of two things number one i want you to create a folder in the smart attendance system folder and inside that folder i want you to name that folder student images and inside that folder i want you to choose three or more images of the people that you want to recognize so this as you can see i want to recognize elon musk myself and mark zuckerberg and again uh so in order to make the process that we're going to do work you have to name each one of the pictures the name of the person in the picture.jpg so now without any further ado let's write our program so just like we start any program we're going to import all the libraries that we'll need or all the packages we'll need which are import cb2 import numpy as np because numpy is too long and import face rack face recognition as face rack so now since we have that down let's start our code shall we so the first thing we're going to do is um i am personally going to get go to face recognition and get the resizing function that we wrote just because i want to i also want to resize all of my images in this program too because the images are too big and again this is optional if your images are just the right size if they're not too big you don't have to do this now the next thing we're going to do is what we want to do is we we want to get we want to find an easier way to get the source images of all of the people that we want to detect because as you can see over here in the face recognition we have to manually upload we have we have to manually upload and find the encodings of each and every person and since we had only one person we wanted to detect me or yourself it wasn't that hard because we only had one person but imagine this was used be this would be used in real time where teachers would have to enter well in my school there's 30 students per class and there are three classes which makes it a total of 90 students so you have to repeat this code for 90 students yeah that's time taking so we want to find a way to make this easier so we want to find a way to where we can write a simple for loop to retract all the images the names of each and every one of those images in the encodings of image of those images straight out of this folder so you just um upload the students you want to recognize in the folder and it gets it and that's exactly what we're going to do we're going to write a simple for loop to get the name image and encoding of each and every student and in this case we only have three but you can have more and now what we're going to do is as i said we're going to write write the for loop but before we do that we're going to declare some variables we're going to declare path which is basically the name of the folder that our students source images are which is student images then we have the then we're going to write we're going to declare two lists in order to store the images in the encoding of each one of the students inside so we're going to say student image equal to list and we're actually going to find the encoding in another for loop for now we're just going to find this um pictures we're going to get the pictures of each and every person and the name so we're going to say student name and we're also going to create a list now guys what we want to do is we first want to get we want to get the names of each and every one of the person inside the student images and we want to store that in a list so we can say my list is equal to and in order to extract uh the names of or the names of each and every one or the names of the pictures in the student images folder we what we want to do is we want to import a package which is going to be import os now what we're going to do is we're going to say os dot and then we're going to say list dir so this basically extracts the uh name of each and every one of the images from student images and we are going to tell um we're going to tell the program from where do we want to extract the images from which in our case is packed because the path has the name of the folder now let us continue what we're going to do now is we're basically going to print the path so print path now if we print that so oh yeah it's not path we're supposed to print my list because that's where all of the names of each and every one of those images is so as you can see it says elon musk.jpg joeshik.jpg and mark zuckerberg.jpg and i know how there's a dot jpg at the end and we'll fix that in the for loop that we're going to write so let's write the for loop where we basically extract the actual names of the people so we like uh take off this dot jpeg and also each and every picture or these three pictures and we store them in the student image list because this just brings out the names of the images not the images themselves so we're going to write a for loop and now we want to store the image in the name of each person and we want to do that in like an order in a nice order so we want to find the image we want to store the image in the name of a person's image we want to do that one by one so we want to go elon musk first elon musk.jpg first then we want to go to the next one which is do joshich.jpg then we want to go to the next one which is mark zuckerberg.jpg so in order to do that we're going to write a for the we're going to say 4cl in my list so what this basically does is it goes so what so if this was the first iteration or the first time this loop was running cl would be stored with the value of elon musk.jpeg because that's the first item in the my list list and then if it's the second iteration it would say josh it would have the it would have um the value of cl would be joshie.jpg because it's the second iteration and this is the second object in my list and for mark zuckerberg.jpg it's the same thing since it's a third iteration in cl there would be markzware.jpg because this is the third thing in the mind list so now since we have that out of the way let us write three lines of code in order to store the images and the names of each and every one of the students so we're going to say current image is equal to and we're just going to use the cb2.iam uh ironread because that's easier and we're not going to use the face recognition method so we're going to say cv2 that i am read and first the file name so we want to have we want to have the source of we want to have the source of the image that we want to retrieve now this is going to be a bit different we're going to say f of first of all that path because inside the path is the name of the folder of our image and then slash and now we want over here we want the path of the image or the name of the image we want to retrieve and if you remember about if you remember the logical explanation i gave you you would remember that in each iteration the name of our folder would be stored in cl so over here we're going to say cl and now what we want to do is we want to add this current image variable to our student image list because we want to store all the images in a list so we're going to use the append function we're going to see student image dot append and what do we want to add on to the student student image list we want to add on current image and then for the name it's actually really simple we're going to use the append function again so we're going to say student name dot append and we what what do we want to append we want to append cl but the problem is that as you can see when we append cl the whole thing comes in so it's elon musk.jpg but we don't want that we only want the name to be elon musk and that's it so what we want to do is we want to divide the we want to divide this name into two parts the name of the image itself which is elon musk and the dot jpeg part so in order to do that we're gonna use os again we're gonna say os dot text split or um i think it's a split text so we're going to say os.path dot split text and now what do we want to split the text of we want to split the text of cia and as as you can see our image splits into two parts the name itself which in this case is elon musk and the dot jpeg part so now we want the first part we want the first part of the uh of the two um two versions of this name so now if you remember your basic list of list um if you remember your basic list knowledge you'll know that the first item in a list doesn't go by the number one but instead it goes by the number zero and that applies here so the first part of the of this name doesn't go by the number one instead it goes by the number zero so that's why we're going to enter a 0 over here and now we're going to print the student name just to make sure we have everything down now it should work in a second as you can see it says elon musk joshua and mark zuckerberg versus elon musk jpeg joshua jpeg and mark zuckerberg.jpg and in order to clarify the um the name the like the names get split into two parts thing what we're going to do is instead of saying getting the first part we're going to get the second part is the dot jpeg so now now if i run this you'll see that the output is all dot jpeg so i hope you understand this part so in our next part what we're going to do is we are going to find the encodings of each and every one of the images on on the frame so let's get into that hey guys so um we just completed on getting the name and image of all of those sample images in our student images folder and now we're going to find the encoding of each and every one of those images in the student images folder and we're going to store all of those encodings in a list so in order to do that we're going to write a function so we're going to say def or define and then we're going to write the function's name which is going to be find encoding and then we just need one input value which is going to be um images or the list of all the images that we have to find the encoding of then we're going to declare a list called image encodings equal to and we're going to declare it as a list and now what we're going to do is we are going to write a for loop so we're going to say for image in images and we're going to do this so we can encode each image one by one so we get one image from the images list that we encode it we store it in the image encodings list and then we move on to the next one so that's why we wrote the for loop so we're gonna say image so before we um encode this image we're gonna have to change the image a bit so number one first of all we want to resize the image now this is optional but i'm doing this because um well i just find it uh because my images from uh my images from the student image i took them off of the camera app from i took them off the camera app from uh windows so that's that's why i am that's why i'm making them smaller because they're really big but it does work even if your images are big but i just like to make my images smaller so we're going to say resize we want to resize image and we want to resize it by 0.50 now we're going to write we're going to change the image color so whenever we get an image it's kind of like in a weird bgr color which kind of makes your skin look blue i hope you remember that from our first part of the video so we're going to do the same thing as we did in the first part of the video to solve it we're going to convert the color palette from um from bgr to rgb so in order to do that we say cv2 dot convert color and what do we want to convert the color of well we want to convert the color of image and we want to convert it from so we're going to say cv2 and we want to convert it from bgr to rgb so there's that now the next thing we're going to do is we're going to find the encoding of each one of these images so we're going to say encode image equal to face rec face encoding and we're gonna say the encoding of image and we're gonna add a zero because it's an image now the next thing we're going to do is once we get the encoding of the images we want to add that encoding to the image encodings list so in order to do that we use the append function so we're going to say image encoding dot append so what do we want to append or add to the image encodings list well we want to add the encode image now we we can we have a list for the encodings of each and every one of them of the sample images so now what we're going to do is we're going to return that um encode image encodings list because we'll need that in our program now since we have this function defined we are going to write our while uh uh yeah our while loop uh on where we get we're on where we get live feed from our camera break it up into frames find the faces in those frames and compare those faces so let's do that but before we do that we need to do two things we need to number one get a live stream from our webcam and number two we need to get the encodings of all of the faces or all of the student pictures so we're gonna say so in order to do that we're going to say um we're going to say encode list so we're going to create a variable in code list and we're going to say find encodings and the list of images that we want the encoding of our student image as you can see so we're going to see student image now the next thing we're going to do is we're going to get a live feed from our webcam so in order to do that we say vid equal to cv2.capture cv2.capture i mean video capture and then we're going to capture we're going to video capture zero or we're we want live feed from our camera now if zero doesn't work um you probably have an external camera so you can you can try out one two three or four and they should work now we're going to write our while loop so wild true and now what we're going to do is we are first going to break our live feed into frames so we can process each frame so we're going to say success frame equal to vid dot read now we're getting we're turning our video or live stream of our webcam video into frame so we can process those frames then we want to make the frames a little smaller because well it just makes it just makes the whole thing easier to process it makes the it makes it easier to process for the laptops so our processing rates will be greater or um our program won't be as laggy so in order to do that we're actually going to use a different method to resize other than making our own function which is going to be cv2.resize so we're going to say smaller underscore frames equal to resize actually cv2.resize and now we just gave it some parameters or inputs so number one our source which is going to be frame and then we're going to say 0 0 and then we want none and then we are going to say 0.25 and 0.25 oops 0.25 and 0.25 and the reason none isn't an error because is because there has to be a capital n now everything is fine for the most part so the while loop for oh yeah so um there was a false indent that should yeah so now we have no errors now the next thing we're going to do is we are going to well we're we're going to find all of the faces in our frame because when students are entering the classroom there could be multiple students entering the classroom where they could be multiple faces slash students in the frame so we want to find each and every one of the each and every one face one of the faces in our frame and then we want to compare each one one every one of those faces in our frame to our sample images so in order to do that what we're going to do is we are going to well first we're going to find all the faces in our frame so we're going to say faces in frame in order to do that we say face rack dot face location and then um well where's like what image am i supposed to get the face locations from so over here we're supposed to input that so we want to get the face location from smaller frame we want to get it from there so smaller frames now the next thing we're going to do is we are going to encode we are going to encode each of the face in our frame so then we can later use that encoding to compare it with the other with our original sample images so we're going to say encode faces in frame and then we're going to say face rack dot encode facing coding and now we're going to actually give it two parameters number one we're going to give it the location of all the faces in the frame we know and before we do that we have to give it the source of where like our face is or like where where is the image and where we want to find the encoding of so we're going to say the source which is smaller frame smaller frames and then the faces or all of the faces in our frame so we're going to say faces in frame the location of all the faces in our frames in our frame so now what we're going to do next is we are going to write a simple for loop that basically allows us to compare all of the encoding of the faces in the frame with our original si original encoding of the pictures guys so we're going to compare all of the faces in the frame with our original pictures so we're going to write a simple photo for that we're going to say for encode face and then face look or face location and again we're writing a four loop because there will be multiple faces in the frame and we want to go through each and every one of those fake faces in the frame one by one i'm gonna say in zip and then um we're going to give the values of of the encoding of all the faces in the frame so encode faces in frame oops encode faces in frame encode faces in frame and the face is in frame so we know the location of the face is in free and again as i said we're using zip because we're getting uh two values from two individual lists so we can use zip so we can just do that in one for loop and again we're writing the for loop so we can um compare face uh compare all the faces uh one by one so now what we're going to do next is we are going to first have matches and we're going to have it compare we're going to have it compare all of our uh we're going to have it compare the face in the frame with all of our sample images so matches equal to faces i mean on matches equal to well um we want it to equal to face rec dot phase compare or compare faces and then our known faces or the list of the known faces is up here you can see it's student image so we're gonna say uh so we want the encoding of the list of the known faces which is encode list and then we also want the encoding of the face we're comparing it with so in code face now we also once we find the match we also want to find uh the distance or the face distance so how far away is the face in our frame away from um our three sample images so we're gonna say face this equal to face this equal to face rec or not face look face rec dot and then we're going to say face distance and now since we're giving we're giving this the input of um so like since we're giving it encode list which is a list with three um objects it's going to give us an output of also three objects which is kind of nice and then we're going to say encode face because that's the encoding of the face we're comparing it with now guys what we're going to do is we are going to print the face distance just so we can see it and then we are also going to match we're also going to have a match index which basically finds um the uh the least from all face uh so like it finds the least amount or the lowest amount from the face distance so match index equal to np dot argument arg min argument and then we're going to say face this now we're going to write an if condition to see if um uh if the face is matched up and if it did in in which case it actually did since the faces match up we are going to find out we are basically going to inside this in if condition so let's write that if condition so we're going to say if matches of the match index match index so now if there's a if there if the face in our frame compares or matches one of these sample images we want to draw a rectangle around that face and under that rectangle we want to have the name of the person so we're going to say first we're going to have the name which is going to be nate um name is equal to student name so we're gonna get the name out of the student name list of match index because that's gonna tell us whether it's zero one or two and then we're gonna say dot upper you know just so our name is in all caps and then what we're going to do is we are going to get the wa the x and y axes of the face location so we can draw a rectangle around it so we're going to say y of one y of one x sub two y of two and x of one from face look or face location now do you remember how all of these calculations like the face location and all of these calculations are based off our smaller frame well when we show our output we don't want our output to be shown as the smaller frame instead we want the output to be shown as the bigger frame or the original frame because it looks better so if we just use these values on the original frame it's going to be off by a lot so we'll have to convert these values or multiply each one of these values times four in order in order to bring these points back to normal because as you can see we divided um the side length by 0.25 or one by four or one fourth because 25 is one fourth so in order to bring it back logically we have to multiply each and everything by four so we're gonna so we're gonna copy this we're going to say this equal and then we're going to multiply each and everything by 4. so let's do that now that we have the now that we have the y and x values all matched up what we're going to do next is we we are going to draw the rectangle so we're going to say cv2 dot rectangle uh so first we have to give it the source for what image we're supposed to draw the rectangle on which is frame and then the points which is x of one y of one and then x of two y of two and again we're giving this the points in tuple then we're going to go over to the color which i am going to give it a green maybe because you know why not then we have the thickness which i'm going to give a thickness of two maybe three yeah three why not now underneath the triangle or the bounding box of the face we want another triangle that's filled in and very thick and inside that triangle we want the name of the person so we're going to say cb2 dot rept i'm sorry highman rectangle.triangle and then again we want to draw this rectangle on the frame now the points are going to be slightly off so it's still going to be x1 but since this has to be underneath um this main rectangle we're going to say y of 2 so y 2 minus 25 and then in this tuple we just say x of 2 and y of 2. then the next thing we're going to do is we are going to give it a color i'm just going to give it green again because it fits our main box and then we want the green to fill the whole box so we will say cv2.field now let's write the text so we say cbt.put text and then we first have to tell on what on what image i'm supposed to put the text so frame and then i believe we say what is the text the text is going to be the name of the student which is in the variable name then we have x1 plus and then the location is going to be x of x1 plus 6 and y2 minus 6 and y2 minus 6. and then we are going to give it a font um font like font face which is going you can give it anything but i'm going to say font hershey complex hershey yeah hershey complex and then the font scale is one the color is going to be white because um it it like contrasts with green and then our thickness is going to be a thickness of two now since we have the text the next thing we're going to do is we are going to show the image so we're going to say cv2 dot i am show frame let me and then since this is going to be a video we're going to say cv2.weightkey we want a weight key of one now guys for the grand reveal will our program work so let's run our program to see if it will work any second now it's going to take a bit of time because we have 55 lines of code so well okay so um you're also supposed to give a name for the window in which our frame is going to be showed so i'm going to say video now it should work i think so as you can see it's working let's go so it it detected my face you can see it detected my face um but just to make sure i'm going to bring up the image of elon musk over here and as you can see it says elon musk and if i kind of space it out and i also bring myself beside here actually if i go back a bit and kind of bring elon musk a bit up front it should be able to detect both of our faces um yeah so as you can see it detected both of our faces both elon musk and myself and also mark zuckerberg which it should be able to detect so as you can see it says mark zuckerberg and now as you can see our program works isn't that just great so as you can see if there is a bit of a lag like a bit of a lag but that shouldn't really make that big of a deal especially because we're making an attendance system so let's stop this program now guys since we have this part done since we have the main part done which is the face detection part we are going to move we're going to move over and um i actually noticed a little fault i don't know if that's yeah so um we're actually going to shift tab this one more time that's just going to make our thing a bit more smoother so if i run this again it should be smoother so as you can see it's a bit better you could say the frames they're a bit faster um let me put elon musk back here so as you can see elon musk is there and then mark zuckerberg where is that covered so let's go so our face detection is working and our next part as i said is to is to well mark the attendance of each one of these students and we also have to greet the students when they enter the class so the next thing we're going to do is we're going to create a folder so we're going to say new or or file and now we're going to name this file attendance uh did i name that attendance dot csv so in this file what we're going to do is we are going to we are basically going to store all of the data on which student came to class at what time so we're going to say name and time so if i attend it to class right now it would say something like this so it would say joe and then 6 40. so we're going to make it something like that but it's going to be automatic so now what we're going to do is we're going to go to face detection i mean on our smart attendance system and now we are going to write another we're going to write another um we're going to write another function so we're going to say define mark attendance attendance and again the uh the only input that we'll be taking this time is going to be the names of the students so we're going to say name now let's write our code so now the first thing we're going to do is we are going to open the we're going to open the attends attendance.csv file so we're going to say width width and then we're going to say open and now over here we're supposed to specify what file we want to open so it's going to be attendance dot csv and we also want to say if we want to read or write in the file and we want to do both and here's why so per se i entered the class and the camera detected me now many times when students enter the class the teacher is there to greet them and um they also take a quick uh five seconds to greet their teachers or to talk discuss really quick a really quick question or personal question they had about whatever so they'll have a quick chit chat with the teacher so when it does that what happens is our program detects the face and if we don't read what is in the folder it's going to continuously say the student's name and what time they attended it's going to repeat that until they're in the frame but we don't want to do that we want to mark the attendance of a student only one time so that's exactly what we're going to do over here so we want to read the files so we can check if we already wrote down that the student came to class and we want to write the we want to be able to write in the file you know in order to um write down when which student came to class at what time so now what we're going to say is so over here we're actually supposed to say as f and now what we're going to do is we are going to read all of the lines in the we're going to read all of the lines in the attendance.csv file in order to make sure that we already haven't um written down the name of the student that we just detected because again as i said some students just stand near the door where our camera can detect uh the student just to have a quick chit chat with the teacher so we are going to say we're going to create a list so we're going to say my list or my data list is going to be equal to f dot read lines now we have all the lines in my data list now we're going to have a list called name list and now what we're going to do is we're going to write a simple for loop in order to store all the names of all of the students that have already been um all the name of all the students that have already been uh written down on our tenancy so we're going to say 4 line in my data list and then in the for loop we're going to say entry equal to and we only want the name right so what we're going to do is we're going to write some simple code to where we only want the first part of the comma we don't want the second part of the comma so over here we're going to say entry equal to line split dot split and where do we want the line to split up we want the line to split at the comma then we're going to um we're going to write name list dot append and then we're gonna say entry and since we want the first part of the entry or since this line is going to be broken up into two pieces this is the first and this is the second we want the first piece so we're gonna type in zero and again the reason we're typing in zero is because in a list or in many programming languages the first term is actually not referred by the number one instead it's referred by the number zero now since we have all now in this for loop we gather the name of all of the students that have already been written down in the attendance sheet and over here we're gonna see if the student that we're detecting is already in the attendance sheet so we're gonna say if name not in uh nameless so if we haven't written down the name of the student yet we're going to write it down so we're going to say first we need the date and time so we're going to say now equal to date time oh yeah so we also need to uh we also need to import a package that allows us to tell our program or the date and time so we're going to say import date uh i mean from daytime so i'm pretty sure it's from daytime import daytime so from daytime import daytime now since we have that uh package imported what we're going to do is we are basically going to head over here or whatever yeah now we're going to see now is equal to datetime.now and then we're going to say time string so the format is going to be uh so we just want the hours and minutes so we're going to say percentage h com i mean this and then percentage and you can also add seconds but i don't want to and then what we're going to do next is we are going to write that down so we're going to say f dot write lines and then we're going to say um f and then we want this to be in the next line so we're going to say slash in and now we are going to actually that's the wrong slash slash in and we are going to write first of all the name and then comma the time stream now since we have that out of the way what we're going to do next is we so that's all so now if we go now what we're going to do over here is we're going to call that function so we're going to say um attendance mark attendance i think is the name of the function mark attendance i think um you market to learn mark attendance and the name is going to be named now oh no i don't want to exit now if i run this program again so as you can see there's nothing in attendance dot csv and if i run this program i'm going to stay out of the frame so the computer doesn't see me and again i'm going to go back here so let it initialize that should take a second or two um so so it's actually up and running so let's put that in so as you can see it already detected my face because i barely peeked but that's okay so now if i minimize this you can see it has joe shake and yeah we have something wrong so this was the problem i was talking about it's gonna repeat my name for a long time so let's see what i got wrong or what i messed up on so let's go back to the smart attendance system and i'm pretty sure it's something to do with the if condition if name not in name list so i don't see what i did wrong um let's see nameless dot append entry of zero uh so oh i see what i did wrong so can you guys spot out what i did wrong so actually where we went wrong is and again if you think about this this is hilarious so where we actually went wrong is number one um so actually let's run this program again you know just to um oops before we run that let's stop that program let's delete these and now if i run this again oh oh no i'm running the wrong way so if i run this program again you'll be able to see that the problem is that whenever i am being detected which i will be detected in a second i'm pretty sure the program is still being like yeah so it started so as you can see i'm i'm being detected that's perfecto but if i minimize this if i minimize this you can see that i that there are two problems let me pause the program there are two problems number one the date and time is not correct like by no means is the time age hours and minutes and number two i am being registered into class multiple times so we want to avoid that so what are we going to do well here's the problem and this is hilarious number one for the times um the time it's actually a syntax error so we're not just supposed to type timestream equal to this we're supposed to type we're actually supposed to type um now dot str f time and yes this is hilarious so the reason are uh we have myself attending uh being registered in the attendance sheet multiple times is because over here as you can see i gave a space between the slash in and the end yes so isn't that hilarious and i'll tell you why this is bad because as you can see uh because as you can see when i do that the name will not be in the name list because what is my name well the name is joshik so when i detect it it's going to be joshua but how did i write this name in the attendance dot tv well i wrote this name in attendance dot cv as space joe shape so joshua and space joshic aren't the same thing so even the space can throw off the whole um program so what i want you to do is i want you to make sure that there's no space between this and the slasher now if i run this um that should be fixed hopefully fingers crossed so if we um if we wait for some time again the reason this is slow because is because well it's a lot of code and you need to give it some time to compile so as you can see my face has been detected and i'm staying on the computer for a long time so if i now minimize voila i've been only registered one time and as you can see it says 1916 and the reason it says 19 is because um python follows the 24 hour clock so instead of the 12 hours so if you subtract 12 from 19 it's 7 so 7 16 pm yes finally we got it and um we are also going to um i'm also going to do a demo with the other two mark zuckerberg and um mark zuckerberg and elon musk but before we do that we're just going to write one more bonus code once so what this is basically going to do is this is going to greet the students whenever they come into the class so it's going to say welcome to class in the students name so this is actually really easy this basically takes any time so what we're going to do is we're going to say we're going to have to download a library so we're going to go to file settings and then we are going to so the package we're going to download is pi t oh oh no i meant so you go over here you go to project you go to python interpreter and then you click on the plus and now the uh the package we have to [Music] download saying text to speech so yeah the text speech library for python two and three so you're gonna have to download this i already have this package downloaded so um i'm not gonna do it and if you want to check if you have this package downloaded you have to come over here and under the package you have to check if it's downloaded and you can see it says pytt sx3 so let's import that package we're going to say import p y yeah and now this since this is hard to type we're going to say text speech text speech now again as i said this is really easy number one we have to declare the text-to-speech um let's text speech library through a variable so we're gonna say engine is going to be equal to well text to speech dot in it now we're going to go to a mark attendance and under the if condition over here what we're going to do is we're going to write number one we are going to say engine.same so engine dot say and then inside here we are going to write what it's supposed to say so it's going to say welcome welcome to class and then plus the name of the student which is just going to be named and then to end this off we're going to say engine dot run and wait run and wait so now what i'm going to do is i'm going to go to attendance.csv i'm going to delete this and then the next thing i'm going to do is i'm going to run this program so it should work when i run this program so what it's willing to do is whenever it detects me or elon musk or mark zuckerberg the program should say welcome to class my name or the other mark zuckerberg or elon musk's name so if we run the program um if we run the program it should pop up any second now so i'm actually going to make my camera blank so um because like the frame so as you can see my camera is blank now if i unblank it welcome to class j o s h i k so d do you see how it says welcome to class but then it kind of spells out my name which is kind of awkward yeah i know so let's try that again with elon musk welcome to class elon musk so um for some reason it says elon musk's name but for my name for some reason it just spells out my name maybe um touch just maybe that's just something that happens sometimes because i've run this program one more time before and this didn't happen so we don't want that to happen we don't even want to change take a chance because that just sounds awkward so what we're going to do is we're going to say statement state mint is going to be equal to sdr of well it's going to say so we're going gonna copy down this so control x and control v and now over here we're gonna type in statement now if i delete this oh no that's the wrong one so attendance.csv i delete this let me actually get out all of these out of the way because they're kind of distracting now if i run this it should say welcome to class and my name not j-o-s-h-i-k so any second now so as you can see i have uh i have now if i unblank it welcome to class g-o-s-h-i-k so for some reason it still says my name as j-o-s-h-i-k but that should be fine just with um uh just as some time passes it should work whereas if i come in and show up march zuckerbergs welcome to class mark zuckerberg yeah um i mean this is a python library we can't expect that much can we welcome to class elon musk so there there's kind of a bit of a lag but again that's because i have a lot of things running on my laptop currently so as you can see i have a lot of things running on my laptop and again um if you run this program a couple of times if the josh hik thing should pass because yeah i i run i run this sometimes and it passed away so you don't have to worry about that but that is how we make an automatic and smart attendance system using face detection guys again thank you for watching until the end i hope you learned some a thing or two about python and opencv again thank you for watching until the end don't forget to like and subscribe this video if you liked my explanation and press on the bell icon for more python videos like these if you have any questions feel free to comment them down below and if you have any corrections or any um recommendations also please feel free to comment them down below again thank you for watching have a nice day see you bye
Info
Channel: LearnFromBasics
Views: 60,395
Rating: undefined out of 5
Keywords: face recogniton, python projects, python projects for beginerrs, automatic attendance system for teachers, opnecv projects for kids, opencv projects, learnFromBasics, basic python project, opencv, opencv attendance system, python face recognition attendance system, how to do face recognition with tensor flow and python, how to perform face detection with python and opencv, how does face detection work, coding projects for beginners, LearnFromBasics, easy python projects, python easy
Id: vHuM6hkHMxE
Channel Id: undefined
Length: 102min 46sec (6166 seconds)
Published: Wed Mar 24 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.