In [6]:
import cv2
import numpy as np

man = cv2.imread('index.jpg')
face = []
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
gray = cv2.cvtColor(man, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

for (x,y,w,h) in faces:
    #cv2.rectangle(man,(x,y),(x+w,y+h),(255,0,0),2)
    face = man[x:x+w,y:y+h]

av = np.average(face, axis=1)
#print(av)

val = np.sum(av, axis=0) / av.shape[0]

print val
a = 60
val_lower = val - [a, a, a]
val_up = val + [a, a, a]

lower = np.array(val_lower, dtype="uint8")
upper = np.array(val_up, dtype="uint8")

mask = cv2.inRange(man, lower, upper)
output = cv2.bitwise_and(man, man, mask = mask)

kernel = np.ones((5,5),np.uint8)
opening = cv2.morphologyEx(output, cv2.MORPH_OPEN, kernel)
output = cv2.erode(output, kernel, iterations = 1)
output = cv2.dilate(output, kernel, iterations = 1)

cv2.imshow('img', output)
cv2.imshow('man', man)
cv2.waitKey(0)
cv2.destroyAllWindows()


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-6-b55216ea1ff3> in <module>()
     13 
     14     # Our operations on the frame come here
---> 15     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
     16 
     17     # Display the resulting frame

error: ..\..\..\modules\imgproc\src\color.cpp:3739: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor

In [ ]: