Created
December 6, 2016 14:21
-
-
Save datitran/12b7171ffc615bda04c5c2e691ad41f4 to your computer and use it in GitHub Desktop.
Detect faces function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def detect_faces(image): | |
| faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") | |
| img = Image.open(StringIO(image)) | |
| img_cv2 = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2RGBA) | |
| gray = cv2.cvtColor(img_cv2, cv2.COLOR_RGBA2GRAY) | |
| faces = faceCascade.detectMultiScale( | |
| gray, | |
| scaleFactor=1.1, | |
| minNeighbors=5, | |
| minSize=(30, 30), | |
| flags=cv2.cv.CV_HAAR_SCALE_IMAGE | |
| ) | |
| try: | |
| return faces.tolist() | |
| except: | |
| return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment