def detect(gray, img):
num_img = np.zeros(img.shape[:2], 'uint8')
result_face = faces.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in result_face:
cv2.rectangle(img, (x, y), (x + w, y + h), (0, 0, 255), 2)
rect = cv2.rectangle(num_img.copy(), (x, y), (x + w, y + h), 255, -1)
num_img = cv2.bitwise_and(gray, gray, mask=rect)
clahe = cv2.createCLAHE(clipLimit=6, tileGridSize=(60, 60))
lab_img = cv2.cvtColor(num_img, cv2.COLOR_GRAY2BGR)
lab = cv2.cvtColor(lab_img, cv2.COLOR_BGR2LAB)
l, a, b = cv2.split(lab)
l2 = clahe.apply(l)
lab = cv2.merge((l2, a, b))
num_img = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR)
result_smile = smile.detectMultiScale(num_img, 1.2, 100)
for (sx, sy, sw, sh) in result_smile:
cv2.rectangle(img, (sx, sy), (sx + sw, sy + sh), (255, 0, 0), 2)
return num_img, img, gray