Ask Your Question

Revision history [back]

Get the cascade and put it in the same directory.


Now there was a typo in your code: haarScascade_frontalface_default.xml should be haarcascade_frontalface_default.xml

Change your code to this, make sure the indention is correct and it will work (make sure the cascade xml file is in the same directory):

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)

while True:
    ret, frame =
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = face_cascade.detectMultiScale(gray,1.3,5)
    for(x,y,w,h) in faces:
       print str(x)

   cv2.imshow('video', frame)
   if cv2.waitKey(1) & 0xFF == ord('q'):

Tested with Python 2.7.6. This works on my machine. If that still does not work copy the code with static image face detection from here and see if that works.