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)
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)
def load_lsfm_tassos_concatenated_fw(): x = load_tassos_lsfm_combined_model( '/vol/atlas/homes/aroussos/results/fit3Dto2D/model/ver2016-12-12_LSFMfrmt_maxNpcInf/all_all_all.mat') shape_model = x['shape_model'] landmarks = m3io.import_landmark_file(TEMPLATE_LMS_PATH).from_vector(shape_model.mean().points[fw_index_for_lms()]) id_indices = np.arange(x['n_id_comps']) exp_indices = np.arange(x['n_id_comps'], shape_model.n_components) return shape_model, landmarks, id_indices, exp_indices
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)
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)
def load_basel_shape(): shape_model = mio.import_pickle('/vol/atlas/databases/lsfm/shape_PCAModel.pkl', encoding='latin1') landmarks = m3io.import_landmark_file(TEMPLATE_LMS_PATH) return shape_model, landmarks
def load_basel_concatenated_fw(): x = mio.import_pickle( '/vol/atlas/homes/jab08/tpami_computational_face/concatenated_model.pkl') shape_model = x['combined_model'] landmarks = m3io.import_landmark_file(TEMPLATE_LMS_PATH).from_vector(shape_model.mean().points[fw_index_for_lms()]) return shape_model, landmarks, x['id_indices'], x['exp_indices']
def load_fw_mean_id_expression_fw(): shape_model = mio.import_pickle('/vol/atlas/databases/lsfm/expression_model_id_mean.pkl') landmarks = m3io.import_landmark_file(TEMPLATE_LMS_PATH).lms.from_vector(shape_model.mean().points[fw_index_for_lms()]) return shape_model, landmarks
def load_basel_combined_fw(): shape_model = mio.import_pickle('/vol/atlas/databases/lsfm/basel_combined_model_fw.pkl') landmarks = m3io.import_landmark_file(TEMPLATE_LMS_PATH).from_vector(shape_model.mean().points[fw_index_for_lms()]) return shape_model, landmarks
def load_lsfm_shape_fwc(): tr = mio.import_pickle('/vol/atlas/databases/lsfm/corrective_translation.pkl') shape_model = mio.import_pickle('/vol/atlas/databases/lsfm/lsfm_shape_model_fw_cropped.pkl') landmarks = tr.apply(m3io.import_landmark_file(TEMPLATE_LMS_PATH)) return shape_model, landmarks
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")
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')
bounding_boxes = [ PointCloud(b[:4].reshape(-1, 2)[:, ::-1]).bounding_box() for b in bounding_boxes ] return bounding_boxes aam_fitter = load_balanced_frontal_face_fitter() __model_path = Path( '/vol/atlas/homes/aroussos/results/fit3Dto2D/model/ver2016-12-12_LSFMfrmt_maxNpcInf/all_all_all.mat' ) shape_model_dict = load_tassos_lsfm_combined_model(__model_path) shape_model = shape_model_dict['shape_model'] landmarks = m3io.import_landmark_file('../ibug68.ljson').lms.from_vector( shape_model.mean().lms.points[mappings.fw_index_for_lms()]) texture_model = mappings.load_itwmm_texture_fast_dsift_fw() diagonal = 185 mm = ColouredMorphableModel(shape_model, texture_model, (landmarks), holistic_features=fast_dsift, diagonal=diagonal) fitter = LucasKanadeMMFitter(mm, n_shape=200, n_texture=200, n_samples=8000, n_scales=1) def fit(imagepath):