Load and parse a DMAP (Depth Map) file. Args: dmap_path (str): The path to the DMAP file. Returns: A dictionary containing the parsed DMAP data.
(dmap_path: str)
| 56 | |
| 57 | |
| 58 | def loadDMAP(dmap_path: str): |
| 59 | """ |
| 60 | Load and parse a DMAP (Depth Map) file. |
| 61 | Args: |
| 62 | dmap_path (str): The path to the DMAP file. |
| 63 | Returns: |
| 64 | A dictionary containing the parsed DMAP data. |
| 65 | """ |
| 66 | with open(dmap_path, 'rb') as dmap: |
| 67 | file_type = dmap.read(2).decode() |
| 68 | content_type = np.frombuffer(dmap.read(1), dtype=np.uint8) |
| 69 | reserve = np.frombuffer(dmap.read(1), dtype=np.uint8) |
| 70 | |
| 71 | has_depth = content_type > 0 |
| 72 | has_normal = content_type in [3, 7, 11, 15] |
| 73 | has_conf = content_type in [5, 7, 13, 15] |
| 74 | has_views = content_type in [9, 11, 13, 15] |
| 75 | |
| 76 | image_width, image_height = np.frombuffer(dmap.read(8), dtype=np.uint32) |
| 77 | depth_width, depth_height = np.frombuffer(dmap.read(8), dtype=np.uint32) |
| 78 | |
| 79 | if (file_type != 'DR' or has_depth == False or depth_width <= 0 or depth_height <= 0 or image_width < depth_width or image_height < depth_height): |
| 80 | print('error: opening file \'{}\' for reading depth-data'.format(dmap_path)) |
| 81 | return |
| 82 | |
| 83 | depth_min, depth_max = np.frombuffer(dmap.read(8), dtype=np.float32) |
| 84 | |
| 85 | file_name_size = np.frombuffer(dmap.read(2), dtype=np.uint16)[0] |
| 86 | file_name = dmap.read(file_name_size).decode() |
| 87 | |
| 88 | view_ids_size = np.frombuffer(dmap.read(4), dtype=np.uint32)[0] |
| 89 | reference_view_id, *neighbor_view_ids = np.frombuffer(dmap.read(4 * view_ids_size), dtype=np.uint32) |
| 90 | |
| 91 | K = np.frombuffer(dmap.read(72), dtype=np.float64).reshape(3, 3) |
| 92 | R = np.frombuffer(dmap.read(72), dtype=np.float64).reshape(3, 3) |
| 93 | C = np.frombuffer(dmap.read(24), dtype=np.float64) |
| 94 | |
| 95 | depth_K = scale_K(K, depth_width / image_width, depth_height / image_height) |
| 96 | |
| 97 | data = { |
| 98 | 'has_normal': has_normal, |
| 99 | 'has_conf': has_conf, |
| 100 | 'has_views': has_views, |
| 101 | 'image_width': image_width, |
| 102 | 'image_height': image_height, |
| 103 | 'depth_width': depth_width, |
| 104 | 'depth_height': depth_height, |
| 105 | 'depth_min': depth_min, |
| 106 | 'depth_max': depth_max, |
| 107 | 'file_name': file_name, |
| 108 | 'reference_view_id': reference_view_id, |
| 109 | 'neighbor_view_ids': neighbor_view_ids, |
| 110 | 'depth_K': depth_K, |
| 111 | 'K': K, |
| 112 | 'R': R, |
| 113 | 'C': C |
| 114 | } |
| 115 |
no test coverage detected