コード例 #1
0
def drop_corner_values(face: Face) -> None:
    """
        Erase those pixels which are too close or to far to be treated as
        valuable data.
    """
    depth_median = np.median(face.depth_img[face.mask])
    face.depth_img[face.mask] -= depth_median
    depth_stdev = np.std(face.depth_img[face.mask])
    # |allowed_dist| is the distance from the center in the maximum metric
    # which allows the any depth values
    allowed_dist = 6
    for i in range(IMG_SIZE):
        for j in range(IMG_SIZE):
            if abs(i - IMG_SIZE // 2) < allowed_dist and abs(j - IMG_SIZE //
                                                             2) < allowed_dist:
                # Too close to the center of the face to drop those values
                # (might be a very pointy nose).
                continue
            if abs(face.depth_img[i, j]) >= 2. * depth_stdev:
                face.depth_img[i, j] = 0

    depth_stdev = np.std(face.depth_img[face.mask])
    face.depth_img /= depth_stdev * 4

    mx = face.depth_img.max()
    mi = face.depth_img.min()
    if abs(mi) > abs(mx):
        face.depth_img = np.maximum(-abs(mx), face.depth_img)
    else:
        face.depth_img = np.minimum(abs(mi), face.depth_img)

    # Scale each dimension into interval 0..1
    rescale_one_dim(face.depth_img)
    rescale_one_dim(face.gir_img)
    face.depth_img *= DEPTH_TO_WIDTH_RATIO
コード例 #2
0
def recentre(face: Face) -> None:
    assert face.depth_img.shape == face.gir_img.shape
    logging.debug("\n\nRECENTRE")
    move_x = int((CENTER_DEST[0] - face.face_center[0]) * IMG_SIZE)
    move_y = int((CENTER_DEST[1] - face.face_center[1]) * IMG_SIZE)

    logging.debug("MOVE X MOVE Y %d %d" % (move_x, move_y))
    face.gir_img = np.roll(face.gir_img, move_x, axis=1)
    face.gir_img = np.roll(face.gir_img, move_y, axis=0)
    face.depth_img = np.roll(face.depth_img, move_x, axis=1)
    face.depth_img = np.roll(face.depth_img, move_y, axis=0)
    if move_x >= 0:
        face.gir_img[:, move_x] = 0
        face.depth_img[:, move_x] = 0
    else:
        face.gir_img[:, move_x:] = 0
        face.depth_img[:, move_x:] = 0
    if move_y >= 0:
        face.gir_img[:move_y, :] = 0
        face.depth_img[:move_y, :] = 0
    else:
        face.gir_img[move_y:, :] = 0
        face.depth_img[move_y:, :] = 0