Пример #1
0
def test_ioinfo():
    # choose a random asset (all should have it!)
    img = pio.import_builtin_asset('einstein.jpg')
    path = pio.data_path_to('einstein.jpg')
    assert(img.ioinfo.filepath == path)
    assert(img.ioinfo.filename == 'einstein')
    assert(img.ioinfo.extension == '.jpg')
    assert(img.ioinfo.dir == pio.data_dir_path())
Пример #2
0
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)
Пример #3
0
def test_json_landmarks_bunny_direct():
    lms = pio.import_landmark_file(pio.data_path_to('bunny.json'))
    assert(lms.group_label == 'JSON')
    labels = {'r_eye', 'mouth', 'nose', 'l_eye'}
    assert(len(labels - set(lms.labels)) == 0)
    assert_allclose(lms['l_eye'].lms.points, bunny_l_eye, atol=1e-7)
    assert_allclose(lms['r_eye'].lms.points, bunny_r_eye, atol=1e-7)
    assert_allclose(lms['nose'].lms.points, bunny_nose, atol=1e-7)
    assert_allclose(lms['mouth'].lms.points, bunny_mouth, atol=1e-7)
Пример #4
0
def test_path():
    # choose a random asset (all should have it!)
    img = mio.import_builtin_asset('einstein.jpg')
    path = mio.data_path_to('einstein.jpg')
    assert(img.path == path)
    assert(img.path.stem == 'einstein')
    assert(img.path.suffix == '.jpg')
    assert(img.path.parent == mio.data_dir_path())
    assert(img.path.name == 'einstein.jpg')
Пример #5
0
def test_custom_landmark_resolver():
    def lmark_resolver(path):
        return {'PTS': mio.data_path_to('takeo.pts')}

    img = mio.import_image(mio.data_path_to('lenna.png'),
                           landmark_resolver=lmark_resolver)
    assert(img.has_landmarks)

    takeo_lmarks = mio.import_builtin_asset.takeo_pts()
    np.allclose(img.landmarks['PTS'].lms.points,
                takeo_lmarks.lms.points)
