Sample the depth map at the given coordinates using bilinear interpolation. Args: depth_map (numpy.ndarray): The depth map. x (numpy.ndarray): The real number coordinates to sample from. Returns: float: The sampled depth value; 0.0 if the coordinates are out of bounds
(depth_map, x)
| 31 | |
| 32 | |
| 33 | def sample_depth_map(depth_map, x): |
| 34 | """ |
| 35 | Sample the depth map at the given coordinates using bilinear interpolation. |
| 36 | Args: |
| 37 | depth_map (numpy.ndarray): The depth map. |
| 38 | x (numpy.ndarray): The real number coordinates to sample from. |
| 39 | Returns: |
| 40 | float: The sampled depth value; |
| 41 | 0.0 if the coordinates are out of bounds or if the sampled depth is zero. |
| 42 | """ |
| 43 | x0 = int(x[0]) |
| 44 | y0 = int(x[1]) |
| 45 | x1 = x0 + 1 |
| 46 | y1 = y0 + 1 |
| 47 | if x0 < 0 or y0 < 0 or x1 >= depth_map.shape[1] or y1 >= depth_map.shape[0]: |
| 48 | return 0.0 |
| 49 | dx = x[0] - x0 |
| 50 | dy = x[1] - y0 |
| 51 | depth = ( |
| 52 | (depth_map[y0, x0] * (1.0 - dx) + depth_map[y0, x1] * dx) * (1.0 - dy) + |
| 53 | (depth_map[y1, x0] * (1.0 - dx) + depth_map[y1, x1] * dx) * dy |
| 54 | ) |
| 55 | return depth |
| 56 | |
| 57 | |
| 58 | def loadDMAP(dmap_path: str): |