Example #1
0
def get_pts_for_mirror_image(file_path, verbose=False):
    for image_file_name in mio.image_paths(file_path):
        if os.path.exists(
                os.path.splitext(str(image_file_name))[0] +
                '_mirror.jpg') and not os.path.exists(
                    os.path.splitext(str(image_file_name))[0] + '_mirror.pts'):
            img = mio.import_image(image_file_name).mirror()
            mirrored_points = []
            for i in range(68):
                unmirrored_points = img.landmarks.get('PTS').lms.points
                mirrored_points.append([
                    unmirrored_points[mirror_transfrom[i + 1] - 1][1],
                    unmirrored_points[mirror_transfrom[i + 1] - 1][0]
                ])
            if verbose:
                print('Adding mirror pts for: ' + image_file_name)

            with open(
                    os.path.splitext(str(image_file_name))[0] + '_mirror.pts',
                    'w') as f:
                f.write('version: 1\nn_points:  %d\n{\n' %
                        (len(mirrored_points)))
                for point in mirrored_points:
                    f.write('%f %f\n' % (point[0], point[1]))
                f.write('}')
Example #2
0
    def from_menpo(cls, data_dir, verbose=True):
        """
        Create class instance from directory of menpo files

        Parameters
        ----------
        data_dir: string
            path to data directory
        verbose: bool
            whether or not to print current progress

        Returns
        -------
        class instance
        """
        if verbose:
            print("Loading data from %s" % data_dir)
            wrapper_fn = tqdm
        else:

            def linear_wrapper(x):
                return x

            wrapper_fn = linear_wrapper
        img_paths = list(mio.image_paths(data_dir))

        samples = []
        for _img in wrapper_fn(img_paths):

            samples.append(
                SingleImage.from_menpo(mio.import_image(_img), img_file=_img))

        return cls(samples=samples)
Example #3
0
File: io.py Project: menpo/menpocli
def resolve_all_paths(img_paths_or_patterns):
    img_paths = set()
    for img_path_or_pattern in img_paths_or_patterns:
        if not isfile(img_path_or_pattern):
            img_paths.update(set(mio.image_paths(img_path_or_pattern)))
        else:
            img_paths.add(Path(img_path_or_pattern))
    return img_paths
Example #4
0
def test_image_paths():
    ls = mio.image_paths(mio.data_dir_path())
    assert(len(list(ls)) == 6)
Example #5
0
def test_image_paths():
    ls = mio.image_paths(mio.data_dir_path())
    assert (len(list(ls)) == 6)
Example #6
0
def kf_sequence_image_paths(i, expression):
    return LazyList.init_from_iterable(
        mio.image_paths(kf_sequence_path(i, expression)))
Example #7
0
def test_image_paths():
    ls = mio.image_paths(os.path.join(mio.data_dir_path(), '*'))
    assert(len(ls) == 5)
Example #8
0
def test_image_paths():
    ls = mio.image_paths(os.path.join(mio.data_dir_path(), '*'))
    assert(len(list(ls)) == 6)