Created
May 12, 2018 21:56
-
-
Save Unitoi01/9b599c33edbf12924fcc25a5aceab2cd to your computer and use it in GitHub Desktop.
Read face color average
This file contains 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
import numpy as np | |
import cv2 as cv | |
import math | |
face_cascade= cv.CascadeClassifier('C:\Program Files\opencv\sources\data\haarcascades\haarcascade_frontalface_default.xml') | |
#direct path to the haarcascade, which is included in openCV | |
pic= cv.imread('face.jpg') | |
#the path to one image that OpenCV will convert to a numpy array | |
gray= cv.imread('face.jpg,0) | |
#the same as above, except we only take one channel making it gray | |
faces=face_cascade.detectMultiScale(gray,1.3,5) | |
#this is what actually detects faces | |
x1=faces[0][0] | |
x2=faces[0][2] | |
y1=faces[0][1] | |
y2= faces[0][3] | |
#x1 and y1 are the x and y components of the top left point on a rectangle around a found face. | |
#x2 and y2 are width and height respectively | |
color= np.mean(pic[x1:x1+x2, y1:y1+y2,:], axis=2) | |
#take a slice of the numpy array starting at row x1 to x1+x2 and each column starting at y1 to y1 +y2 | |
print(color) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment