深度学习与人脸识别之-脸部分割与校正

1.检测脸部

def read_im_and_landmarks(fname):
    if not osp.exists(fname):
        raise Exception('Cannot find image file: {}'.format(fname))

    im = cv2.imread(fname, cv2.IMREAD_COLOR)
    im = cv2.resize(im, (im.shape[1] * SCALE_FACTOR,
                         im.shape[0] * SCALE_FACTOR))
    s = get_landmarks(im)

    return im, s

2.校正脸部

def calibrate(frame):
    
    frame_new = numpy.clip(frame,0,255)
    frame_new = numpy.uint8(frame_new)
    frame_new = cv2.cvtColor(frame_new,cv2.COLOR_BGR2RGB)
    dets = predictor_calibrate(frame_new, 1)
    
    num_faces = len(dets)
    if num_faces == 0:
        print("Sorry, there were no faces found in current frame")
        return None
    faces = dlib.full_object_detections()
    for detection in dets:
        faces.append(sp(frame_new, detection))
    images = dlib.get_face_chips(frame_new, faces, size=150)
    
    return images

 

3.脸部分割效果:

深度学习与人脸识别之-脸部分割与校正_第1张图片

4.脸部校正效果

深度学习与人脸识别之-脸部分割与校正_第2张图片

你可能感兴趣的:(深度学习)