In [1]:
import cv2

In [2]:
img = cv2.imread('data/src/lena_square.png')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

In [3]:
print(type(img), img.shape)
print(type(img_gray), img_gray.shape)


<class 'numpy.ndarray'> (512, 512, 3)
<class 'numpy.ndarray'> (512, 512)

In [4]:
cascade_path = '/usr/local/Cellar/opencv3/3.2.0/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml'
cascade = cv2.CascadeClassifier(cascade_path)

In [5]:
faces = cascade.detectMultiScale(img_gray)

In [6]:
print(faces)


[[215 201 175 175]]

In [7]:
for x, y, w, h in faces:
    cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)

In [8]:
cv2.imwrite('data/dst/lena_square_face.jpg', img)


Out[8]:
True