Load camera from a json file. Json file format: H_c2w: (b, q, 4, 4), a nested list containing the camera pose in the world coord. `b` is the batch dimension, `q` is number of camera poses in a batch. For example, `H_c2w[i,
(
self,
filename: str,
device: torch.device = torch.device('cpu'),
)
| 1708 | setattr(self, name, state_dict.get(name, None)) |
| 1709 | |
| 1710 | def load_json( |
| 1711 | self, |
| 1712 | filename: str, |
| 1713 | device: torch.device = torch.device('cpu'), |
| 1714 | ) -> 'Camera': |
| 1715 | """ |
| 1716 | Load camera from a json file. |
| 1717 | |
| 1718 | Json file format: |
| 1719 | H_c2w: |
| 1720 | (b, q, 4, 4), a nested list containing the camera pose in the world coord. |
| 1721 | `b` is the batch dimension, `q` is number of camera poses in a batch. |
| 1722 | For example, `H_c2w[i,j]` is the 4x4 camera pose matrix that converts |
| 1723 | a point in the camera coordinate to the world coordinate. |
| 1724 | intrinsic: |
| 1725 | (b, q, 3, 3) a nested list containing the 3x3 camera intrinsic matrices. |
| 1726 | width_px: |
| 1727 | int, number of pixels in width (horizontal) |
| 1728 | height_px: |
| 1729 | int, number of pixels in height (vertical) |
| 1730 | """ |
| 1731 | |
| 1732 | with open(filename, 'r') as f: |
| 1733 | d = json.load(f) |
| 1734 | |
| 1735 | if 'H_c2w' in d: |
| 1736 | H_c2w = torch.tensor(d['H_c2w'], dtype=torch.float, device=device) |
| 1737 | else: |
| 1738 | H_c2w = None |
| 1739 | |
| 1740 | if 'intrinsic' in d: |
| 1741 | intrinsic = torch.tensor(d['intrinsic'], dtype=torch.float, device=device) |
| 1742 | else: |
| 1743 | intrinsic = None |
| 1744 | |
| 1745 | return Camera( |
| 1746 | H_c2w=H_c2w, |
| 1747 | intrinsic=intrinsic, |
| 1748 | width_px=d.get('width_px', None), |
| 1749 | height_px=d.get('height_px', None), |
| 1750 | ) |
| 1751 | |
| 1752 | def get_H_w2c(self) -> torch.Tensor: |
| 1753 | """ |