예제 #1
0
def recognizeFace(image, faceCascade, eyeCascade, faceSize, threshold,
                  recognizer):
    found_faces = []

    gray, faces = detect.detectFaces(image,
                                     faceCascade,
                                     eyeCascade,
                                     returnGray=1)

    # If faces are found, try to recognize them
    for ((x, y, w, h), eyedim) in faces:
        # confidence formula: distance = 1.0f - sqrt( distSq / (float)(nTrainFaces * nEigens) ) / 255.0f
        label, confidence = recognizer.predict(
            cv2.resize(detect.levelFace(gray, ((x, y, w, h), eyedim)),
                       faceSize))
        print "label"
        print label

        # note that for some distributions of python-opencv, the predict function
        # returns the label only.
        #label = recognizer.predict(cv2.resize(detect.levelFace(gray, ((x, y, w, h), eyedim)), faceSize))
        #confidence = -1
        # if confidence < threshold:
        found_faces.append((label, confidence, (x, y, w, h)))

    return found_faces
예제 #2
0
def RecognizeFace(image, faceCascade, eyeCascade, faceSize, threshold):
    found_faces = []
    recognizer = train.trainRecognizer("train", faceSize, showFaces=True)
    gray, faces = detect.detectFaces(image, faceCascade, eyeCascade, returnGray=1)
    for ((x, y, w, h), eyedim)  in faces:
        label, confidence = recognizer.predict(cv2.resize(detect.levelFace(gray, ((x, y, w, h), eyedim)), faceSize))
        if confidence < threshold:
            found_faces.append((label, confidence, (x, y, w, h)))

    return found_faces
예제 #3
0
 def extractFaces(self,image,levelFace=False):
     faceCascade = cv2.CascadeClassifier(config.FACE_CASCADE_FILE)
     eyeCascade = cv2.CascadeClassifier(config.EYE_CASCADE_FILE)
     
     result = []
     img, faces = detect.detectFaces(image, faceCascade, eyeCascade, True)
     for ((x, y, w, h), eyedim) in faces:
         if not levelFace:
             result.append(img[y:y+h, x:x+w])
         else:
             result.append(detect.levelFace(img, ((x, y, w, h), eyedim)))
     return result
예제 #4
0
    def extractFaces(self, image, levelFace=False):
        faceCascade = cv2.CascadeClassifier(config.FACE_CASCADE_FILE)
        eyeCascade = cv2.CascadeClassifier(config.EYE_CASCADE_FILE)

        result = []
        img, faces = detect.detectFaces(image, faceCascade, eyeCascade, True)
        for ((x, y, w, h), eyedim) in faces:
            if not levelFace:
                result.append(img[y:y + h, x:x + w])
            else:
                result.append(detect.levelFace(img, ((x, y, w, h), eyedim)))
        return result
예제 #5
0
def RecognizeFace(image, faceCascade, eyeCascade, faceSize, threshold):
    found_faces = []

    gray, faces = detect.detectFaces(image, faceCascade, eyeCascade, returnGray=1)

    # If faces are found, try to recognize them
    for ((x, y, w, h), eyedim)  in faces:
        label, confidence = recognizer.predict(cv2.resize(detect.levelFace(gray, ((x, y, w, h), eyedim)), faceSize))
        # note that for some distributions of python-opencv, the predict function
        # returns the label only.
        #label = recognizer.predict(cv2.resize(detect.levelFace(gray, ((x, y, w, h), eyedim)), faceSize))
        #confidence = -1
        if confidence < threshold:
            found_faces.append((label, confidence, (x, y, w, h)))

    return found_faces
예제 #6
0
def extractFaces(a_dir, folder, levelFace=False):
    faceCascade = cv2.CascadeClassifier(config.FACE_CASCADE_FILE)
    eyeCascade = cv2.CascadeClassifier(config.EYE_CASCADE_FILE)

    the_path = join(a_dir, folder)
    result = []

    for img in [f for f in os.listdir(the_path) if supportedImg(f)]:
        img_path = join(the_path, img)
        image, faces = detect.detectFaces(cv2.imread(img_path), faceCascade, eyeCascade, True)
        if len(faces) == 0:
            print("No face found in " + img_path)
        for ((x, y, w, h), eyedim) in faces:
            if not levelFace:
                result.append(image[y:y+h, x:x+w])
            else:
                result.append(detect.levelFace(image, ((x, y, w, h), eyedim)))
                #result.append(image[y:y+h, x:x+w])
    return result
예제 #7
0
def extractFaces(a_dir, folder, levelFace=False):
    faceCascade = cv2.CascadeClassifier('cascades/haarcascade_frontalface_alt2.xml')
    eyeCascade = cv2.CascadeClassifier('cascades/haarcascade_eye.xml')

    the_path = join(a_dir, folder)
    result = []

    for img in [f for f in os.listdir(the_path) if supportedImg(f)]:
        img_path = join(the_path, img)
        image, faces = detect.detectFaces(cv2.imread(img_path), faceCascade, eyeCascade, True)
        print(len(faces))
        if len(faces) == 0:
            print("No face found in " + img_path)
        for ((x, y, w, h), eyedim) in faces:
            if not levelFace:
                result.append(image[y:y+h, x:x+w])
            else:
                result.append(detect.levelFace(image, ((x, y, w, h), eyedim)))
                #result.append(image[y:y+h, x:x+w])
    return result