Пример #6
0
def test_custom_landmark_logic_bunny():
    def f(mesh):
        return {
            'no_nose': os.path.join(mesh.ioinfo.dir, 'bunny_no_nose.json'),
            'full_set': os.path.join(mesh.ioinfo.dir, 'bunny.json')
        }
    mesh = pio.import_mesh(pio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert('no_nose' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['no_nose']
    labels = {'r_eye', 'mouth', 'l_eye'}
    assert(len(set(lms.labels) - labels) == 0)
    assert_allclose(lms['l_eye'].lms.points, bunny_l_eye, atol=1e-7)
    assert_allclose(lms['r_eye'].lms.points, bunny_r_eye, atol=1e-7)
    assert_allclose(lms['mouth'].lms.points, bunny_mouth, atol=1e-7)

    assert('full_set' in mesh.landmarks.group_labels)
    lms = mesh.landmarks['full_set']
    labels = {'r_eye', 'mouth', 'nose', 'l_eye'}
    assert(len(set(lms.labels) - labels) == 0)
    assert_allclose(lms['l_eye'].lms.points, bunny_l_eye, atol=1e-7)
    assert_allclose(lms['r_eye'].lms.points, bunny_r_eye, atol=1e-7)
    assert_allclose(lms['nose'].lms.points, bunny_nose, atol=1e-7)
    assert_allclose(lms['mouth'].lms.points, bunny_mouth, atol=1e-7)
Пример #7
0
def test_custom_landmark_logic_None_bunny():
    def f(mesh):
        return None
    mesh = pio.import_mesh(pio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert(mesh.landmarks.n_groups == 0)
Пример #8
0
def test_landmark_resolver_none():
    img = mio.import_image(mio.data_path_to('lenna.png'),
                           landmark_resolver=None)
    assert (not img.has_landmarks)
Пример #9
0
import numpy as np
import sys
from numpy.testing import assert_allclose
import os
from pathlib import PosixPath, WindowsPath, Path
from mock import patch, PropertyMock, MagicMock
from nose.tools import raises

import menpo.io as mio
from menpo.io.utils import _norm_path
from menpo.image import Image
from menpo.io.output.pickle import pickle_paths_as_pure

builtins_str = '__builtin__' if sys.version_info[0] == 2 else 'builtins'

test_lg = mio.import_landmark_file(mio.data_path_to('breakingbad.pts'))
nan_lg = test_lg.copy()
nan_lg.lms.points[0, :] = np.nan
test_img = Image(np.random.random([100, 100]))
colour_test_img = Image(np.random.random([3, 100, 100]))
fake_path = '/tmp/test.fake'


@patch('menpo.io.output.base.landmark_types')
@patch('menpo.io.output.base.Path.exists')
@patch('menpo.io.output.base.Path.open')
def test_export_filepath_overwrite_exists(mock_open, exists, landmark_types):
    exists.return_value = True
    landmark_types.__contains__.return_value = True
    mio.export_landmark_file(test_lg, fake_path, overwrite=True)
    mock_open.assert_called_with('wb')
Пример #10
0
 def lmark_resolver(path):
     return {'PTS': mio.data_path_to('takeo.pts')}
Пример #11
0
import warnings
from pathlib import Path, PosixPath, WindowsPath
from unittest.mock import MagicMock, PropertyMock, patch

import numpy as np
from numpy.testing import assert_allclose
from pytest import raises

import menpo.io as mio
from menpo.image import Image
from menpo.io.output.pickle import pickle_paths_as_pure
from menpo.io.utils import _norm_path

builtins_str = "__builtin__" if sys.version_info[0] == 2 else "builtins"

test_lg = mio.import_landmark_file(mio.data_path_to("lenna.ljson"),
                                   group="LJSON")
nan_lg = test_lg.copy()
nan_lg.points[0, :] = np.nan
test_img = Image(np.random.random([100, 100]))
colour_test_img = Image(np.random.random([3, 100, 100]))
fake_path = "/tmp/test.fake"


@patch("menpo.io.output.base.landmark_types")
@patch("menpo.io.output.base.Path.exists")
@patch("menpo.io.output.base.Path.open")
def test_export_filepath_overwrite_exists(mock_open, exists, landmark_types):
    exists.return_value = True
    landmark_types.__contains__.return_value = True
    mio.export_landmark_file(test_lg, fake_path, overwrite=True)
Пример #12
0
def test_landmark_resolver_none():
    img = mio.import_image(mio.data_path_to('lenna.png'),
                           landmark_resolver=None)
    assert(not img.has_landmarks)
Пример #13
0
def test_custom_landmark_logic_None_bunny():
    def f(mesh):
        return None

    mesh = pio.import_mesh(pio.data_path_to('bunny.obj'), landmark_resolver=f)
    assert (mesh.landmarks.n_groups == 0)
Пример #14
0
from mock import MagicMock
import numpy as np
from numpy.testing import assert_allclose

from menpo.shape import PointDirectedGraph
from menpodetect.detect import (detect, menpo_image_to_uint8)
import menpo.io as mio

takeo = mio.import_builtin_asset.takeo_ppm()
takeo_uint8 = mio.import_image(mio.data_path_to('takeo.ppm'), normalize=False)
fake_box = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
fake_detector = lambda x: ([
    PointDirectedGraph.init_from_edges(
        fake_box.copy(), np.array([[0, 1], [1, 2], [2, 3], [3, 0]]))
])


def test_rescaling_image():
    takeo_copy = takeo.copy()
    ratio = 200.0 / takeo_copy.diagonal()
    pcs = detect(fake_detector, takeo_copy, image_diagonal=200)
    assert len(pcs) == 1
    assert takeo_copy.n_channels == 3
    assert takeo_copy.landmarks['object_0'].n_points == 4
    assert_allclose(takeo_copy.landmarks['object_0'].points,
                    fake_box * (1.0 / ratio),
                    atol=10e-2)


def test_passing_uint8_image():
    takeo_copy = takeo_uint8.copy()
Пример #15
0
import numpy as np
from mock import patch, PropertyMock
from nose.tools import raises
import sys

import menpo.io as mio
from menpo.image import Image

builtins_str = '__builtin__' if sys.version_info[0] == 2 else 'builtins'

test_lg = mio.import_landmark_file(mio.data_path_to('breakingbad.pts'))
nan_lg = test_lg.copy()
nan_lg.lms.points[0, :] = np.nan
test_img = Image(np.random.random([100, 100]))
fake_path = '/tmp/test.fake'


@patch('menpo.io.output.base.landmark_types')
@patch('menpo.io.output.base.Path.exists')
@patch('menpo.io.output.base.Path.open')
def test_export_filepath_overwrite_exists(mock_open, exists, landmark_types):
    exists.return_value = True
    mio.export_landmark_file(test_lg, fake_path, overwrite=True)
    mock_open.assert_called_once_with('wb')
    landmark_types.__getitem__.assert_called_once_with('.fake')
    export_function = landmark_types.__getitem__.return_value
    export_function.assert_called_once()


@patch('menpo.io.output.base.landmark_types')
@patch('menpo.io.output.base.Path.exists')
Пример #16
0
from numpy.testing import assert_allclose
import os
from pathlib import PosixPath, WindowsPath, Path
from mock import patch, PropertyMock, MagicMock
from nose.tools import raises


import menpo.io as mio
from menpo.io.utils import _norm_path
from menpo.image import Image
from menpo.io.output.pickle import pickle_paths_as_pure


builtins_str = '__builtin__' if sys.version_info[0] == 2 else 'builtins'

test_lg = mio.import_landmark_file(mio.data_path_to('lenna.ljson'))
nan_lg = test_lg.copy()
nan_lg.points[0, :] = np.nan
test_img = Image(np.random.random([100, 100]))
colour_test_img = Image(np.random.random([3, 100, 100]))
fake_path = '/tmp/test.fake'


@patch('menpo.io.output.base.landmark_types')
@patch('menpo.io.output.base.Path.exists')
@patch('menpo.io.output.base.Path.open')
def test_export_filepath_overwrite_exists(mock_open, exists, landmark_types):
    exists.return_value = True
    landmark_types.__contains__.return_value = True
    mio.export_landmark_file(test_lg, fake_path, overwrite=True)
    mock_open.assert_called_with('wb')
Пример #17
0
from mock import MagicMock
import numpy as np
from numpy.testing import assert_allclose

from menpo.shape import PointDirectedGraph
from menpodetect.detect import (detect, menpo_image_to_uint8)
import menpo.io as mio


takeo = mio.import_builtin_asset.takeo_ppm()
takeo_uint8 = mio.import_image(mio.data_path_to('takeo.ppm'), normalize=False)
fake_box = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
fake_detector = lambda x: ([PointDirectedGraph.init_from_edges(
    fake_box.copy(),
    np.array([[0, 1], [1, 2], [2, 3], [3, 0]]))])


def test_rescaling_image():
    takeo_copy = takeo.copy()
    ratio = 200.0 / takeo_copy.diagonal()
    pcs = detect(fake_detector, takeo_copy, image_diagonal=200)
    assert len(pcs) == 1
    assert takeo_copy.n_channels == 3
    assert takeo_copy.landmarks['object_0'][None].n_points == 4
    assert_allclose(takeo_copy.landmarks['object_0'][None].points,
                    fake_box * (1.0 / ratio), atol=10e-2)


def test_passing_uint8_image():
    takeo_copy = takeo_uint8.copy()
    pcs = detect(fake_detector, takeo_copy, greyscale=False)
Пример #18
0
 def lmark_resolver(path):
     return {'PTS': mio.data_path_to('takeo.pts')}
Пример #19
0
 def lmark_resolver(path):
     return mio.import_landmark_file(mio.data_path_to("takeo.pts"))