Spaces:
Runtime error
Runtime error
Download engine/pose_estimation/pose_utils/inference_utils.py from 3DAIGC/LHM: direct link, hf CLI and curl.
- Browser
- Download file 712 Bytes
-
https://huggingface.co/spaces/3DAIGC/LHM/resolve/refs%2Fpr%2F6/engine/pose_estimation/pose_utils/inference_utils.py
- Command line
-
hf download hf://spaces/3DAIGC/LHM@refs/pr/6/engine/pose_estimation/pose_utils/inference_utils.py
-
curl -L -o inference_utils.py https://huggingface.co/spaces/3DAIGC/LHM/resolve/refs%2Fpr%2F6/engine/pose_estimation/pose_utils/inference_utils.py
712 Bytes
| import os | |
| import torch | |
| from pose_utils.camera import get_focalLength_from_fieldOfView | |
| def get_camera_parameters(img_size, fov=60, p_x=None, p_y=None, device=torch.device("cuda")): | |
| """Given image size, fov and principal point coordinates, return K the camera parameter matrix""" | |
| K = torch.eye(3) | |
| # Get focal length. | |
| focal = get_focalLength_from_fieldOfView(fov=fov, img_size=img_size) | |
| K[0, 0], K[1, 1] = focal, focal | |
| # Set principal point | |
| if p_x is not None and p_y is not None: | |
| K[0, -1], K[1, -1] = p_x * img_size, p_y * img_size | |
| else: | |
| K[0, -1], K[1, -1] = img_size // 2, img_size // 2 | |
| # Add batch dimension | |
| K = K.unsqueeze(0).to(device) | |
| return K | |