Face Recognition Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys today we will be doing something really cool we will code facial recognition and we will use python opencv and trained ai model that we get from opencv and in the end we will have something like this now the picture or the webcam is lacking a little bit because i'm screen recording but if you do this on your own computer you will see that this is really smooth okay let's let's get started [Music] now this is the project that i just used to um to show you the the webcam stream what we will do we will create a brand new project so you will know what we do what you have to do from the beginning to make this work and we will call it facial recognition and as interpreter i will use a environment i called tensor which is pretty that's pretty much everything in it that is needed now okay let's delete what's in main.p.i we don't need that stuff and what we can do first in arch settings i check if opencv is installed in this environment here we go opencv so we are good to go now in case in your environment opencv is not installed what you have to do is you open the terminal check that you are in the right environment that you want to use and you type pip install opencv python which will install the python environment or the python library into your environment no that's what i wanted to say okay now we don't have to do this because we already did this if you don't know how to set up python environment i recommend i recommend you i recommend you to watch one of my previous videos which is linked in the description okay let's continue with this video and first thing we do is we import um we import the opencv library and now what we want to do first we want to get a hold on our [Music] video or webcam stream so what we do is video capture we now in my case i have two webcams connected so i can select zero or one depending on which webcam i wanna use in this case i use webcam one [Music] and take this and now i have a stream or i have a connection to my to my webcam let's call it this way and what i want to do is i want to read from this webcam so i do red frame [Music] read this is all i gotta do to get the frames that are being captured by the webcam [Music] and the next thing [Music] i want to do is i want to show that frame in in a window so we will call it webcam and the next thing is we will tell image show which picture to show and what's also important we have to say we have to make it able to quit the window because we have a while loop here we have to tell when we want to exit this while blue and in our case we want to exit the while loop if we press q and we'll check every second if q is pressed okay now and then what we do at the end of the program we release our connection to the webcam so other software can make a connection to it and we also say we wanna destroy all windows that are open okay now let's check what we got so far uh let me check edit configuration is everything set up correctly okay main is using python integrator with the tensor environment that looks good so let's see what happens if we start this program okay that looks good hey now this is a webcam stream uh it's not doing facial recognition so far but at least we got a webcam stream i like that [Music] now let's start it again let's okay so my face is on because we want to do facial recognition now the next thing we want to do is this is not really needed but i'm showing you this that you can make the video a little bit larger or the resolution so here we can say prop frame hey in frame width and as frame width we want to use 1080 and frame height we will use 1920 and then we can start program again and we'll see better resolution now i don't know why this is happening but the images get rotated by 90 degrees when i use this higher resolution so what i usually do i just flip the frame after reading it although i really have to tell you i have absolutely no idea why this is happening so in case someone knows please let me know what we do to solve this issue we rotate the frame that we receive from our webcam by 90 degrees and here we go got a good resolution with a with the right um alignment so i like that okay now what i also usually do now i cannot test this but i show you this if not cap is open like if like in case um the camera is being blocked by some other software you don't get access to it and you want to tell the user that you're not able to open the camera and exit the program [Music] and another thing that i also want to do is in this while loop i want to tell if i'm not able like let's put it here i'm not able to read the frame then i want to print to the user can't access or can receive anything any frames from the webcam like we are connected to the webcam but we don't receive any frames so we also want to break here because if we did not receive a frame then we don't have to to show it or do anything with it that would probably result in an error so that's why we do this here okay now now comes the interesting part now what i did or what you have to do go to opencv and open github or go to the github repository of opencv and here we have data now here is where opencv is storing some of their trained ai models and here we have our heart cascades model and here you can see there are a lot of models like you also got a model for eye detection a lot of models for frontal face detection a model for full body detection left eye right eye russian blade number uh okay that sounds interesting uh other party smile like you could probably pretty much um develop snapchat with this which is always asking smile and then you get a get a filter maybe we'll do that in another video but what i used you can try some other models but what i use for my example is this one and this one worked pretty good although it's has changed was seven years ago now um no i don't know oh god that's too stupid to download this file let's download it dirty version a dirty way let's go in raw and just press ctrl a to select all control c to copy everything and then create here file let's call it arcs gate frontal face deformed xml and paste it in here now we got 33 000 lines of a trained ai model which is capable of [Music] detecting a face and what we want to do in our code the first thing we want to do we want to look that model okay so let's um load this cascade classifier let's see if pycharm is smart enough no i have to type this okay let's hope i'll make any spelling errors now we did load our faces model and the next thing we do is we want to define a method which we would call face recognition and we can pass any image to this model add to this method and the method will then return the image with some green green boxes around the faces or at least where it thinks there are faces now most ai algorithms don't care about at least the picture ai algorithms don't care about colors in fact it's easier for them to work with gray images so the first thing you usually do is you convert the color image from red green blue color usually to a gray image now we do this with cbt color [Music] and as source we enter the image and say we wanna see the color um blue green red to create yeah we will use this and then we will get a gray image uh we can start this just so you see where we are at the moment return tray image and then down here we say before we show the image we say frame equals face recognition frame now what we should see here when we start the code is we should see the image in gray yeah now the next step is we want these green box around my face so we have to keep on working on this face recognition method now thanks to our phases model from opencv what we can do is we can read the coordinates of the faces that are found faces coordinates equals basis model detect multiscale and we will enter the gray image and now um now we got the coordinates where all our faces are and let me sing if i make an example or [Music] now let's just let's just continue and then for index and faces coordinate according in enumerate phase coordinates now we go through all the phase coordinates because sometimes it finds more than only one only one and phase that case we want to make a box around all the faces and not only around one face and we say x y with an a equals phase coordinate index now we will read x y with nate of the first phase coordinate now you if you're good or if you're decent in algebra you should know what x and y is um so if not i will tell a little bit about when we start to call software the next time now what we do we use opencv to draw a rectangle so as source we say image and we start our rectangle at x y and the size of the rectangle is x and y plus h so that's pretty much the the end of the rectangle yeah you can you can put it at now i got some error let me check yes okay because because the color is also missing now we use 0 255 0 which stands for cream you can test around some other colors later on and that should be pretty much it okay now let's start the code oh okay guys i found the arrow of course i should not read from face coordinates i should read from face coordinate and basically i think which also should work like this and then okay this can stay the way it was and here we will return the image and let's see if this is working okay looks pretty good now it is detecting too many faces but i still like that and what i wanted to tell you know the coordinates i get is here um the coordinates i get here when i make this is i get x which is this here and y like this is the x line this is the y line and this tells me x y and this is the width of my face and height and so i decide to draw a rectangle which starts at x y and ends at x x y plus width and 8 now what we could do is we could change the color i don't know what color is what but i'm pretty sure that this will change and let's quit this first start again [Music] yeah now we got blue and we can also change the thickness so if we want to make a really thick line [Music] then we can just make 25 okay i like that now what you can do for practice you can play around a little bit with with these algorithms here from github from opencv it's probably pretty interesting and write in the comments which one you like most to be honest i have not tried any one of these besides the default one which we just tried and which was working but i'd be interested in knowing what's what the other ones do [Music] okay so [Music] so i hope you enjoyed this video and please follow us for more and if you like this yeah leave a comment or or give us a thumbs up we really love that so see you next time
Info
Channel: LumaBIT
Views: 109
Rating: undefined out of 5
Keywords: ai, face recognition, artificial intelligence, opencv, facial recognition, python, deep learning, face recognition python, face detection, face recognition python opencv, computer vision, face detection python, python face recognition, face recognition with python, opencv python tutorial, machine learning, face recognition using python, opencv tutorial, opencv face recognition, opencv python
Id: xOG48JcqY5k
Channel Id: undefined
Length: 20min 24sec (1224 seconds)
Published: Mon Feb 01 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.