-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_depth_renderer.py
140 lines (140 loc) · 4.75 KB
/
test_depth_renderer.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# from renderer import DepthRenderer
# import numpy as np
# import unittest
#
#
# visualize = False
#
# class TestDepthRenderer(unittest.TestCase):
#
# def setUp(self):
# np.random.seed(0)
#
# def test_depth_image(self):
# # Create renderer
# import chumpy as ch
# from renderer import DepthRenderer
# rn = DepthRenderer()
#
# # Assign attributes to renderer
# from util_tests import get_earthmesh
# m = get_earthmesh(trans=ch.array([0,0,0]), rotation=ch.zeros(3))
# m.v = m.v * .01
# m.v[:,2] += 4
# w, h = (320, 240)
# from camera import ProjectPoints
# rn.camera = ProjectPoints(v=m.v, rt=ch.zeros(3), t=ch.zeros(3), f=ch.array([w,w])/2., c=ch.array([w,h])/2., k=ch.zeros(5))
# rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
# rn.set(v=m.v, f=m.f, vc=m.vc*0+1, bgcolor=ch.zeros(3))
#
# # import time
# # tm = time.time()
# # rn.r
# # print 'took %es' % (time.time() - tm)
#
# # print np.min(rn.r.ravel())
# # print np.max(rn.r.ravel())
# self.assertLess(np.abs(np.min(rn.r.ravel()) - 3.98), 1e-5)
# self.assertLess(np.abs(np.min(m.v[:,2]) - np.min(rn.r.ravel())), 1e-5)
# self.assertLess(np.abs(rn.r[h/2,w/2] - 3.98), 1e-5)
#
# def test_derivatives(self):
# import chumpy as ch
# from chumpy.utils import row
# import numpy as np
# from renderer import DepthRenderer
#
# rn = DepthRenderer()
#
# # Assign attributes to renderer
# from util_tests import get_earthmesh
# m = get_earthmesh(trans=ch.array([0,0,4]), rotation=ch.zeros(3))
# w, h = (320, 240)
# from camera import ProjectPoints
# rn.camera = ProjectPoints(v=m.v, rt=ch.zeros(3), t=ch.zeros(3), f=ch.array([w,w])/2., c=ch.array([w,h])/2., k=ch.zeros(5))
# rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
# rn.set(v=m.v, f=m.f, bgcolor=ch.zeros(3))
#
# if visualize:
# import matplotlib.pyplot as plt
# plt.figure()
# for which in range(3):
# r1 = rn.r
#
# adder = np.zeros(3)
# adder[which] = .01
# change = rn.v.r * 0 + row(adder)
# dr_pred = rn.dr_wrt(rn.v).dot(change.ravel()).reshape(rn.shape)
# rn.v = rn.v.r + change
#
# r2 = rn.r
# dr_emp = r2 - r1
#
# # print np.mean(np.abs(dr_pred-dr_emp))
#
# self.assertLess(np.mean(np.abs(dr_pred-dr_emp)), .031)
#
# if visualize:
# plt.subplot(2,3,which+1)
# plt.imshow(dr_pred)
# plt.clim(-.01,.01)
# plt.title('emp')
# plt.subplot(2,3,which+4)
# plt.imshow(dr_emp)
# plt.clim(-.01,.01)
# plt.title('pred')
#
# def test_derivatives2(self):
# import chumpy as ch
# import numpy as np
# from renderer import DepthRenderer
#
# rn = DepthRenderer()
#
# # Assign attributes to renderer
# from util_tests import get_earthmesh
# m = get_earthmesh(trans=ch.array([0,0,4]), rotation=ch.zeros(3))
# w, h = (320, 240)
# from camera import ProjectPoints
# rn.camera = ProjectPoints(v=m.v, rt=ch.zeros(3), t=ch.zeros(3), f=ch.array([w,w])/2., c=ch.array([w,h])/2., k=ch.zeros(5))
# rn.frustum = {'near': 1., 'far': 10., 'width': w, 'height': h}
# rn.set(v=m.v, f=m.f, bgcolor=ch.zeros(3))
#
# if visualize:
# import matplotlib.pyplot as plt
# plt.ion()
# plt.figure()
#
# for which in range(3):
# r1 = rn.r
#
# adder = np.random.rand(rn.v.r.size).reshape(rn.v.r.shape)*.01
# change = rn.v.r * 0 + adder
# dr_pred = rn.dr_wrt(rn.v).dot(change.ravel()).reshape(rn.shape)
# rn.v = rn.v.r + change
#
# r2 = rn.r
# dr_emp = r2 - r1
#
# #print np.mean(np.abs(dr_pred-dr_emp))
#
# self.assertLess(np.mean(np.abs(dr_pred-dr_emp)), .024)
#
# if visualize:
# plt.subplot(2,3,which+1)
# plt.imshow(dr_pred)
# plt.clim(-.01,.01)
# plt.title('emp')
# plt.subplot(2,3,which+4)
# plt.imshow(dr_emp)
# plt.clim(-.01,.01)
# plt.title('pred')
# plt.draw()
# plt.show()
#
# if __name__ == '__main__':
# visualize = True
# #unittest.main()
# suite = unittest.TestLoader().loadTestsFromTestCase(TestDepthRenderer)
# unittest.TextTestRunner(verbosity=2).run(suite)
# import pdb; pdb.set_trace()