OpenCV Haar Cascades
CS-161: Software Project
Instructor: Rob Bruce
Spring 2016

SLIDE 1: OpenCV

  • OpenCV : Open Source Computer Vision library
  • Many useful machine vision algorithms:
    •  Haar Cascades for facial feature detection

SLIDE 2: Haar Cascades

  • Default cascades included with OpenCV are useful for estimating location of:
    •  whole face
    •  left and right eyes
    •  nose
    •  mouth

SLIDE 3: Haar Cascades

  • When a facial feature is detected with Haar Cascades:
    •  A rectangle encapsulating the facial feature is returned with Cartesian coordinates for upper left corner of rectangle followed by (width, height) relative to left corner.

SLIDE 4: Haar Cascades: Accuracy

  • Haar cascades are NOT super accurate!
  • They give you a rough estimate of where some pattern (in this case facial feature) is located.

SLIDE 5: Example code using Haar cascades

if (face_cascade.load ("haarcascade_frontalface_alt2.xml"))
{
  source_image_gray = imread (input_filename, CV_LOAD_IMAGE_GRAYSCALE);
  if (!source_image_gray.empty())
  {
    equalizeHist (source_image_gray, source_image_gray);
    min_neighbors = 10;
    face_cascade.detectMultiScale (source_image_gray, face, scale_factor, min_neighbors, CV_HAAR_FIND_BIGGEST_OBJECT);
    if (face.size() > 0)
    {
      printf ("Face found at (%d, %d) to (%d, %d)\n", face.x, face.y, face.x + face.width, face.y + face.height);
    }
  }
}