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)
Out[48]: