Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Using the Viola-Jones Framework

Give Feedback

Training a Viola-Jones classifier from scratch can take a long time. Fortunately, a pre-trained Viola-Jones classifier comes out-of-the-box with OpenCV! You will use that one to see the algorithm in action. If you really want to train the classifier yourself, scikit-image offers a tutorial with the accompanying code on their website.

To follow the exercise in this lesson, you’re going to need to dowload the following image:

Family stock photo
Example stock photo for face detection (Image source)

You’ll also need to go to the OpenCV GitHub repo.

Comments & Discussion

kishorekaruparthi on Sept. 9, 2019

Hello Austin,

Can i use haarcascade_frontalface_alt.xml for any image to detect faces?

Keegan on March 27, 2020

Im having some trouble installing opencv3, I tried conda install -c menpo opencv3

and was prompted with an error:

“collecting packing metadata (current_reopendata.json): failed”

Luke Brown on March 28, 2020

Should go into more detail on the python 2.7 stuff that happened in your conda. I had an issue where mine did not automatically downgrade me. Maybe instead use the latest version of openCV?

rafaelboisel on March 28, 2020

I’m having trouble importing opencv3 in my python script. After setting up just like in the video and trying to run the script I get this error : line 1, in <module> import cv2 as cv ImportError: DLL load failed: The specified module could not be found.

Ramon de Lima Ramos on March 30, 2020

For those who it’s facing issue with import of cv2. Head up to the terminal and create a new conda create --name face-detection2 python=2.7 and install the libs the same way presented on the video. When you run it again will work fine.

richlysakowski on April 3, 2020

Why are you using Python 2.7? Planet Earth dropped support completely, i.e., End-of-Life for Python 2.7 on January 1, 2020.

Did you pull this lesson out of an old archive somewhere?

Your example is impractical to use for a real application unless we package it in a conda time capsule - a frozen zombie on ice.

The algorithm is practical because it is simple and fast.

I get through your very nice explanation lesson, only to find near the end you want me to go back to 2010 software! Sorry to be harsh, it is a ridiculous. From

"July 3rd, 2010 Python 2.7. 0 was released on July 3rd, 2010. Python 2.7 is scheduled to be the last major version in the 2. x series before it moves into an extended maintenance period."

The current year is 2020, not 2010. Your lesson was great up to your code at the end.

Come on, dump the Python 2.7 and update your lesson. Give us code that works with Python 3.8.

richlysakowski on April 3, 2020

I’m a subscriber AND I pay with my time too to get through your examples. Even if this is “free”, it costs time.

I appreciate your time in creating the informative explanations, but if you use obsolete software (Python 2.7), please let us know up front, so we can make an informed choice to pass on to another example.

I really hated learning Python with two incompatible versions of Python at once. It was mostly a lot of needless headaches, very little useful pedagogy besides too much practice debugging a lot of crappy old code.

Dan Bader RP Team on April 3, 2020

@richlysakowski: This course uses Python 3.7, as you can see in the video around the 01:40 mark.

Edit: My bad, this lesson actually switches to 2.7 at the end. We’ll look into updating this course for Python 3 throughout!

atomiczagnut on April 4, 2020

I’ll start with the good stuff. I did like your layman’s explanations of how the algorithms work. And, of course, the price was right.

After that, I ran into the same problem as everyone else. Mine did not automatically downgrade to to 2.7 when I tried to install OpenCV, and nor should it! 2.7 is deprecated beyond belief.

I already had OpenCV successfully installed through pip, and could use it fine with IDLE. Maybe try that?

harpoongt4 on April 13, 2020

**how to do download haarcascade_frontalface_alt.xml

rathodsushma5 on April 20, 2020

The code worked fine for me with python3.7. I didn’t had to downgrade to python2.7 as it was mentioned in the above comments.

OpenCV3 seemed to work fine, everything worked seemlessly for me.

justintylerfarias on April 26, 2020

for some reason my error is saying small is the problem that the variable small is invalid

Become a Member to join the conversation.