I am using the haarcascade_frontalface_default.xml classifier to detect faces in python 3 on Windows 7 with OpenCV 3.1.0 using the following code:
import cv2
import sys
classifier = cv2.CascadeClassifier ("haarcascade_frontalface_default.xml")
image = cv2.imread (sys.argv[1]) # Read image from first command line param
gray = cv2.cvtColor (image, cv2.COLOR_BGR2GRAY) # Convert the image to grey scale
# Detect faces on image
faces = classifier.detectMultiScale (gray, scaleFactor = 1.1, minNeighbors = 5, minSize = (30, 30), flags = cv2.CASCADE_SCALE_IMAGE)
print ("Found {0} faces!".format (len (faces)))
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle (image, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow ("Faces found", image)
cv2.waitKey (0)
cv2.destroyAllWindows ()
This code works fine for most face images I have. However it does not work for this specific image. C:\fakepath\1a.jpg Any idea why?