well, after countless videos, online "courses" and other resources, yours is spot on. i've been able to implement your approach in my project. i'm working with multi-threading so that works faster. (i'm too lazy for the GPU opencv module build). Keep up the good work!
if someone have trouble install dependencies like cmake or dlib u can install manually also i need to thank sturkmen he found if u use different webcam/cam include a external webcam u will get the following error; CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(unsupported media type) the solution clearly could be video_capture = cv2.VideoCapture(0,cv2.CAP_DSHOW) at least in my case works thanks bruno nice work buddy
@@ujjwaalbhardwaj8355 Hi, so the module has an attribute of load_image_file, please check that the module is correctly instaled and passed on the head section to import it
Hi, the script that is here is set to take the frame of the camera as soon as it finish checking for faces, so one option is to make your machine faster or using a GPU another thing that it will make it faster is reducing the image size, but this will reduce the accuracy recognition
The lag is becasue the computer takes a frame, then analyses the frame and then gram the next one, one option is to reduce de size of the frame, another one is to have more computing power. Warning: Reducing the size of the frame will reduce the quality for recognition
Hi, this function video_capture.read() only takes the next frame of the video and then you can search for faces, docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-read to increase the fps analysis you can resize the image for faster analysis to a 1/4 of the image, small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=resize#cv2.resize
I have given multiple images as input but the code is able to detecf only one face and rest all are shown as unknown. Do you have any solution where i can increase the accuracy so that it can detect atleast 3-4 faces?
Hi, you can use this for many faces, but you need to pass each face encodign into the array of known_face_encodings and the corresponding name into the array known_face_names so it will work with multiple people
Hey Mate, thanks for the guide,! Ive been looking into a way to detect my specific face in a webcam feed compared to others and this one hit the nail on the head. I need to look into how to enable GPU for facial recognition / dlib because it was running very slow, even thought my cpu wasent being used much. Might need to compile dlib with cuda enabled or something from what a quick Google mentions.
i used this code and commented out the image lines (7-11) and it work fine giving me "unknown" as the name. recently i tried to add my own pictures but got "IndexError: list index out of range" error. Now i get this error even when going back to the modified code. Would you know what is causing this.
please chek which line is giving you The error, and try checking the value of that variable list to sre what is happening, most probably is that the list is empty for some reason and that's why it does have any index and it returns the error of not found
@@brunocen I fixed it. The problem was that Visual Studio Code did not have access to my camera and would not request for it. So I had to run it from my terminal "sudo code" and the run the program.
Hello Sir, when I try to run the code : I get an error message saying : IdentationError : unindent does not match any outer identation level, any solutions ?
check your spaces, remember that python uses 4 spaces or a TAB, you can change this for 2 spaces, but make sure they are all the same. The error should have a line error, go to that line and check the number of blank spaces that are there
this code would place all know and unknown faces in red box, you should make only known faces in green box and unknown in red..and if i am not mistaken u hardcoded your name. The code sould read the name from the photo and displayed it in the box...but other than that nice one
Hello Anne, yes on the video I download the libraries that you need, using the command "pip install" and the names of the libraries check the video for more detail
vscode keep telling it cant find the module face_recognition, i tired everything, installing cmake,dlib and more stuff online, im on a mac bytheway, someone can help?
that's why its important to install the virtual environment so you can work on an entire new and separated enverioment, but even if you are not working on a venv you should be able to see the python modules installed with "pip list" if you don't see the module then use "pip install"+ the module " then do "pip list" again and you should see the new installed module, if you don't see it then you might be using a different path or a different python to install and run the modules
wait for some time. it may take 10-15 minutes. first install cmake - pip install cmake and then install face_recogntion : ignore if you already have cmake. or you can uninstall cmake and then reinstall cmake and face_recognition. hope this helps;)
Hello Mr. Centeno! I keep gettign an error saying: "ModuleNotFoundError: No module named 'numpy'". I searched this problem up on stack overflow and across the internet and everyoen says to uninstall and reinstall numpy. I tried this multiple times and then restarted my VS code. Do u have any solution to this issue?
please run "pip list" it will show you a list of your packages, if you dont see numpy in the list then you need to install it "pip install numpy", also make sure you are using the right environment, I use a new virtual environment for each project. Create a new one and install the packages that you need for that project only.
Hi seems like you didn't install the module, remember to follow the steps of "pip install face_recognition" and all the other pip installs that I used in the first part of the video
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases... how to solve this bro
I used the build-in camera, if you want to use an external camera you can just select the default camera to be the external and then you would be able to use that one. And actually any camera could be the source of your video, just check that the script is taking the frame from that video
out of index happens when you are accessing an array and the index you are using is greater than the array top index. In the code this might be because you are missing a [0]. Most arrays come inside another one with a smaller index number. Check your code for a missing [0]
That was mind blowing sir!! And if I want to make that like if it detects unrecognised face It should raise an alert message!! Any suggestions from you sir?
well just use a the lib request to send a POST to any endpoint in another system, its an API call, it can have any information on the body, like who else is in the picture with the unknown face
Hi @Bruno Centeno I was using pip to install face-recognition and I am not able to download it. I am currently using python 3.9 is there any other way I can do it. please help!
@@dishantisrani2609 You can do it there, the code editor is not a problem, you can use anyone you prefer, pycharm, atom, sublime2 or any other you like
yes, its the same code, but instead of grabing the frame from the computer camera you would need to set up the ip camera feed to grab the frame from there
Hi, here's an example of how to create a window with the size that you want and then populate it with the image that you want answers.opencv.org/question/84985/resizing-the-output-window-of-imshow-function/
the algorithm is not perfect it was trained over thousands of faces and its retrained on your photo, but you can also change the settings to be more strict if you need it, there is a threshold of the match that you can change. Like match only if they are really similar, or match if they kind of look alike.
I think yes, First you need to give permissions for the browser to use the camera, Second install dependencies (pip install) Third I think you can upload the picture (bruno.jpg) into the colab folder, but if not, you can pass a link from a google drive
@@Majesthc_ well for example you can create an array with the names of the images that you want to pass and then do a for loop to extract each image something like assuming files is an array of names of the images for file in files: #here is the code for open the image and append it to the array of known faces (same as the video)
For now its the best it can get, cause it needs to analyze the frame fro the faces and match them, and then grab another frame, so that's why it looks slow, but for now I dont know how to improve that, sorry about that
you can use any code editor you want, if you dont have visual code you can use "sublime text 2" is much more simple to use, and the face_recognition module is installed via pip, its explained on the video
seems like a recent deploy of vscode is not asking permission to use the camera and it get stuck so thats why it aborts. Try running it from the macbook shell
Please install `face_recognition_models` with this command before using `face_recognition`: pip install git+github.com/ageitgey/face_recognition_models Process finished with exit code 0 Pls Help Me I am getting this when I run your code. I installed the models but it is still saying the same thing pls help. Other than that I loved the video...
a python object is not subscriptable if its a container of other object, make sure you grab the frame correctly with the "ret, frame = " stackoverflow.com/questions/216972/what-does-it-mean-if-a-python-object-is-subscriptable-or-not
video_capture = cv2.VideoCapture(1) change the (0) to (1) as shown above sometimes if the default value of camera gets' changed in the laptop mostly so if you are a laptop user this must work
first create an array of the names of the photos then do a loop for the photos for photo in photos: load image face encoding add to known faces array after that you will have a bigger array of known faces
berke_face_encoding = fr.face_encodings(berke_image) hamit_face_encoding = fr.face_encodings(hamit_image) seval_face_encoding = fr.face_encodings(seval_image) furkan_face_encoding = fr.face_encodings(furkan_image) known_face_encondings = [berke_face_encoding,hamit_face_encoding,seval_face_encoding,furkan_face_encoding] known_face_names = ["Berke", "Furkan", "Hamit", "Seval"] I did like that but it gives me this error: File "C:/Users/BERKE/Desktop/PYTHONKLASÖR/FaceDetection/main.py", line 8, in fr.load_image_file() TypeError: load_image_file() missing 1 required positional argument: 'file' [ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
@@Majesthc_ Seems like your error is on the load image, are you passing the name of the file correctly? verify that the image file is in the same folder, or pass the absolut path to the file
well, after countless videos, online "courses" and other resources, yours is spot on.
i've been able to implement your approach in my project.
i'm working with multi-threading so that works faster. (i'm too lazy for the GPU opencv module build).
Keep up the good work!
Amazing I'm glad that you found my video helpfull
if someone have trouble install dependencies like cmake or dlib u can install manually also i need to thank sturkmen he found if u use different webcam/cam include a external webcam u will get the following error;
CvCapture_MSMF::initStream Failed to set mediaType (stream 0, (640x480 @ 30) MFVideoFormat_RGB24(unsupported media type)
the solution clearly could be
video_capture = cv2.VideoCapture(0,cv2.CAP_DSHOW)
at least in my case works
thanks bruno nice work buddy
Thanks for the extra info, hope it works for other people with the same problem
Sir, can you please upload a video of multiple face detecting program with python opencv
i get
module 'face_recognition' has no attribute 'load_image_file'
can you help me fix that?
Can you double check that you wrote correctly the names? This happens very often, if you misspell it then it will say that there is not that attribute
same error for me also
@@ujjwaalbhardwaj8355 Hi, so the module has an attribute of load_image_file, please check that the module is correctly instaled and passed on the head section to import it
I'm getting an error in "source venv/bin/activate" part
what is the error? make sure you created the enviroment with the name venv (there should be a folder with that name
Face detection is slow using face_recognition package...Please suggest me how to improve FPS in Realtime.
Good job Bruno.
What Face REcognition Algorithm did you use in this program?
It's a deep learning model based on the dlib.net/ library
Thank you solved my problem
Excellent!!! I'm glad I was able to help!
Hi Bruno,
It says syntax error at && 0xFF
And it’s not opening the window
it's just one & sorry i made that mistake if you see when i run it I correct that part
is there a way to make the camera faster when running the program? it looks laggy even do my webcam is like 50 fps
and great video man!!
Hi, the script that is here is set to take the frame of the camera as soon as it finish checking for faces, so one option is to make your machine faster or using a GPU another thing that it will make it faster is reducing the image size, but this will reduce the accuracy recognition
Hi, I would like to ask if you know how to get rid the lag when recognizing a person.
The lag is becasue the computer takes a frame, then analyses the frame and then gram the next one, one option is to reduce de size of the frame, another one is to have more computing power. Warning: Reducing the size of the frame will reduce the quality for recognition
How could I expand this program to detecting several faces at once??
What Face Recognition Algorithm did you use in this program? can you please tell me?
It's a deep learning model based on the dlib.net/ library
Nice video! do you know how to improve the fps in the webcam?
Hi, this function video_capture.read() only takes the next frame of the video and then you can search for faces, docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-read
to increase the fps analysis you can resize the image for faster analysis to a 1/4 of the image,
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=resize#cv2.resize
@@brunocen Where should I be putting this code? I can't seem to find a spot to put it that works
@@suspiciouscitrus6815 at the begining of the while loop when you take the read form the webcam
@@brunocen should we replace the ret, frame = video_capture.read() line with the code you have given or add this to the code given in the video.
Please tell
how to find many face with true name ?
I have given multiple images as input but the code is able to detecf only one face and rest all are shown as unknown.
Do you have any solution where i can increase the accuracy so that it can detect atleast 3-4 faces?
Hi, you can use this for many faces, but you need to pass each face encodign into the array of known_face_encodings and the corresponding name into the array known_face_names so it will work with multiple people
It works like a charm! But i need help to add several faces to recognise can you help ?
I have been asked this many times, I definitely need to find the time to make a new video
Hey Mate, thanks for the guide,! Ive been looking into a way to detect my specific face in a webcam feed compared to others and this one hit the nail on the head.
I need to look into how to enable GPU for facial recognition / dlib because it was running very slow, even thought my cpu wasent being used much. Might need to compile dlib with cuda enabled or something from what a quick Google mentions.
yes using a GPU will help get the recognition faster, but you can also reduce the quality of the image, althought you might loose accuracy
hello can you please provide a code of multiple face detection
all the subscribe getting the same issue please make a tutorial on this
yes you are right I will definetly do a multiple face detection, I will prepare the code and the video, I will upload it next week
@@brunocen Hello, I have write down the code of Multiple face detection
@@mayurmoundekar5252 awesome!! that's great
@@brunocen thanks
i used this code and commented out the image lines (7-11) and it work fine giving me "unknown" as the name. recently i tried to add my own pictures but got "IndexError: list index out of range" error. Now i get this error even when going back to the modified code. Would you know what is causing this.
please chek which line is giving you The error, and try checking the value of that variable list to sre what is happening, most probably is that the list is empty for some reason and that's why it does have any index and it returns the error of not found
I got a problem with the font apparently, cant quite seems to get it working but it doesn't matter. Great video man!
thank you, If you got an error with that font try using another one.
When I try to run the program it says zsh: abort. Why does this happen?
zsh is your console comande line seems like you have something wrong with that, try running some simpler commands and see if it still works
@@brunocen I fixed it. The problem was that Visual Studio Code did not have access to my camera and would not request for it. So I had to run it from my terminal "sudo code" and the run the program.
@@spousalhat2721 Awesome I hope that everything is working now smothly
@@spousalhat2721 awesome!!
Hello Sir, when I try to run the code : I get an error message saying : IdentationError : unindent does not match any outer identation level, any solutions ?
check your spaces, remember that python uses 4 spaces or a TAB, you can change this for 2 spaces, but make sure they are all the same. The error should have a line error, go to that line and check the number of blank spaces that are there
@@brunocen Actually It was en error about the spaces, and I had to reinstall dlib library again and it worked, thanks for the help
@@kheir-eddineferhat8420 Awesome!! I'm glad it worked
this code would place all know and unknown faces in red box, you should make only known faces in green box and unknown in red..and if i am not mistaken u hardcoded your name. The code sould read the name from the photo and displayed it in the box...but other than that nice one
You are right, i ddint want to make it more complex than that, but those are good improvements to add, nice catch!! 🙌
Do I have to download libraries for this project?
Hello Anne, yes on the video I download the libraries that you need, using the command "pip install" and the names of the libraries check the video for more detail
vscode keep telling it cant find the module face_recognition, i tired everything, installing cmake,dlib and more stuff online, im on a mac bytheway, someone can help?
that's why its important to install the virtual environment so you can work on an entire new and separated enverioment, but even if you are not working on a venv you should be able to see the python modules installed with "pip list" if you don't see the module then use "pip install"+ the module " then do "pip list" again and you should see the new installed module, if you don't see it then you might be using a different path or a different python to install and run the modules
@Bruno Centeno
if i do: pip3 install face_recognition, it keeps loading on running setup.py install for dlib, how do i fix this?
same
Seems like you dont have dlib installed try installing it learnopencv.com/install-dlib-on-windows/
wait for some time. it may take 10-15 minutes. first install cmake - pip install cmake and then install face_recogntion : ignore if you already have cmake. or you can uninstall cmake and then reinstall cmake and face_recognition. hope this helps;)
Hello Mr. Centeno! I keep gettign an error saying: "ModuleNotFoundError: No module named 'numpy'". I searched this problem up on stack overflow and across the internet and everyoen says to uninstall and reinstall numpy. I tried this multiple times and then restarted my VS code. Do u have any solution to this issue?
please run "pip list" it will show you a list of your packages, if you dont see numpy in the list then you need to install it "pip install numpy", also make sure you are using the right environment, I use a new virtual environment for each project. Create a new one and install the packages that you need for that project only.
@@brunocen Thank you SOOO much it works now!
@@roko6033 excellent!! good work!!
Anyone keep getting the error "ModuleNotFoundError: No module named "face_recognition" and if so, how can this be corrected?
Hi seems like you didn't install the module, remember to follow the steps of "pip install face_recognition" and all the other pip installs that I used in the first part of the video
hi bruno nice one ! please how to add other faces to your program , i tried but it didn't work :(
So we have to add more pictures on the arrays and pass the other face_encodings of the pictures containing the faces
Great tutorial sir 👌. Can you tell me which IDE you use for coding.
Sure i am using VS Code
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App
Execution Aliases... how to solve this bro
Seems like either you havent installed python or you are using a wrong folder to call phyton
Did you use an external webcam or the built-in camera ?
I used the build-in camera, if you want to use an external camera you can just select the default camera to be the external and then you would be able to use that one. And actually any camera could be the source of your video, just check that the script is taking the frame from that video
I get an error in like 8: Index-error list index out of range
out of index happens when you are accessing an array and the index you are using is greater than the array top index. In the code this might be because you are missing a [0]. Most arrays come inside another one with a smaller index number. Check your code for a missing [0]
That was mind blowing sir!! And if I want to make that like if it detects unrecognised face It should raise an alert message!! Any suggestions from you sir?
well just use a the lib request to send a POST to any endpoint in another system, its an API call, it can have any information on the body, like who else is in the picture with the unknown face
Hi @Bruno Centeno I was using pip to install face-recognition and I am not able to download it. I am currently using python 3.9 is there any other way I can do it. please help!
why you can't use pip? is it the dlib error?
@@brunocen I am working on visual studio code ? Will it work there? Or I have to download visual studio ?
@@dishantisrani2609 You can do it there, the code editor is not a problem, you can use anyone you prefer, pycharm, atom, sublime2 or any other you like
I have been trying it from a while but the face_recognition module doesn't gets installed
It always gives me a dlib error if there is someway I can contact you I can share you the error
Thanks!
where did you code
The code editor is Visual Studio Code, the script was run in my local
Can python do, face identification via ip camera?
yes, its the same code, but instead of grabing the frame from the computer camera you would need to set up the ip camera feed to grab the frame from there
hi mr bruno how can i change the video window size
Hi, here's an example of how to create a window with the size that you want and then populate it with the image that you want
answers.opencv.org/question/84985/resizing-the-output-window-of-imshow-function/
had problems with installing the face_recognition
what was the problem? pip install normally works fine
@@brunocen it didnt work for me i ended up using tesseract and opencv and that worked
Bro..It shows same name for different faces.. What problem plzz expalin..
the algorithm is not perfect it was trained over thousands of faces and its retrained on your photo, but you can also change the settings to be more strict if you need it, there is a threshold of the match that you can change. Like match only if they are really similar, or match if they kind of look alike.
rgb_frame = frame[:, :, ::-1] TypeError: 'NoneType' object is not subscriptable how do i fix this
seems like you have a typo, check the code. The typo is creating an non suscriptable object
Love You Bro..
it kept crashing as the webcam starts.
does it print any error?
@@brunocen no
very very thanks for this video can you update it by recognizing many people can you pls make it .
Yes, I will do it, cause a lot of people is asking for it, so I will upload a new one with more faces
thank you
hi, thank a lot for the video, is there a way to make this on colab?
I think yes, First you need to give permissions for the browser to use the camera, Second install dependencies (pip install) Third I think you can upload the picture (bruno.jpg) into the colab folder, but if not, you can pass a link from a google drive
thank you so much ...
how can i test it with dataset of images
The same way I did it, i explained where you can pass more faces and more people, if you want to do it with more images just do a loop on those images
How i can do a for loop for that?Can u write please
Did u make it?Can u show me if u did it
I need it too, I cant figure out what to do here
@@Majesthc_ well for example you can create an array with the names of the images that you want to pass and then do a for loop to extract each image something like
assuming files is an array of names of the images
for file in files:
#here is the code for open the image and append it to the array of known faces (same as the video)
Thank you so much
welcome
Thanks for this tutorial, it works..i had some trouble increasing the fps though even after adding the code. Did anyone figure it out
For now its the best it can get, cause it needs to analyze the frame fro the faces and match them, and then grab another frame, so that's why it looks slow, but for now I dont know how to improve that, sorry about that
decrising the size of the image can make it a little faster but you loose quality of recognition so its a trade off
Can I get algorithm for this code sir...plz
face_recognition library is open source and it's on github, github.com/brunocenteno/face_recognition
Thank u... sir
a very lot thanks bro
I'm glad it was usefull for you
I have an error that says "dlib has no attribute get_frontal_face_detector" in line.
PS: I like your viedeos
I have never seen that error, where is it calling that get_frontal_face_detector ?
Stop that and install the dlib in system
Pip install dlib
then install the wheel also
put video about your openeditors steup and face recognition steup
you can use any code editor you want, if you dont have visual code you can use "sublime text 2" is much more simple to use, and the face_recognition module is installed via pip, its explained on the video
The video was OK, but u kept on making mistakes bro(in the code), u gotta improve.
Well it's not always perfect, but I will try to get better, thanks for the support
It says zsh: abort when I run the code
zsh is the terminal, you probably have an error in your computer, try running a simple script to see if you have any error
seems like a recent deploy of vscode is not asking permission to use the camera and it get stuck so thats why it aborts. Try running it from the macbook shell
Please install `face_recognition_models` with this command before using `face_recognition`:
pip install git+github.com/ageitgey/face_recognition_models
Process finished with exit code 0
Pls Help Me I am getting this when I run your code. I installed the models but it is still saying the same thing pls help. Other than that I loved the video...
Face recognition attendance project check it out
@pKgA
rgb_frame = frame[:, :, ::-1] non-scriptable
a python object is not subscriptable if its a container of other object, make sure you grab the frame correctly with the "ret, frame = " stackoverflow.com/questions/216972/what-does-it-mean-if-a-python-object-is-subscriptable-or-not
Bruno Centeno ok I will look at it again, thanks for the reply
@@brunocen I already had that and I still get the error
video_capture = cv2.VideoCapture(1)
change the (0) to (1) as shown above
sometimes if the default value of camera gets' changed in the laptop mostly
so if you are a laptop user this must work
also check if your webcam is not in use by another app, turn this app off and it will work
How can i do a for loop for multiply images?
first create an array of the names of the photos
then do a loop for the photos
for photo in photos:
load image
face encoding
add to known faces array
after that you will have a bigger array of known faces
@@brunocen
photos = ["Berke.jpg","Furkan.jpg","Hamit.jpg","Seval.jpg"]
fr.load_image_file()
berke_image = fr.load_image_file("Berke.jpg")
hamit_image = fr.load_image_file("Hamit.jpg")
seval_image = fr.load_image_file("Seval.jpg")
furkan_image = fr.load_image_file("Furkan.jpg")
for photo in photos:
berke_face_encoding = fr.face_encodings(berke_image)
hamit_face_encoding = fr.face_encodings(hamit_image)
seval_face_encoding = fr.face_encodings(seval_image)
furkan_face_encoding = fr.face_encodings(furkan_image)
known_face_encondings = [berke_face_encoding,hamit_face_encoding,seval_face_encoding,furkan_face_encoding]
known_face_names = ["Berke", "Furkan", "Hamit", "Seval"]
I did like that but it gives me this error:
File "C:/Users/BERKE/Desktop/PYTHONKLASÖR/FaceDetection/main.py", line 8, in
fr.load_image_file()
TypeError: load_image_file() missing 1 required positional argument: 'file'
[ WARN:0] global C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-k8sx3e60\opencv\modules\videoio\src\cap_msmf.cpp (435) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback
@@Majesthc_ Seems like your error is on the load image, are you passing the name of the file correctly? verify that the image file is in the same folder, or pass the absolut path to the file