forked from mattloper/opendr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_tests.py
50 lines (39 loc) · 1.36 KB
/
util_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
__author__ = 'matt'
from copy import deepcopy
from os.path import join, split, exists
import numpy as np
from cvwrap import cv2
from chumpy.utils import row, col
from utils import wget
def get_earthmesh(trans, rotation):
from serialization import load_mesh
from copy import deepcopy
if not hasattr(get_earthmesh, 'm'):
def wg(url):
dest = join('/tmp', split(url)[1])
if not exists(dest):
wget(url, dest)
wg('http://files.is.tue.mpg.de/mloper/opendr/images/nasa_earth.obj')
wg('http://files.is.tue.mpg.de/mloper/opendr/images/nasa_earth.mtl')
wg('http://files.is.tue.mpg.de/mloper/opendr/images/nasa_earth.jpg')
fname = join('/tmp', 'nasa_earth.obj')
mesh = load_mesh(fname)
mesh.v = np.asarray(mesh.v, order='C')
mesh.vc = mesh.v*0 + 1
mesh.v -= row(np.mean(mesh.v, axis=0))
mesh.v /= np.max(mesh.v)
mesh.v *= 2.0
get_earthmesh.mesh = mesh
mesh = deepcopy(get_earthmesh.mesh)
mesh.v = mesh.v.dot(cv2.Rodrigues(np.asarray(np.array(rotation), np.float64))[0])
mesh.v = mesh.v + row(np.asarray(trans))
return mesh
def process(im, vmin, vmax):
shape = im.shape
im = deepcopy(im).flatten()
im[im>vmax] = vmax
im[im<vmin] = vmin
im -= vmin
im /= (vmax-vmin)
im = im.reshape(shape)
return im