Skip to content

Tutorials

Face detection using Haar Cascades – OpenCV 3.4 with python 3 Tutorial 37

Access community, courses and source codes
Logo

AI Vision Academy

Access the code of this tutorial, computer vision courses and an exclusive community on AI Vision Academy

  • Access to over 50+ source codes from Pysource.com/blog
  • Dedicated video courses about computer vision
  • Access to an exclusive community of professionals
  • Real-World AI Projects – Get hands-on experience building practical AI Computer Vision solutions with a structured path.
  • Monthly Coaching Calls – get support and any of your questions answered

Subscribe to our newsletter to learn more

You will learn in this video how to detect Faces using the Haar Cascades object detection method.

13 comments

  1. hello i got one error code how do i fix it?
    faces = face_cascade.detectMultiScale(gray, [1.1, [neighbours]])
    TypeError: must be real number, not list

    1. faces = face_cascade.detectMultiScale(gray, [1.1, [neighbours]])
      replace by this line of code
      faces = face_cascade.detectMultiScale(gray, 1.1, neighbours)

      1. I copy your code, but my pycharm report error:
        Traceback (most recent call last):
        File “F:/OpenCV/OpenCV_Draw1.py”, line 20, in
        faces = face_cascade.detectMultiScale(gray, 1.3, neighbours)
        cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function ‘cv::CascadeClassifier::detectMultiScale’
        Can you help me fix this error

        1. actually the error is occuring because of you are not defining the correct path of the harcascade file
          the harcascade file is missing or named differently or u dont have the file in your directory

          try to fix this i.e the file path(i mean location of file or address ok hope it helps whoever gets stuck:))

  2. pycharm report error
    C:\Users\pc\PycharmProjects\facerecognition\venv\Scripts\python.exe C:/Users/pc/PycharmProjects/facerecognition/identification.py
    Traceback (most recent call last):
    File “C:/Users/pc/PycharmProjects/facerecognition/identification.py”, line 21, in
    faces = face_cascade.detectMultiScale(gray, 1.3, neighbours)
    cv2.error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\objdetect\src\cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function ‘cv::CascadeClassifier::detectMultiScale’
    can u help me please
    tell me what should i do ?

  3. Hi, I’m facing following error
    cv2.error: OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:253: error: (-215:Assertion failed) VScn::contains(scn) && VDcn::contains(dcn) && VDepth::contains(depth) in function ‘cv::CvtHelper<struct cv::Set,struct cv::Set,struct cv::Set,2>::CvtHelper’

    1. i have an error here below when i run this code

      runfile(‘/Users/ujjwalabhishek/Desktop/deep learning/AutoEncoders/untitled6.py’, wdir=’/Users/ujjwalabhishek/Desktop/deep learning/AutoEncoders’)
      Traceback (most recent call last):

      File “/Users/ujjwalabhishek/Desktop/deep learning/AutoEncoders/untitled6.py”, line 29, in
      faces = face_cascade.detectMultiScale(gray, 1.3, neighbours)

      error: OpenCV(3.4.2) /opt/concourse/worker/volumes/live/9523d527-1b9e-48e0-7ed0-a36adde286f0/volume/opencv-suite_1535558719691/work/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215:Assertion failed) !empty() in function ‘detectMultiScale’

Join the discussion