Args: imgs: [N V C H W] depths: [N V H W] poses: w2c c2w intrinsic [N V 4 4] [B V levels 3 3)] init_depth_min: [B D H W] depth_interval: N_rays: int N_samples: same as D int level: int 0 == smalest near_fars: [B D 2]
(imgs, depths, pose_ref, w2cs, c2ws, intrinsics, near_fars, N_rays, N_samples, pad=0, is_precrop_iters=False, ref_idx=0, importanceSampling=False, with_depth=False, is_volume=False)
| 146 | return point_samples_pixel |
| 147 | |
| 148 | def build_rays(imgs, depths, pose_ref, w2cs, c2ws, intrinsics, near_fars, N_rays, N_samples, pad=0, is_precrop_iters=False, ref_idx=0, importanceSampling=False, with_depth=False, is_volume=False): |
| 149 | ''' |
| 150 | |
| 151 | Args: |
| 152 | imgs: [N V C H W] |
| 153 | depths: [N V H W] |
| 154 | poses: w2c c2w intrinsic [N V 4 4] [B V levels 3 3)] |
| 155 | init_depth_min: [B D H W] |
| 156 | depth_interval: |
| 157 | N_rays: int |
| 158 | N_samples: same as D int |
| 159 | level: int 0 == smalest |
| 160 | near_fars: [B D 2] |
| 161 | |
| 162 | Returns: |
| 163 | [3 N_rays N_samples] |
| 164 | ''' |
| 165 | |
| 166 | device = imgs.device |
| 167 | |
| 168 | N, V, C, H, W = imgs.shape |
| 169 | w2c_ref, intrinsic_ref = pose_ref['w2cs'][ref_idx], pose_ref['intrinsics'][ref_idx] # assume camera 0 is reference |
| 170 | inv_scale = torch.tensor([W-1, H-1]).to(device) |
| 171 | |
| 172 | ray_coordinate_ref = [] |
| 173 | near_ref, far_ref = pose_ref['near_fars'][ref_idx, 0], pose_ref['near_fars'][ref_idx, 1] |
| 174 | ray_coordinate_world, ray_dir_world, colors, depth_candidates = [],[],[],[] |
| 175 | rays_os, rays_ds, cos_angles, rays_depths = [],[],[],[] |
| 176 | |
| 177 | for i in range(V-1,V): |
| 178 | intrinsic = intrinsics[i] #!!!!!! assuming batch size equal to 1 |
| 179 | c2w, w2c = c2ws[i].clone(), w2cs[i].clone() |
| 180 | |
| 181 | rays_o, rays_d, pixel_coordinates = get_rays_mvs(H, W, intrinsic, c2w, N_rays, is_precrop_iters=is_precrop_iters) # [N_rays 3] |
| 182 | |
| 183 | |
| 184 | # direction |
| 185 | ray_dir_world.append(rays_d) # toward camera [N_rays 3] |
| 186 | |
| 187 | # position |
| 188 | rays_o = rays_o.reshape(1, 3) |
| 189 | rays_o = rays_o.expand(N_rays, -1) |
| 190 | rays_os.append(rays_o) |
| 191 | |
| 192 | # colors |
| 193 | pixel_coordinates_int = pixel_coordinates.long() |
| 194 | color = imgs[0, i, :, pixel_coordinates_int[0], pixel_coordinates_int[1]] # [3 N_rays] |
| 195 | colors.append(color) |
| 196 | |
| 197 | if depths.shape[2] != 1: |
| 198 | rays_depth = depths[0,i,pixel_coordinates_int[0], pixel_coordinates_int[1]] |
| 199 | rays_depths.append(rays_depth) |
| 200 | |
| 201 | # travel along the rays |
| 202 | if with_depth: |
| 203 | depth_candidate = near_fars[pixel_coordinates_int[0], pixel_coordinates_int[1]].reshape(-1,1) # [ray_samples N_samples] |
| 204 | else: |
| 205 | if importanceSampling: |
no test coverage detected