예제 #1
0
def detect(input_image, output_path, use_json, annotate_faces,
           annotate_landmarks, face_color, landmark_color, save_chip):
    img = io.imread(input_image)

    d = Detector(input_image)
    d.detect()

    if use_json:
        json = []
    else:
        print '\nImage: {}'.format(input_image)
        print 'Number of cat faces detected: {}'.format(d.result.face_count)

    if annotate_faces or annotate_landmarks:
        w = img.shape[1]

    for i, face in enumerate(d.result.faces):
        shape = d.predictor(img, face)


        if save_chip:
            cropped = Image.open(input_image)
            cropped = cropped.crop((face.left(),
                                    face.top(),
                                    face.right(),
                                    face.bottom()))

            chip_path = get_output_file(output_path,
                                        input_image,
                                        '_face_{}'.format(i),
                                        'jpg')
            cropped.save(chip_path)

        if annotate_landmarks:
            draw_landmark_annotation(img, shape, landmark_color,
                                     int(w * 0.0025))

        if annotate_faces:
            draw_face_annotation(img, face, face_color, int(w * 0.005))

        if use_json:
            json.append(get_face_json(face, shape))
        else:
            print_face_info(i, face, shape)

    if d.result.face_count > 0:
        if annotate_faces or annotate_landmarks:
            filename = get_output_file(output_path,
                                       input_image,
                                       '_annotated',
                                       'jpg')

            cv2.imwrite(filename, cv2.cvtColor(img, cv2.COLOR_RGB2BGR))

    if use_json:
        print json
예제 #2
0
def get_landmarks(input_image, img, face):
    d = Detector(input_image)
    shape = d.predictor(img, face)
    return shape
예제 #3
0
def get_face(input_image, img):
    d = Detector(input_image)
    face = d.FaceDetectionDLIB(img)
    return face