Face Detection in 2 Minutes using OpenCV and Python

Sdílet
Vložit
  • čas přidán 4. 09. 2024
  • In this quick tutorial I explain how you can detect faces in images as well as videos using Haar Cascades in OpenCV and Python. Face detection is the first step for doing face recognition.
    Written version of this tutorial:
    towardsdatasci...
    GitHub link: github.com/ada...
    Having trouble ? Need help ? Connect with me !
    Email: adarsh1021@gmail.com
    Instagram: / adarsh_menon_
    Twitter : / adarsh_menon_
    Github : github.com/ada...
    #machinelearning #python #facedetection #opencv

Komentáře • 464

  • @adithyasai8987
    @adithyasai8987 Před 4 lety +101

    while others are struggling to explain opencv. you did it in a simple way. In just 2 min
    GREAT vlog

    • @interesting7215
      @interesting7215 Před 4 lety +3

      this is not 2 min...

    • @shuaibsugaran8936
      @shuaibsugaran8936 Před 4 lety +2

      actually he skip it for a seconds without skipping the countdown in the screen

    • @voltifer5267
      @voltifer5267 Před 4 lety +4

      This is not a vlog. If you don’t know, don’t use it

  • @Integralsouls
    @Integralsouls Před 4 lety +11

    i really have to say ...nice work man ...u deserve to be recognised not just be these cascades but also by real people all around this ML community...

  • @nainaalex9053
    @nainaalex9053 Před 3 lety +3

    You gotta be kidding me..
    The error I've been trying to fix got fixed in 2 seconds just cuz of you 🔥
    Thanks buddy!

  • @bunnyvlogs7647
    @bunnyvlogs7647 Před 4 lety +16

    u earned my like with 2 min stopper clock

  • @okokicici
    @okokicici Před rokem +3

    This helped me a lot done with my project just in 15 mins😊 ,.... U r fabulous bro...

  • @anadani81917
    @anadani81917 Před 4 lety +24

    Finally, a good video. Thank you!

  • @shaad498
    @shaad498 Před 4 lety +35

    Watched every commercial videos but got the thing in DESI ONE

  • @philliphelmut1077
    @philliphelmut1077 Před 3 lety +7

    Great Video, everyone else makes hour-long videos and explains basically the same stuff, here I learned all what is important in 6min. Good job!

  • @shubhamkhupase6514
    @shubhamkhupase6514 Před 4 lety +9

    Bro explained very well. Just carry on !!!!

  • @albertovarela6050
    @albertovarela6050 Před 3 lety +1

    Thank you!!! I tried to do this for more than a month...
    You explained very well!

  • @ahmed1o137
    @ahmed1o137 Před 2 lety +6

    good job man. keep up the good work because im sure it'll pay off in the long run. its rare to find talanted teachers and you are definitely one. simply well done

  • @radhikaravindra7293
    @radhikaravindra7293 Před 3 lety +2

    Best one I have come across on CZcams. Works without any error SO INSTANTLY.
    Keep more coming!

  • @rohitsharma-pz1xc
    @rohitsharma-pz1xc Před 3 lety +2

    This is great video, I knew the basics off all the commands, your video helped me put all my knowledge to a functional detector. Thank you

  • @leamlisophara731
    @leamlisophara731 Před 3 lety +2

    I have some error with this --> 'cv2.CascadeClassifier' object has no attribute 'detectMultiScal'. Could you tell how to fix it ????

  • @okokicici
    @okokicici Před rokem +1

    Can u pls upload about human activity recognition

  • @rusbiantrush4576
    @rusbiantrush4576 Před 3 lety +1

    hi Ardas, thanks for your Lesson. god bless you ..Rusbi from Indonesia

  • @herecomestherainagain3031

    u are a king man thanks from turkey

  • @pranitsawant6085
    @pranitsawant6085 Před 3 lety +1

    amazing buddy its really help me my mca projects thanks a lot buddy.

  • @atlurivijay10
    @atlurivijay10 Před 2 lety +1

    So I have been getting this error OpenCV(4.1.2) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor' any idea?

  • @HOBBY-MASTER
    @HOBBY-MASTER Před 2 lety

    thank you , this was my first face detection project , awesome explanation

  • @OT-oi8kl
    @OT-oi8kl Před 3 lety +2

    This was hella easy to follow, thank you!

  • @shouviksamadder5193
    @shouviksamadder5193 Před 3 lety +1

    by far the best explanation

  • @JalalKhan-we1th
    @JalalKhan-we1th Před 3 lety +1

    Wow simply amazing, hats off to you😍

  • @likhithagoberu1304
    @likhithagoberu1304 Před 3 lety +2

    Traceback (most recent call last):
    File "C:/face recognition/detectfacevideo.py", line 19, in
    faces = face_cascade.detectMultiScale(gray, 1.1, 4)
    cv2.error: OpenCV(4.5.2) C:\Users
    unneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale' iam having this error how can i solve it..

  • @safabelhadjromdhane2922
    @safabelhadjromdhane2922 Před 3 lety +3

    Hello, I have a question to ask, I did the exact same thing as you in the video but the program didn't work and it announced an error while running the color saying "error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor' " how do I fix it ? and thanks in advance for your help.

  • @Singer_Sonali
    @Singer_Sonali Před 4 lety +1

    Very well explained. ..found it easiest tutorial

  • @AmeerHamza-uu1gc
    @AmeerHamza-uu1gc Před 2 lety

    Good bro Also made video on face MASK detection.
    Thanks

  • @hermawannugroho4070
    @hermawannugroho4070 Před 4 lety +2

    thanks my man you save my life

  • @sunil-khatri
    @sunil-khatri Před 4 lety +11

    Hey, I have one question to ask. How can I make my own classifier instead of using pre-built haar cascade files?

    • @AdarshMenon
      @AdarshMenon  Před 4 lety +9

      Sentdex has made an amazing video on making your own classifier using haar cascasde - czcams.com/video/jG3bu0tjFbk/video.html
      Another option for object detection would be to build a deep learning model using keras. You can also use something called "transfer learning", to retrain existing classification models to classify the objects you want to

  • @homelessgod2145
    @homelessgod2145 Před 3 lety +1

    Thanks, it works so easy in just 5 minutes,

  • @JNK369
    @JNK369 Před 4 lety +4

    you may not reply for the error i think , you only reply for the person who appreciate you
    you may try to clear the errrors of your subscribers also it may gives you a real happiness and thats the true appretiation

  • @kmnm9463
    @kmnm9463 Před 3 lety +3

    Hi Adarsh,
    You made Face Recognition look so simple . Felt like I can learn FR hands down. . I have subscribed to your channel.
    Thanks form KM

  • @nareshkosuri2724
    @nareshkosuri2724 Před 3 lety +1

    Great

  • @mertceylan2080
    @mertceylan2080 Před 3 lety +1

    thanks man, beneficial video for beginners

  • @betsythomas5971
    @betsythomas5971 Před 4 lety +1

    Good work Adarsh..Saved a lot of time!!

  • @infobox-Hindi
    @infobox-Hindi Před 3 lety +1

    Can u please make video like detecting the presence of human and with respect to open or close the relay

  • @valibabushaik5073
    @valibabushaik5073 Před 3 lety +1

    Everything is Awesome.... Tnq bro

  • @MohitSaini-zc5zi
    @MohitSaini-zc5zi Před 2 lety

    Good job. Your code is still working.

  • @roku1892
    @roku1892 Před 3 lety

    Nice video, because :
    -Indian tutorial
    -Cursed audio
    -Machine backsound

  • @sheikhanikulislamhani1304

    It works properly. Thank you.

  • @Kishu6969
    @Kishu6969 Před 2 lety

    Helped A lot. Thanks for a detailed tutorial!

  • @saurabh-ny8cn
    @saurabh-ny8cn Před 4 lety +2

    If we want to recognize faces with names then what we can do ?
    Means it can able to detect face. Then what ?

    • @AdarshMenon
      @AdarshMenon  Před 4 lety

      This is only to detect faces. To recognize them - czcams.com/video/987QtKPZ-P0/video.html

    • @saurabh-ny8cn
      @saurabh-ny8cn Před 4 lety

      @@AdarshMenon I watched that video but I am saying that if a moving person comes infront of camera. Then how we can do that in real time??

    • @AdarshMenon
      @AdarshMenon  Před 4 lety

      the face recognition library can help you do that - github.com/ageitgey/face_recognition

  • @roku1892
    @roku1892 Před 3 lety

    Nice, clean and good explanation tutorial ❌
    Indian guy tutorial, machine sound, cursed audio 👍👍👍👍

  • @ft.Atulkumarsingh
    @ft.Atulkumarsingh Před 4 lety +2

    Thanks bro, just thanks, now i really get this

  • @deepakdadlani9284
    @deepakdadlani9284 Před 3 lety +1

    hey...i need your help please reply..
    can you tell me how can i detect the face of dog and cat and their emotions ...in python..please let me know if you know anything about it ..please help!

  • @SUMITMITRA25
    @SUMITMITRA25 Před rokem

    its small to get started on and its good

  • @HEROSHORTS101
    @HEROSHORTS101 Před 3 lety

    thank you very much. very educational and helpful tutorial.

  • @forhadkhan5316
    @forhadkhan5316 Před 4 lety +3

    Oh man you just save my day. Thank u

  • @akashrajak-PhD
    @akashrajak-PhD Před 3 lety +1

    Good one..

  • @priy3865
    @priy3865 Před 8 měsíci

    Thankyou so much vdo helped a lot🙌❤️

  • @SreekumarNk
    @SreekumarNk Před 4 lety +1

    Very useful Adarsh. Thank you.

  • @pankajjoshi4206
    @pankajjoshi4206 Před rokem

    How to detect two or more faces coming towards camera. Thankyou for your video

  • @MertAliBarlas
    @MertAliBarlas Před 4 lety +2

    Hi
    I'm getting this error:
    C:\Users\pc\AppData\Local\Programs\Python\Python38-32\python.exe: can't open file 'test2.py': [Errno 2] No such file or directory
    I'm try to solve but I can't solve it, can you help me ? @Adarsh Menon

    • @AdarshMenon
      @AdarshMenon  Před 4 lety +1

      you need to be inside the directory where you saved your file 'test2.py'. Use chdir command in windows terminal to change directory

    • @MertAliBarlas
      @MertAliBarlas Před 4 lety +2

      @@AdarshMenon Thanks but ı already solved, thx for help

  • @achendvankar
    @achendvankar Před 3 lety

    thank you so much. it totally worked. Keep up the good work.

  • @seemaager3241
    @seemaager3241 Před 2 lety

    Thank u so much..😍
    U saved me today😅

  • @shriyanssudhi4545
    @shriyanssudhi4545 Před 2 lety

    Thanks for making this video not complex

  • @amalipremasiri2237
    @amalipremasiri2237 Před 3 lety +1

    sir thank your for this video. i tried this. but i have a error.how can i fix it?
    Traceback (most recent call last):
    File "C:\Users\amali\Desktop\Face_Detection\test1.py", line 13, in
    faces = face_casCade.detectMultiScale(gray, 1.3, 5)
    NameError: name 'face_casCade' is not defined

    • @AdarshMenon
      @AdarshMenon  Před 3 lety

      looks like the variable is not defined, python is case sensitive. I think it should be face_cascade if you have used my code. Or else make sure the cascade file is in the same folder where the code is

  • @marcusbeck2329
    @marcusbeck2329 Před 3 lety +1

    In what software do you code this

  • @nishanisha1266
    @nishanisha1266 Před 4 lety +1

    What if we need to detect a photo which is in a particular drive

    • @AdarshMenon
      @AdarshMenon  Před 4 lety

      In the video at 1:30, line number 5 simply change the path of your file. For example if your file is C:/pictures/test.jpg, you can change that line to cv2.imread('C:/pictures/test.jpg')

    • @nishanisha1266
      @nishanisha1266 Před 4 lety +1

      @@AdarshMenon thank you for replying

    • @nishanisha1266
      @nishanisha1266 Před 4 lety +1

      @@AdarshMenon I have a doubt could you pls help me out...how can I reach you!!pls a small help

    • @AdarshMenon
      @AdarshMenon  Před 4 lety

      adarsh1021@gmail.com

    • @nishanisha1266
      @nishanisha1266 Před 4 lety

      @@AdarshMenon I mailed!!pls checkout

  • @vishalananth
    @vishalananth Před rokem

    Thank you very much for this , helped a lot !!!

  • @lvmeghana130
    @lvmeghana130 Před 4 lety +1

    hey help plz getting errors like
    Module 'cv2' has no 'CascadeClassifier' member..,Module 'cv2' has no 'VideoCapture' member,..Module 'cv2' has no 'cvtColor' member...,Module 'cv2' has no 'COLOR_BGR2GRAY' member...,Module 'cv2' has no 'rectangle' member....,Module 'cv2' has no 'waitKey' member

  • @Daniel-qo9uv
    @Daniel-qo9uv Před 3 lety +1

    Hi I did: pip3 install opencv-python but I get an error with pycharm regarding open cv2 : ModuleNotFoundError: No module named 'cv2' How to fix it?

    • @AdarshMenon
      @AdarshMenon  Před 3 lety

      Maybe you are on another version of python ? if you are using pip3, then make sure you call the script with python3

  • @frozen-x-fire163
    @frozen-x-fire163 Před 3 lety +1

    thank u very much bro its really nice working

  • @rajkushwahar
    @rajkushwahar Před 3 lety

    No problem video is six minete greet job dud

  • @lfmtube
    @lfmtube Před 3 lety

    Most straightforward video and useful video. Very helpful to me! Thank you very much.

  • @suggu_sandeep_passion
    @suggu_sandeep_passion Před 4 lety +1

    Thanks Bro You Made Simple ;)

  • @madhusree.a7794
    @madhusree.a7794 Před 3 lety +1

    thankyou for this video..

  • @AayushMatkar
    @AayushMatkar Před 4 lety +1

    OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
    how can i resolve this error

    • @AdarshMenon
      @AdarshMenon  Před 4 lety

      Maybe your haar cascade file did not load properly. Check if you donwloaded it in the same directory as your code.
      Maybe this will help - answers.opencv.org/question/52340/opencv-error-assertion-failed-empty-in-detectmultiscale/

  • @raviprakash9338
    @raviprakash9338 Před 4 lety +1

    Working Now..Thanks

  • @spjcovers1204
    @spjcovers1204 Před 3 lety +1

    Can we add some time limit for the camera so that the camera turns off automatically and we don't have to press the ESC button ???

    • @AdarshMenon
      @AdarshMenon  Před 3 lety

      inside the while loop you could add a delay of say 100ms. Then you can keep a counter to count the number of times it ran (or maybe use a for loop). So now when this counter reaches 100 then you know that 10 seconds have passed

  • @rog_shakhyar6171
    @rog_shakhyar6171 Před 4 lety +2

    wow He explained so simply! Others are just making 23 mins video for this little purpose, anyways any solution to reduce cpu usage in the while loop? This takes up the whole cpu after 6 seconds!! Would be very helpful If we can run it on our gpu... is that possible?

    • @AdarshMenon
      @AdarshMenon  Před 4 lety +1

      Glad it helped ! It can be done, but seems complicated - www.quora.com/How-can-I-code-OpenCV-to-use-GPU-using-Python#:~:text=%2F%20Umat%20Objects)%20.-,When%20you%20use%20Umat%20type%2C%20OpenCV%20automatically%20tries%20to%20utilize,with%20CUDA%20and%20Python%20support.

  • @akshaykadam3811
    @akshaykadam3811 Před 2 lety

    That's Very Nice 👍👍.............
    You have any report of this project which gives details information about this project.

  • @koushikguptabonthala2429
    @koushikguptabonthala2429 Před 2 lety +1

    Hello. For detecting faces from images and detecting images from webcam do we need to build two different models

  • @kakulapatisunandini8429

    Hi... im working with upperbody detection, this is not working with the detection of upper-body. can u plz help me out to get a frame over the upperbody recognition

  • @abdullaal-bader46
    @abdullaal-bader46 Před 3 lety +1

    hello, there is a problem in line 19

  • @shafiquesayed2673
    @shafiquesayed2673 Před 4 lety +1

    In web cam capture it is not showing rectangle on more than 1 face what should i do

    • @AdarshMenon
      @AdarshMenon  Před 4 lety

      This will help you stackoverflow.com/questions/33546356/how-to-detect-multiple-faces-in-opencv

  • @sindhupriya6299
    @sindhupriya6299 Před rokem +1

    Super sir

  • @md.mojidulhaque7164
    @md.mojidulhaque7164 Před 4 lety +1

    Thank you very much brother.

  • @soseikiharagatatsu7859

    it didn't work in my sublime software because there's no run button but it run on idle python

  • @suryanshusaxena2082
    @suryanshusaxena2082 Před 2 lety +1

    Hello sir I am getting this error:
    error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
    Please tell me how to resolve it

    • @raviteja843
      @raviteja843 Před 2 lety

      Same error sir can you help me if you know how to resolve it

    • @hurraykoookie21
      @hurraykoookie21 Před 2 lety

      Please help me same error

  • @ramsy-sploit22
    @ramsy-sploit22 Před 3 lety +1

    i want to cheek if the face is my face then it wil give me a signe that the face is my you know what i'm saying

  • @leon81446
    @leon81446 Před 3 lety +1

    I'm getting this error please help
    face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
    AttributeError: module 'cv2' has no attribute 'CascadeClassifier'

    • @AdarshMenon
      @AdarshMenon  Před 3 lety

      Maybe your haar cascade file did not load properly. Check if you donwloaded it in the same directory as your code.
      Maybe this will help - answers.opencv.org/question/52340/opencv-error-assertion-failed-empty-in-detectmultiscale/

    • @leon81446
      @leon81446 Před 3 lety

      @@AdarshMenon Thank you for replying brother! Actually the problem was w/ the version of OpenCV. It wasn't compatible with the python version installed on my PC

  • @pankajjoshi8292
    @pankajjoshi8292 Před 3 lety +1

    Liked and subscribed.
    One question.
    I want to this with 10 diff ip cams not just one laptop camera. Pls tell how to do

    • @AdarshMenon
      @AdarshMenon  Před 3 lety

      you can definitely do it with 2 or even 3 i guess, but 10 might be a bit too much on your computer, unless you have a really powerful machine. In the line cv2.VideCapture(cam_no) - for each camera you need to write this like, where cam_no = 0, 1, 2.. no, of cameras. ref - stackoverflow.com/questions/29664399/capturing-video-from-two-cameras-in-opencv-at-once

  • @vyas8137
    @vyas8137 Před 3 lety

    Really loved you way of explaining stuff, could you tell where can I find internship to actually apply what I've learnt :)

  • @aryansonone7751
    @aryansonone7751 Před 3 lety

    Thank You So Much !!
    Very Brilliant !!

  • @user-of8pd5pl4z
    @user-of8pd5pl4z Před 7 měsíci

    Hi sir it shows an error cv2 has no attribute wait key can u solve this sir???

  • @sarthakagrawal8460
    @sarthakagrawal8460 Před 3 lety

    great video i founded on youtube thanks a lot bro.
    I am facing some error in code can u help me with that

  • @nawaab9275
    @nawaab9275 Před 3 lety +1

    how can we display the name along with the rectangle box around the face

    • @AdarshMenon
      @AdarshMenon  Před 3 lety +1

      there is a method cv2.putText to write text on the image - you can also check my face recognition video, where I did that

  • @akankshachoudante2489
    @akankshachoudante2489 Před 3 lety +2

    Please help me sir..it is showing error no Module named cv2

    • @AdarshMenon
      @AdarshMenon  Před 3 lety

      make sure you have installed opencv - run pip install opencv-python

    • @akankshachoudante2489
      @akankshachoudante2489 Před 3 lety

      @@AdarshMenon sir I have followed all the steps.already installed openCV n I have saved raw file as well .but this error is coming

    • @AdarshMenon
      @AdarshMenon  Před 3 lety +1

      @@akankshachoudante2489 if you are on python3 then you might also want to try pip3 install opencv-python. Or the recommended way is to create a virtual env and do everything inside it

    • @akankshachoudante2489
      @akankshachoudante2489 Před 3 lety

      @@AdarshMenon ok thank you Sir I will try ...

  • @madhumitham6702
    @madhumitham6702 Před 3 lety

    Hi brother ... You really explained awesome ... Thanks for sharing your knowledge brother How could I modify the code for the recognition of twins ??? ....

  • @circuittricks5144
    @circuittricks5144 Před 3 lety

    Very great video sir, please tell me how I save XML file in python project

  • @SomethingSpiritual
    @SomethingSpiritual Před 3 lety +1

    installing error 1 while doing pip install opencv-python
    please guide for opencv installation

  • @SUMITMITRA25
    @SUMITMITRA25 Před rokem

    giving a start on your github too

  • @pranavshridhar452
    @pranavshridhar452 Před 5 lety +1

    Awesome video! Keep going 👍

  • @samijulian1767
    @samijulian1767 Před 5 lety +1

    thanks lot bro ,i use the code and it works

  • @Evolutionofacharyaprsant

    Hello buddy I have cctv footage video it's possible to detect the face coz the face in video lil blur

  • @passion002
    @passion002 Před 2 lety

    Getting an error on line 7 saying src.empty() in function cv::cvtColor

  • @abhicruz1668
    @abhicruz1668 Před 2 lety

    i wrote the exact code but i there is not rectangle formation for the detection of faces

  • @imperial-x9899
    @imperial-x9899 Před 2 lety

    how did u use face recognization module without having it to train ??? arent we suppose to upload example of face and no face pic and make him learn?

  • @pratikdhule2579
    @pratikdhule2579 Před 3 lety

    bro how to close this application it opens again when i close it,, i am running this in anaconda... any key to stop this?