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

Комментарии • 218

  • @Hackopat1
    @Hackopat1 4 года назад +9

    just thinking about how many things you have taught me is amazing. i am so grateful you can't even imagine. thanks a lot 🙏🏻

  • @Augmented_AI
    @Augmented_AI 3 года назад

    Really awesome tutorial @sentdex. What frame rate are you getting on facial recognition?

  • @VerresInvictus
    @VerresInvictus 4 года назад +9

    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.

  • @mindml3895
    @mindml3895 4 года назад +1

    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?

  • @prashantjain983
    @prashantjain983 4 года назад +2

    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.

  • @YasaswiS
    @YasaswiS 4 года назад +1

    Nice Video! Do you have any plans about making a custom object detection neural network? (Like the ones with live bounding boxes)

  • @Sirfrigth
    @Sirfrigth 4 года назад

    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.

  • @sergiuszzalewski1947
    @sergiuszzalewski1947 4 года назад

    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.

  • @user-od6re6gk4p
    @user-od6re6gk4p 4 года назад

    Exactly what I was looking for ... a while ago.
    Thanks dude

  • @entertainvideo
    @entertainvideo 3 года назад

    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?

  • @lautarodapin
    @lautarodapin 4 года назад

    The mergin can be done at the same time? Or doing it with threading?

  • @leestons
    @leestons 4 года назад +1

    After writing the line for encodings, I am getting the error "UnpicklingError: invalid load key, '\xff'" any advice?

  • @TPA22222
    @TPA22222 4 года назад

    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

  • @Elclassicodelaelbe
    @Elclassicodelaelbe 3 года назад +1

    is it possible to save the video with captured faces, INCLUDING the audio line?

  • @KingDuken
    @KingDuken 4 года назад

    Sweet video :) any recommendations for libraries for something like object recognition?

  • @pratikgangurde_te-b-7428
    @pratikgangurde_te-b-7428 4 года назад

    Sentdex,Your teaching method is really unique than others.

  • @acidtears
    @acidtears 4 года назад

    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.

  • @lautarodapin
    @lautarodapin 4 года назад +3

    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)

  • @dracleirbag5838
    @dracleirbag5838 4 года назад

    can you do one dealing with low resouces like trying to do this on jetson nano it crawls to a stop and start process

  • @davidmensah136
    @davidmensah136 2 года назад

    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...

  • @FadliGustiansyah
    @FadliGustiansyah 4 года назад

    Nice content, I really want to try this. You make me love python much much more. Thanks

  • @aotrakstar
    @aotrakstar 4 года назад +9

    Absolutely, add more logic in the third video.

  • @rahuldass4882
    @rahuldass4882 4 года назад +4

    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?

    • @eksanataprawira
      @eksanataprawira 4 года назад +2

      Preprocessing the image. Like use some image filter i guess

  • @ShivamDubeymike
    @ShivamDubeymike 4 года назад +1

    @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.

  • @tsohgsshell707
    @tsohgsshell707 4 года назад

    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?

  • @ronkeyx5
    @ronkeyx5 3 года назад

    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.

  • @anthonygonsalvis121
    @anthonygonsalvis121 3 года назад

    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

  • @daliasalah8304
    @daliasalah8304 3 года назад

    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 ?

  • @tickyotacky
    @tickyotacky 4 года назад +2

    Why does you profile picture get more pixelated every time?

  • @sandtiwa
    @sandtiwa 4 года назад +1

    Could you do a video on how to integrate this with an application? maybe a mobile app? Thanks!

  • @MrReaps84
    @MrReaps84 Год назад

    Is there a folder i can download that is ready to use- ie plug and play?

  • @sambitbanerjee2535
    @sambitbanerjee2535 3 года назад

    Hey I just wanna know that how do i classify wheather this facial detection can be taken from video or other mobile

  • @ibrahimafall7867
    @ibrahimafall7867 2 года назад

    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

    • @FrenchcoreFlava
      @FrenchcoreFlava Год назад

      Can't you end the loop when it says hi the first time?

  • @bejgaonnischit9718
    @bejgaonnischit9718 4 года назад +1

    Out of curiosity which phone do you own?🤔🤔🤔

  • @bhoomikachudasama3150
    @bhoomikachudasama3150 4 года назад

    Great and to the point video.

  • @samu6982
    @samu6982 4 года назад +1

    Can't wait for part 3

  • @tedp9146
    @tedp9146 4 года назад

    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?

    • @acidtears
      @acidtears 4 года назад +1

      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.

    • @tedp9146
      @tedp9146 4 года назад

      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

  • @anthonygonsalvis121
    @anthonygonsalvis121 3 года назад

    @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.

  • @tanishqsoni2194
    @tanishqsoni2194 4 года назад

    When is part 3 coming?

  • @Obliviander
    @Obliviander 4 года назад +5

    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

    • @mrfrozen97-despicable
      @mrfrozen97-despicable 3 года назад

      Respect+=1

    • @aristology6912
      @aristology6912 3 года назад +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.

  • @GraemeMac
    @GraemeMac 4 года назад +1

    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

    • @midgekiller2151
      @midgekiller2151 4 года назад +1

      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.

  • @hamzaraza9804
    @hamzaraza9804 4 года назад

    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

  • @rafaelenv
    @rafaelenv 3 года назад

    its lagging a lot on my pc, but is a strong machine, maybe can be the video card?

  • @agungbanar687
    @agungbanar687 3 года назад

    is it possible to do this live? like from camera

  • @teachusmore
    @teachusmore 4 года назад

    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.

    • @anthonygonsalvis121
      @anthonygonsalvis121 3 года назад

      Give the full file path (instead of relative path) and see if that helps.

  • @et2124
    @et2124 4 года назад

    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

    • @et2124
      @et2124 4 года назад

      Is there anything I can do or is it just about the machine

  • @Ahmed.Shaikh
    @Ahmed.Shaikh 3 года назад

    Great vid! =D
    Can you show how we can do the merge on the encodings for the same face with multiple IDs?

  • @yacinenr7602
    @yacinenr7602 3 года назад +1

    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

    • @neuron8186
      @neuron8186 3 года назад

      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

    • @neuron8186
      @neuron8186 3 года назад

      10th gen and 2gb inbuild graphic

  • @simonfaulkner5596
    @simonfaulkner5596 Год назад

    Is the code fort this tutorial available?

  • @gunarakulangunaretnam3353
    @gunarakulangunaretnam3353 4 года назад

    Wonderful tutorial. I am one of your fan from Sri Lanka. Please make part 03.

  • @rwcmarketing2587
    @rwcmarketing2587 4 года назад

    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)

  • @nite8club
    @nite8club 4 года назад

    Not working proper windows, what config do we need for Linux?

  • @adityar2654
    @adityar2654 2 года назад

    Can someone tell me what is the accuracy of cnn model used here?

  • @czeuw3896
    @czeuw3896 4 года назад

    Man you are just awesome !

  • @indrasishdatta7210
    @indrasishdatta7210 4 года назад

    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 !!

  • @ananoor7385
    @ananoor7385 4 года назад +1

    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

  • @daenutt8
    @daenutt8 4 года назад

    Gracias muy buen video, saludos desde Perú 🇵🇪

  • @comtech80
    @comtech80 4 года назад

    Love your videos! Please make a third video on this :)

  • @tayebsaadi
    @tayebsaadi 2 года назад

    part 3 seems very interesting. Please do it

  • @meashu29
    @meashu29 4 года назад

    amazing ....thank you very much

  • @shockingvideos5225
    @shockingvideos5225 4 года назад

    Your tutorials are great.
    Can you make series on building systems like amazon go?

  • @ajairahouse7058
    @ajairahouse7058 4 года назад +4

    Please continue,the series of face_recognition library

  • @NoOne-uz4vs
    @NoOne-uz4vs 4 года назад +1

    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*

    • @sentdex
      @sentdex  4 года назад +2

      Use a smaller resolution.

    • @NoOne-uz4vs
      @NoOne-uz4vs 4 года назад

      ​@@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

  • @rahilshiraz2247
    @rahilshiraz2247 4 года назад +1

    Please do a part 3!!!

  • @user-nf1dj4vv5n
    @user-nf1dj4vv5n Год назад

    Where can I find the final code?

  • @nikhilkamble4210
    @nikhilkamble4210 4 года назад

    Can you make video tutorials on docker?

  • @sumanthkota8267
    @sumanthkota8267 4 года назад

    Does this code work on Windows too?

  • @DeepakKumar-uz4xy
    @DeepakKumar-uz4xy 4 года назад

    where is the part 3?

  • @PsychOpathy
    @PsychOpathy 3 года назад

    It's more than a year and still no part 3 :(

  • @zpeike8424
    @zpeike8424 4 года назад

    so interesting! thanks a lot~

  • @patrickmullot73
    @patrickmullot73 4 года назад

    definitely PArt II should be you doing that!

  • @mohmmedfaisl5275
    @mohmmedfaisl5275 4 года назад

    Can this code run in raspberry pi with pi camera

  • @microgamawave
    @microgamawave 3 месяца назад

    there is 2024 model that is good?

  • @bejjan
    @bejjan Год назад

    I don't know what I'm doing wrong but my program lags out like crazy even with just one image.

  • @trol9880
    @trol9880 4 года назад

    Yeah part 3 please !

  • @amanborse8968
    @amanborse8968 3 года назад

    How can we increase the FPS of a webcam ?

  • @hassenzarroug9159
    @hassenzarroug9159 4 года назад

    Thank you so much

  • @ahsanbaig8569
    @ahsanbaig8569 4 года назад

    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.

  • @robertknopf6207
    @robertknopf6207 3 года назад

    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....

    • @arthure6846
      @arthure6846 3 года назад

      You are probably not finding any matches, or you have to many pictures in your known faces

  • @akashkesharwani5761
    @akashkesharwani5761 4 года назад

    Your laugh is pretty good 😄

  • @ajaykumargogineni6498
    @ajaykumargogineni6498 4 года назад

    Are you planning to make a video on deepfakes competetion?
    Some of the participants are using face detection.

  • @ahmadkelixo7243
    @ahmadkelixo7243 3 года назад

    permission to learn sir. thanks you

  • @JNET_Reloaded
    @JNET_Reloaded 2 года назад

    can I have the link to code please?

  • @wolverine87833
    @wolverine87833 3 года назад

    2:54 Yup..your assumption is right. It does convert the image to grayscale by default even if you don't mention it explicitly.

  • @ishmamtasin7537
    @ishmamtasin7537 3 года назад

    this is so extraordinary

  • @talhatariqyuluqatdis
    @talhatariqyuluqatdis 4 года назад +1

    I salute you for that thumbnail

    • @sentdex
      @sentdex  4 года назад

      Salute the YT thumbnail picking algorithm lol. I usually just go with whatever it chooses, and ... it chose well yet again :)

  • @nictanghe98
    @nictanghe98 4 года назад

    also ask kite for meney if ur going to pro;ote them like that.

  • @wokeman9928
    @wokeman9928 4 года назад +1

    This work if you do it with images ?

    • @sentdex
      @sentdex  4 года назад +1

      We did it with images in the previous tutorial: pythonprogramming.net/facial-recognition-python/

  • @vaibhavnitsure4101
    @vaibhavnitsure4101 4 года назад

    Can't open camera by index
    Error dude 👆

  • @CS-su2fk
    @CS-su2fk 4 года назад

    May i know why the code doesn't activate my live webcam? video =cv2.VideoCapture(2)

    • @KCLX_DLEX
      @KCLX_DLEX 4 года назад +3

      try video = cv2.VideoCapture(0)

  • @RonMartinJr
    @RonMartinJr 4 года назад

    That's fascinating and terrifying haha

  • @nictanghe98
    @nictanghe98 4 года назад

    y u no arch ?

  • @jyleong2383
    @jyleong2383 4 года назад +2

    Hi, the face_recognition module can't work. It ask to install dlib first but dlib can't be installed too.

    • @NoOne-uz4vs
      @NoOne-uz4vs 4 года назад

      @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.

    • @abhishekdutt1996
      @abhishekdutt1996 4 года назад

      @Arihant Debnath it worked for me just install cmake and then dlib

    • @jyleong2383
      @jyleong2383 4 года назад

      @@abhishekdutt1996 dlib can't be installed, although I have already installed cmake.

    • @meshkatshadik
      @meshkatshadik 4 года назад

      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!

    • @denniskainga6970
      @denniskainga6970 3 года назад

      Incase you couldnt find a solution just download visual studio for c++ install then run
      Pip install cmake
      Pip install dlib
      It should work

  • @moustafa_shomer
    @moustafa_shomer 4 года назад

    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♥

  • @comtech80
    @comtech80 4 года назад

    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.

    • @comtech80
      @comtech80 4 года назад +1

      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))

  • @py_tok5589
    @py_tok5589 3 года назад

    any idea how to install CV2 AND OS, ? I cant , I did try, I m working on python 3.7.6 and pycharm

    • @py_tok5589
      @py_tok5589 3 года назад

      pycharm version 2019.3., I cnt find the installers of cv2 nor os ON PYCHARM? any idea how to install? Harrison

    • @erandeye
      @erandeye 3 года назад

      @@py_tok5589 pip install opencv -python

  • @selcukmisir2399
    @selcukmisir2399 4 года назад

    thanks man :)

  • @satyamsinghal930
    @satyamsinghal930 3 года назад

    Waiting for the 3rd video 🤞

  • @kunalbhagia
    @kunalbhagia 4 года назад

    great content

  • @mohmmedfaisl5275
    @mohmmedfaisl5275 4 года назад

    can u update the code to say the face name with text to speech code when it detect it

    • @acidtears
      @acidtears 4 года назад

      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.