コード例 #1
0
def test_custom_landmark_logic_bunny():
    def f(path):
        lmark_dict = {
            'no_nose': path.with_name('bunny_no_nose.ljson'),
            'full_set': path.with_name('bunny.ljson')
        }
        return menpo.io.input.resolve_from_paths(lmark_dict)

    mesh = mio.import_mesh(mio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert ('no_nose' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['no_nose']
    labels = {'reye', 'mouth', 'leye'}
    assert (len(set(lms.labels) - labels) == 0)
    assert_allclose(lms.with_labels('leye').points, bunny_leye, atol=1e-7)
    assert_allclose(lms.with_labels('reye').points, bunny_reye, atol=1e-7)
    assert_allclose(lms.with_labels('mouth').points, bunny_mouth, atol=1e-7)

    assert ('full_set' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['full_set']
    labels = {'reye', 'mouth', 'nose', 'leye'}
    assert (len(set(lms.labels) - labels) == 0)
    assert_allclose(lms.with_labels('leye').points, bunny_leye, atol=1e-7)
    assert_allclose(lms.with_labels('reye').points, bunny_reye, atol=1e-7)
    assert_allclose(lms.with_labels('nose').points, bunny_nose, atol=1e-7)
    assert_allclose(lms.with_labels('mouth').points, bunny_mouth, atol=1e-7)
コード例 #2
0
def test_custom_landmark_logic_bunny():
    def f(path):
        lmark_dict = {
            "no_nose": path.with_name("bunny_no_nose.ljson"),
            "full_set": path.with_name("bunny.ljson"),
        }
        return menpo.io.input.resolve_from_paths(lmark_dict)

    mesh = mio.import_mesh(mio.data_path_to("bunny.obj"), landmark_resolver=f)
    assert "no_nose" in mesh.landmarks.group_labels
    lms = mesh.landmarks["no_nose"]
    labels = {"reye", "mouth", "leye"}
    assert len(set(lms.labels) - labels) == 0
    assert_allclose(lms.with_labels("leye").points, bunny_leye, atol=1e-7)
    assert_allclose(lms.with_labels("reye").points, bunny_reye, atol=1e-7)
    assert_allclose(lms.with_labels("mouth").points, bunny_mouth, atol=1e-7)

    assert "full_set" in mesh.landmarks.group_labels
    lms = mesh.landmarks["full_set"]
    labels = {"reye", "mouth", "nose", "leye"}
    assert len(set(lms.labels) - labels) == 0
    assert_allclose(lms.with_labels("leye").points, bunny_leye, atol=1e-7)
    assert_allclose(lms.with_labels("reye").points, bunny_reye, atol=1e-7)
    assert_allclose(lms.with_labels("nose").points, bunny_nose, atol=1e-7)
    assert_allclose(lms.with_labels("mouth").points, bunny_mouth, atol=1e-7)
コード例 #3
0
ファイル: io_input_test.py プロジェクト: trigeorgis/menpo3d
def test_json_landmarks_bunny_direct():
    lms = mio.import_landmark_file(mio.data_path_to('bunny.ljson'))
    labels = {'reye', 'mouth', 'nose', 'leye'}
    assert (len(labels - set(lms.labels)) == 0)
    assert_allclose(lms.with_labels('leye').points, bunny_leye, atol=1e-7)
    assert_allclose(lms.with_labels('reye').points, bunny_reye, atol=1e-7)
    assert_allclose(lms.with_labels('nose').points, bunny_nose, atol=1e-7)
    assert_allclose(lms.with_labels('mouth').points, bunny_mouth, atol=1e-7)
コード例 #4
0
ファイル: io_input_test.py プロジェクト: Loubnar/menpo3d
def test_json_landmarks_bunny_direct():
    lms = mio.import_landmark_file(mio.data_path_to('bunny.ljson'))
    labels = {'reye', 'mouth', 'nose', 'leye'}
    assert(len(labels - set(lms.labels)) == 0)
    assert_allclose(lms['leye'].points, bunny_leye, atol=1e-7)
    assert_allclose(lms['reye'].points, bunny_reye, atol=1e-7)
    assert_allclose(lms['nose'].points, bunny_nose, atol=1e-7)
    assert_allclose(lms['mouth'].points, bunny_mouth, atol=1e-7)
コード例 #5
0
def test_json_landmarks_bunny_direct():
    lms = mio.import_landmark_file(mio.data_path_to("bunny.ljson"))["LJSON"]
    labels = {"reye", "mouth", "nose", "leye"}
    assert len(labels - set(lms.labels)) == 0
    assert_allclose(lms.with_labels("leye").points, bunny_leye, atol=1e-7)
    assert_allclose(lms.with_labels("reye").points, bunny_reye, atol=1e-7)
    assert_allclose(lms.with_labels("nose").points, bunny_nose, atol=1e-7)
    assert_allclose(lms.with_labels("mouth").points, bunny_mouth, atol=1e-7)
コード例 #6
0
ファイル: io_input_test.py プロジェクト: lydonchandra/menpo3d
def test_json_landmarks_bunny_direct():
    lms = mio.import_landmark_file(mio.data_path_to("bunny.ljson"))
    labels = {"reye", "mouth", "nose", "leye"}
    assert len(labels - set(lms.labels)) == 0
    assert_allclose(lms["leye"].points, bunny_leye, atol=1e-7)
    assert_allclose(lms["reye"].points, bunny_reye, atol=1e-7)
    assert_allclose(lms["nose"].points, bunny_nose, atol=1e-7)
    assert_allclose(lms["mouth"].points, bunny_mouth, atol=1e-7)
コード例 #7
0
ファイル: io_input_test.py プロジェクト: lydonchandra/menpo3d
def test_custom_landmark_logic_bunny():
    def f(mesh):
        return {"no_nose": mesh.path.with_name("bunny_no_nose.ljson"), "full_set": mesh.path.with_name("bunny.ljson")}

    mesh = mio.import_mesh(mio.data_path_to("bunny.obj"), landmark_resolver=f)
    assert "no_nose" in mesh.landmarks.group_labels
    lms = mesh.landmarks["no_nose"]
    labels = {"reye", "mouth", "leye"}
    assert len(set(lms.labels) - labels) == 0
    assert_allclose(lms["leye"].points, bunny_leye, atol=1e-7)
    assert_allclose(lms["reye"].points, bunny_reye, atol=1e-7)
    assert_allclose(lms["mouth"].points, bunny_mouth, atol=1e-7)

    assert "full_set" in mesh.landmarks.group_labels
    lms = mesh.landmarks["full_set"]
    labels = {"reye", "mouth", "nose", "leye"}
    assert len(set(lms.labels) - labels) == 0
    assert_allclose(lms["leye"].points, bunny_leye, atol=1e-7)
    assert_allclose(lms["reye"].points, bunny_reye, atol=1e-7)
    assert_allclose(lms["nose"].points, bunny_nose, atol=1e-7)
    assert_allclose(lms["mouth"].points, bunny_mouth, atol=1e-7)
コード例 #8
0
ファイル: io_input_test.py プロジェクト: Loubnar/menpo3d
def test_custom_landmark_logic_bunny():
    def f(path):
        return {
            'no_nose': path.with_name('bunny_no_nose.ljson'),
            'full_set': path.with_name('bunny.ljson')
        }
    mesh = mio.import_mesh(mio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert('no_nose' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['no_nose']
    labels = {'reye', 'mouth', 'leye'}
    assert(len(set(lms.labels) - labels) == 0)
    assert_allclose(lms['leye'].points, bunny_leye, atol=1e-7)
    assert_allclose(lms['reye'].points, bunny_reye, atol=1e-7)
    assert_allclose(lms['mouth'].points, bunny_mouth, atol=1e-7)

    assert('full_set' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['full_set']
    labels = {'reye', 'mouth', 'nose', 'leye'}
    assert(len(set(lms.labels) - labels) == 0)
    assert_allclose(lms['leye'].points, bunny_leye, atol=1e-7)
    assert_allclose(lms['reye'].points, bunny_reye, atol=1e-7)
    assert_allclose(lms['nose'].points, bunny_nose, atol=1e-7)
    assert_allclose(lms['mouth'].points, bunny_mouth, atol=1e-7)
コード例 #9
0
ファイル: io_input_test.py プロジェクト: yuxiang-zhou/menpo3d
def test_custom_landmark_logic_bunny():
    def f(mesh):
        return {
            'no_nose': mesh.path.with_name('bunny_no_nose.ljson'),
            'full_set': mesh.path.with_name('bunny.ljson')
        }

    mesh = mio.import_mesh(mio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert ('no_nose' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['no_nose']
    labels = {'reye', 'mouth', 'leye'}
    assert (len(set(lms.labels) - labels) == 0)
    assert_allclose(lms['leye'].points, bunny_leye, atol=1e-7)
    assert_allclose(lms['reye'].points, bunny_reye, atol=1e-7)
    assert_allclose(lms['mouth'].points, bunny_mouth, atol=1e-7)

    assert ('full_set' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['full_set']
    labels = {'reye', 'mouth', 'nose', 'leye'}
    assert (len(set(lms.labels) - labels) == 0)
    assert_allclose(lms['leye'].points, bunny_leye, atol=1e-7)
    assert_allclose(lms['reye'].points, bunny_reye, atol=1e-7)
    assert_allclose(lms['nose'].points, bunny_nose, atol=1e-7)
    assert_allclose(lms['mouth'].points, bunny_mouth, atol=1e-7)
コード例 #10
0
ファイル: io_input_test.py プロジェクト: trigeorgis/menpo3d
def test_custom_landmark_logic_None_bunny():
    def f(mesh):
        return None

    mesh = mio.import_mesh(mio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert (mesh.landmarks.n_groups == 0)
コード例 #11
0
ファイル: io_input_test.py プロジェクト: Loubnar/menpo3d
def test_custom_landmark_logic_None_bunny():
    def f(mesh):
        return None
    mesh = mio.import_mesh(mio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert(mesh.landmarks.n_groups == 0)
コード例 #12
0
import contextlib
import os
import tempfile
from unittest.mock import MagicMock, PropertyMock, patch

import menpo3d.io as mio

test_obj = mio.import_builtin_asset("james.obj")
test_lg = mio.import_landmark_file(mio.data_path_to("bunny.ljson"))


@contextlib.contextmanager
def _temporary_path(extension):
    # Create a temporary file and remove it
    fake_path = tempfile.NamedTemporaryFile(delete=False, suffix=extension)
    fake_path.close()
    fake_path = fake_path.name
    os.unlink(fake_path)
    yield fake_path
    if os.path.exists(fake_path):
        os.unlink(fake_path)


@patch("menpo3d.io.output.base.Path.exists")
@patch("{}.open".format(__name__), create=True)
def test_export_mesh_obj(mock_open, exists):
    exists.return_value = False
    fake_path = "/fake/fake.obj"
    with open(fake_path) as f:
        type(f).name = PropertyMock(return_value=fake_path)
        mio.export_mesh(test_obj, f, extension="obj")
コード例 #13
0
ファイル: io_export_test.py プロジェクト: Loubnar/menpo3d
from mock import patch, PropertyMock, MagicMock
import menpo3d.io as mio


test_obj = mio.import_builtin_asset('james.obj')
test_lg = mio.import_landmark_file(mio.data_path_to('bunny.ljson'))


@patch('menpo3d.io.output.base.Path.exists')
@patch('{}.open'.format(__name__), create=True)
def test_export_mesh_obj(mock_open, exists):
    exists.return_value = False
    fake_path = '/fake/fake.obj'
    with open(fake_path) as f:
        type(f).name = PropertyMock(return_value=fake_path)
        mio.export_mesh(test_obj, f, extension='obj')


@patch('menpo.image.base.PILImage')
@patch('menpo3d.io.output.base.Path.exists')
@patch('menpo.io.output.base.Path.open')
def test_export_mesh_obj_textured(mock_open, exists, PILImage):
    exists.return_value = False
    mock_open.return_value = MagicMock()
    fake_path = '/fake/fake.obj'
    mio.export_textured_mesh(test_obj, fake_path, extension='obj')
    assert PILImage.fromarray.called


@patch('menpo.io.output.landmark.json.dump')
@patch('menpo3d.io.output.base.Path.exists')