def face_img_func(key, entry, viewer):
    # Image conversion
    img = entry['img'][0]   # Use only a first data in the batch
    assert(img.ndim == 3 and (img.shape[0] == 1 or img.shape[0] == 3))
    img = np.transpose(img, (1, 2, 0))
    img = img.copy()  # for safety
    img += 0.5  # [-0.5:0.5] -> [0:1]
    # Draw
    try:
        detection_raw = entry['detection'][0]
        detection = (detection_raw > 0.5)
        if 0.0 <= detection_raw <= 1.0:
            drawing.draw_detection(img, detection)

        landmark = entry['landmark'][0]
        visibility = entry['visibility'][0]
        landmark_color = (0, 1, 0) if detection == 1 else (0, 0, 1)
        drawing.draw_landmark(img, landmark, visibility, landmark_color, 0.5)

        pose = entry['pose'][0]
        drawing.draw_pose(img, pose)

        gender = entry['gender'][0]
        if 0.0 <= gender <= 1.0:
            gender = (gender > 0.5)
            drawing.draw_gender(img, gender)

    except KeyError:
        pass

    img = (img * 255).astype(np.uint8)
    caption = '{:02d}'.format(viewer.img_cnts[key])
    return {'img': img, 'cap': caption}
예제 #2
0
    # Use first data in one batch
    img = imgs[0]
    detection = detections[0]
    landmark = landmarks[0]
    visibility = visibilitys[0]
    pose = poses[0]
    gender = genders[0]

    img = np.transpose(img, (1, 2, 0))
    img = img.copy()
    img += 0.5  # [-0.5:0.5] -> [0:1]
    detection = (detection > 0.5)
    gender = (gender > 0.5)

    # Draw results
    drawing.draw_detection(img, detection)
    landmark_color = (0, 1, 0) if detection == 1 else (0, 0, 1)
    drawing.draw_landmark(img, landmark, visibility, landmark_color, 0.5)
    drawing.draw_pose(img, pose)
    drawing.draw_gender(img, gender)

    # Show image
    logger.info('Show the result image')

    # cv2.imshow('result', img)
    # cv2.waitKey(0)
    img = img * 255
    cv2.imwrite('sample_images/lena_face1.png', img)

    print('finished at', time.time())
    print('cost time', time.time() - init_time)