Facial Recognition on Video with Python
HTML-код
- Опубликовано: 6 июл 2024
- Neural Networks from Scratch: nnfs.io
Face Recognition package tutorial (part 1): pythonprogramming.net/facial-...
Channel membership: / @sentdex
Discord: / discord
Support the content: pythonprogramming.net/support...
Twitter: / sentdex
Instagram: / sentdex
Facebook: / pythonprogramming.net
Twitch: / sentdex
#python #facialrecognition #tutorial
just thinking about how many things you have taught me is amazing. i am so grateful you can't even imagine. thanks a lot 🙏🏻
Really awesome tutorial @sentdex. What frame rate are you getting on facial recognition?
Please please please make a part 3! This was soo enjoyable to watch and I learned a lot! I'm definitely going to make a few projects surrounding this.
Hey Sentdex! Thanks for making facial recognition clear and accessible for a noob like me! Normally I just drown in the jargon and never see the end of it. I tried your code and it works just fine, except my machine specs make it really slow. Do you use a GPU for your facial recognition tutorials? If so which one?
Hi. I am trying to do the same on raspberrypi . After training, on guessing part, throw the error of low memory. I am using 2 GB ram raspberrypi and also checked personally checking the ram usage during run.
Can you suggest me something for the raspberrypi. To get the same results.
Nice Video! Do you have any plans about making a custom object detection neural network? (Like the ones with live bounding boxes)
Hello! This is really helpful! Thank you! Im not very good at programming and the teacher had us to make a face recognition program as the last assignment so I'm clueless on many things! I would like to use this tutorial to start my assignment but we are not allowed to use any machine learning package/module and we cannot use any built-in/ready to use linear regression functions. So I more lost than ever of how to start. Do you have any advice? We have to use an algorithm and not sure how to implement it on python.
Is it possible to improve the performance of face recognition in live stream? My thought was to capture frames and process them in different threads, but I didn't manage to gain any improvement by doing that.
Exactly what I was looking for ... a while ago.
Thanks dude
Thank you for this amazing face recognition tutorial. It helped me a lot. How to fasten the live feed, it seems my video is lag? What are the computer specs needed in running this face recognition sir?
The mergin can be done at the same time? Or doing it with threading?
After writing the line for encodings, I am getting the error "UnpicklingError: invalid load key, '\xff'" any advice?
Hi I'm using Jupyter Lab on my headless Raspberry Pi and have been trying to stream the csi camera into a notebook with ipywidgets and am having no luck. Can you offer any advice?
Thanks
is it possible to save the video with captured faces, INCLUDING the audio line?
Sweet video :) any recommendations for libraries for something like object recognition?
Sentdex,Your teaching method is really unique than others.
14:40 Not sure if thats the same issue but I was encountering the forward slash problem in your Cats vs. Dogs CNN tutorial as well. The fix was passing in the filepath/name as a raw string (i.e. DOGS = r"bla\bla\dogs"). Afaik it just ignores the associated functions of back/forwardslash inside the string.
Just in case if some one didn't notice, in the cv2.putText match is a int, so you have to str(match)
cv2.putText(image, str(match), (face_location[3] + 10, face_location[2] + 15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200), FONT_THICKNESS)
can you do one dealing with low resouces like trying to do this on jetson nano it crawls to a stop and start process
two questions for you (if I may). Do you think FACIAL RECOGNITION is ready to provide a one step verification for login and payment for a Banking app or similar (the backend could be doing several things at once, but the UX would consist of a user taking a "realtime" photo/video?
And lastly, is "skin texture analysis for face recognition".a game changer?
Be nice to start a conversation, if your willing...
Nice content, I really want to try this. You make me love python much much more. Thanks
Absolutely, add more logic in the third video.
I do like the idea of adding more logic to increase robustness. However, I'm curious if the input source is a video camera, how can we ensure that the encoding is robust enough to handle variations in pose, lighting, and a person's distance from the source, while still maintaining a consistent, smooth frame rate?
Preprocessing the image. Like use some image filter i guess
@sentdex I would like to say when I implemented the same code on my System reading webcam feed, its output time is exceeding like 45secs, meaning its taking around 45 sec to process one image captured from live feed, any suggestion, I have used like 15 single person images in KNOWN_FACES_DIR.
Same thing for me.
Did you find a solution to read more faster the video? Please
I can't get this to work. After running it, I get:
QObject::moveToThread: Current thread (0x9663790) is not the object's thread (0x8fc73d0).
Cannot move to target thread (0x9663790)
Segmentation fault (core dumped)
There seems to be a problem with cv2 and dlib; I'm running Kubuntu. How would you write this if you used pillow instead of cv2?
Is there anyway to use multicore? I think it doesnt even use 100% on one core but I don't know why, I've been searching without luck. And can't use Cuda bc I have an AMD card.
Yes, will be nice to learn how to merge multiple facial IDs of the same face/person into one and prevent identity proliferation. Thanks as always for offering these great tutorials. Best wishes
Hi, when the code runs again it gives "PermissionError: [Errno 13] Permission denied: 'known_faces/0'", as the folders already exists, if i delete the folders, it works fine.
would you please help to resolve this error ?
Why does you profile picture get more pixelated every time?
Could you do a video on how to integrate this with an application? maybe a mobile app? Thanks!
Is there a folder i can download that is ready to use- ie plug and play?
Hey I just wanna know that how do i classify wheather this facial detection can be taken from video or other mobile
Hi Sentdex ! Great tutorial.
I'm wondering if we can add a function allowing the algorithm to say "Hi" to a person in the Camera when it recognizes him or tells him to register otherwise without infinite looping ?
I tried to integrate it in the loop but it kept repeating "Hi" non stop
Can't you end the loop when it says hi the first time?
Out of curiosity which phone do you own?🤔🤔🤔
Great and to the point video.
Can't wait for part 3
Sorry for asking this without really watching this or the previous videos (I will) but how does does it recognize a face? Does a cnn just learn on images of the same face to recognize it or does it find keypoints (ie eyes nose mouth) and matches the distances of different face parts?
Basically with every network you 1.) feed it labelled training data (e.g. obama1.jpg = obama, trump1.jpg = trump etc.) and 2.) test the network by providing untrained data. The goal is for the network to correctly predict the label of the input, based on previous observations (training). It is hard to tell whether the NN finds keypoints or recognizes the whole face even, because of the black box problem. I haven't watched the previous videos in this particular series either, but I am assuming that the CNN tries to detect common features, and attributes them a label (e.g. facial features of obama (features) = obama (ouput)).
Its important to remember that NNs are not sentient, as in they don't know what a face is, neither a nose or any other facial feature. They can merely (better than humans) derive from a lot of data, common and underlying features.
Marc Galitski ah okay, so normal cnn prediction. But good that you are mentioned it: Even though it’s a black box problem, you can plot the feature maps and see which are responsible for detecting which feature (as you probably know). I did it today the first time and it’s so fascinating to see the feature maps in which only the eyes or nose or hair are highlighted. So actually it’s not a total black box
@sentdex, Please HELP! Running into the following issue when running this code (bummer). Thanks in advance. Stackoverflow also documents this issue. (To be sure, my filename is NOT face_recognition.py)
AttributeError: module 'face_recognition' has no attribute 'load_image_file'
I correctly installed all dependencies including Dlib and Cmake and verified via pip freeze. Win64, Python 3.8.
When is part 3 coming?
Is it possible to place a webcam on your door that recognise the person at the doorstep, and then changes the door bell sound to say something like "John is at the door" ? would be kinda cool
Respect+=1
You could try to do that, just find a host for your code, so you don’t have to leave it running every time you leave your house.
Good work, is it possible to add the id/name of the person onto the video stream ? Also how could you open a live feed from a ip camera with a url rather than a file? Thanks
Yes. For adding the name in the video stream just rename the subfolders with the known faces accordingly. To open a live feed from an ip camera, just include the url and the port number like this:
video = cv2.VideoCapture("192.168.xxxx.xx:8080/video")
Obviously, replace the url and the port number with your individual numbers. Note that the ip camera has to be in the same network than your processing machine.
Can we place more than one picture of a person in known face directory liking keeping obama picture there as well so it can also recognize that during the video? thankyou
its lagging a lot on my pc, but is a strong machine, maybe can be the video card?
is it possible to do this live? like from camera
I get the following error "FileNotFoundError: [WinError 3] The system cannot find the path specified: 'known_faces'
- Line 20 in module for name in os.listdir(KNOWN_FACES_DIR)
I have the "Known_faces" folder in the same director as the face_rec_example.py..Im using windows 10.
Give the full file path (instead of relative path) and see if that helps.
Hi
I tried to remake this programm that you show, but it turns out that when I put my video file in the programm, it takes it 40 - 45 seconds per frame!
So I wanted to ask you what are your pc performances
Ps.: My pc is a 3 year old 8 GB machine and I am using Linux Mint
Is there anything I can do or is it just about the machine
Great vid! =D
Can you show how we can do the merge on the encodings for the same face with multiple IDs?
thank you very much for the video it taught me a lot, I just need the details of the configuration of the pc because for the cnn model it bugs it is around 1image / 20 sec, I have an intel 8th generation 8gb ram I5, es ce that will solve the problem if I increase the ram to 16 gb? or help me to find another solution please
no it does not i have intel i7 with 16gb but sill it gives around 8frame/sec which is pretty bad i think cnn need more gpu
10th gen and 2gb inbuild graphic
Is the code fort this tutorial available?
Wonderful tutorial. I am one of your fan from Sri Lanka. Please make part 03.
I've been at this for days and can't make it work. I started with the first video using pictures and couldn't get that to work either. I run into the same problem on both. This is the error I get:
Traceback (most recent call last):
File "video_recog_ex.py", line 36, in
results = face_recognition.compare_faces(known_faces, face_encoding, TOLERANCE)
File "C:\Users\Rick\AppData\Local\Programs\Python\Python36\lib\site-packages\face_recognition\api.py", line 226, in compare_faces
return list(face_distance(known_face_encodings, face_encoding_to_check)
Not working proper windows, what config do we need for Linux?
Can someone tell me what is the accuracy of cnn model used here?
Man you are just awesome !
Can you make a project on -> like the video is being captured through the laptop webcam and then the image captured through the webcam is matched with the current image data set for real time facial recognition. Great Video !!
Best teacher very useful video thank Pro
We need to read expressions from photo or video or live cam and writ expression name on photo
Thanks for you alot
Gracias muy buen video, saludos desde Perú 🇵🇪
Love your videos! Please make a third video on this :)
part 3 seems very interesting. Please do it
amazing ....thank you very much
Your tutorials are great.
Can you make series on building systems like amazon go?
Please continue,the series of face_recognition library
How do we speed up the video so that we can get at least 30 fps with the HOG (or other detectors such as YOLOv3)? Without a GPU*
Use a smaller resolution.
@@sentdex Also, I've been using the face_recognition module for a while and it supports a KNN classifier (you give it a folder containing many pics from the same person and that may improve the accuracy of the recognition). Anyway, I'm a CS student and you've been helping me a lot since last year. Thank you so much!! Cheers from Brazil xD
Please do a part 3!!!
Where can I find the final code?
Can you make video tutorials on docker?
Does this code work on Windows too?
where is the part 3?
It's more than a year and still no part 3 :(
so interesting! thanks a lot~
definitely PArt II should be you doing that!
Can this code run in raspberry pi with pi camera
there is 2024 model that is good?
I don't know what I'm doing wrong but my program lags out like crazy even with just one image.
Yeah part 3 please !
How can we increase the FPS of a webcam ?
Thank you so much
For your previous video you could have used:
if results.count(True) >= 3
to increase accuracy (reduce false negatives).
PS: I am assuming you are using four photos for identity (1 less than the number of identity photos).
PS: all my knowledge in Python is a result of daily sentdex dose, thanks for sharing such valuable knowledge.
Hello! I'm getting an error when running this....
Traceback (most recent call last):
File "facial.py", line 39, in
encoding = face_recognition.face_encodings(image)[0]
IndexError: list index out of range
Trying to figure it out so far, but no luck....
You are probably not finding any matches, or you have to many pictures in your known faces
Your laugh is pretty good 😄
Are you planning to make a video on deepfakes competetion?
Some of the participants are using face detection.
permission to learn sir. thanks you
can I have the link to code please?
2:54 Yup..your assumption is right. It does convert the image to grayscale by default even if you don't mention it explicitly.
this is so extraordinary
I salute you for that thumbnail
Salute the YT thumbnail picking algorithm lol. I usually just go with whatever it chooses, and ... it chose well yet again :)
also ask kite for meney if ur going to pro;ote them like that.
This work if you do it with images ?
We did it with images in the previous tutorial: pythonprogramming.net/facial-recognition-python/
Can't open camera by index
Error dude 👆
May i know why the code doesn't activate my live webcam? video =cv2.VideoCapture(2)
try video = cv2.VideoCapture(0)
That's fascinating and terrifying haha
y u no arch ?
Hi, the face_recognition module can't work. It ask to install dlib first but dlib can't be installed too.
@Arihant Debnath I first started using this module on Windows a year ago and it actually works, but you're gonna have problems. After I switched to Linux my problems were gone.
@Arihant Debnath it worked for me just install cmake and then dlib
@@abhishekdutt1996 dlib can't be installed, although I have already installed cmake.
Okay! How I install dlib and face-recognition. I think, why VS (visual studio)? I use VS 2017 community. VS '17 is for installing Cmake c++ library nothing much!!
I type in the Pycharm's terminal 'pip install dlib', then my pc hanged out for 5 minutes. I got afraid! Then after 20 minutes, I see the successful message. Then just type 'pip install face-recognition' and boom!!
Note : I installed cmake!
Incase you couldnt find a solution just download visual studio for c++ install then run
Pip install cmake
Pip install dlib
It should work
i'm really into this facial stuff thanks,, but i had a problems with the first video when i inserted a lot of faces into the KNOWN_FACES and i categorized them into 2 people. but it didn't work, idlk is it a bug from the library or my foult. so please consider putting a lot of known people and known faces into the thoughts of the next video♥
When restarting the application after it has learned a few faces I get the below error when it recognizes the first face it finds.
Loading known faces...
Processing unknown faces...
, found 1 face(s)
- 0 from [True, False, False, True, False, False, False, False, False, False, False]
Traceback (most recent call last):
File "facerec-webcam-v3.py", line 63, in
cv2.putText(image, match, (face_location[3]+10, face_location[2]+15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200))
SystemError: returned NULL without setting an error
Anyone know how to fix this? I only get this error when I restart the application with known faces in my directory. when I change the "match" variable to the filename it seems works ok but it does not get the correct name when it's displayed.
Found the issue! you need to make it an Str
cv2.putText(image, str(match), (face_location[3]+10, face_location[2]+15), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (200, 200, 200))
any idea how to install CV2 AND OS, ? I cant , I did try, I m working on python 3.7.6 and pycharm
pycharm version 2019.3., I cnt find the installers of cv2 nor os ON PYCHARM? any idea how to install? Harrison
@@py_tok5589 pip install opencv -python
thanks man :)
Waiting for the 3rd video 🤞
great content
can u update the code to say the face name with text to speech code when it detect it
What makes coding fun is doing it yourself! You can copy+paste the code and search on google for your specific problem and then try to implement it.