In [48]:
### %matplotlib inline
import matplotlib.pyplot as plt
import cv2
import os

#cscpath = '/data/haarcascade_profileface.xml'
cscpath = '/data/haarcascade_frontalface_default.xml'

files = os.listdir("/data/images")
print(files)
filepath = '/data/images/' + files[5]
#filepath = '/data/images/pic.jpg'
print(filepath)

faceCascade = cv2.CascadeClassifier(cscpath)
image = cv2.imread(filepath)
image = cv2.cvtColor(image, cv2.cv.CV_BGR2RGB)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=4,
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)
#print(faces)
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

plt.imshow(image)
#print(image.shape)
#plt.imshow(image)
#plt.imshow(gray)


['1016545105_873840a508_1150_92729647@N00.jpg', '1117311341_5ec6dec4fd_1137_12349681@N00.jpg', '2556815071_48ab24131c_3120_87173471@N00.jpg', '402282589_73c23a1a39_141_93745350@N00.jpg', 'faces_orig.jpg', 'pic.jpg']
/data/images/pic.jpg
Out[48]:
<matplotlib.image.AxesImage at 0x7f57281f1bd0>