MCPcopy
hub / github.com/shunsukesaito/PIFu / get_render

Method get_render

lib/data/TrainDataset.py:114–245  ·  view source on GitHub ↗

Return the render data :param subject: subject name :param num_views: how many views to return :param view_id: the first view_id. If None, select a random one. :return: 'img': [num_views, C, W, H] images 'calib': [num_views, 4, 4] cali

(self, subject, num_views, yid=0, pid=0, random_sample=False)

Source from the content-addressed store, hash-verified

112 return len(self.subjects) * len(self.yaw_list) * len(self.pitch_list)
113
114 def get_render(self, subject, num_views, yid=0, pid=0, random_sample=False):
115 '''
116 Return the render data
117 :param subject: subject name
118 :param num_views: how many views to return
119 :param view_id: the first view_id. If None, select a random one.
120 :return:
121 'img': [num_views, C, W, H] images
122 'calib': [num_views, 4, 4] calibration matrix
123 'extrinsic': [num_views, 4, 4] extrinsic matrix
124 'mask': [num_views, 1, W, H] masks
125 '''
126 pitch = self.pitch_list[pid]
127
128 # The ids are an even distribution of num_views around view_id
129 view_ids = [self.yaw_list[(yid + len(self.yaw_list) // num_views * offset) % len(self.yaw_list)]
130 for offset in range(num_views)]
131 if random_sample:
132 view_ids = np.random.choice(self.yaw_list, num_views, replace=False)
133
134 calib_list = []
135 render_list = []
136 mask_list = []
137 extrinsic_list = []
138
139 for vid in view_ids:
140 param_path = os.path.join(self.PARAM, subject, '%d_%d_%02d.npy' % (vid, pitch, 0))
141 render_path = os.path.join(self.RENDER, subject, '%d_%d_%02d.jpg' % (vid, pitch, 0))
142 mask_path = os.path.join(self.MASK, subject, '%d_%d_%02d.png' % (vid, pitch, 0))
143
144 # loading calibration data
145 param = np.load(param_path, allow_pickle=True)
146 # pixel unit / world unit
147 ortho_ratio = param.item().get('ortho_ratio')
148 # world unit / model unit
149 scale = param.item().get('scale')
150 # camera center world coordinate
151 center = param.item().get('center')
152 # model rotation
153 R = param.item().get('R')
154
155 translate = -np.matmul(R, center).reshape(3, 1)
156 extrinsic = np.concatenate([R, translate], axis=1)
157 extrinsic = np.concatenate([extrinsic, np.array([0, 0, 0, 1]).reshape(1, 4)], 0)
158 # Match camera space to image pixel space
159 scale_intrinsic = np.identity(4)
160 scale_intrinsic[0, 0] = scale / ortho_ratio
161 scale_intrinsic[1, 1] = -scale / ortho_ratio
162 scale_intrinsic[2, 2] = scale / ortho_ratio
163 # Match image pixel space to image uv space
164 uv_intrinsic = np.identity(4)
165 uv_intrinsic[0, 0] = 1.0 / float(self.opt.loadSize // 2)
166 uv_intrinsic[1, 1] = 1.0 / float(self.opt.loadSize // 2)
167 uv_intrinsic[2, 2] = 1.0 / float(self.opt.loadSize // 2)
168 # Transform under image pixel space
169 trans_intrinsic = np.identity(4)
170
171 mask = Image.open(mask_path).convert('L')

Callers 1

get_itemMethod · 0.95

Calls 1

filterMethod · 0.45

Tested by

no test coverage detected