You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I have recently been trying to train my mesh to ground truth by using the normals of some images in the COLMAP dataset, specifically, the camera information that provides each view in the dataset: cameras.txt contains the camera's internal information, images.txt contains the camera's external parameters. The dataset can be downloaded through Google Drive. I calculated the view and projection matrices using the following functions.
import numpy as np
from scipy.spatial.transform import Rotation as R
import torch
def get_mv_proj(path):
with open((path + '/cameras.txt'), 'r') as cam_file:
for line in cam_file:
if line.startswith('#') or len(line.strip()) == 0:
continue
parts = line.split()
camera_id = int(parts[0])
model = parts[1]
width = int(parts[2])
height = int(parts[3])
f_x, f_y, c_x, c_y = map(float, parts[4:])
break
image_data = []
with open((path + '/images.txt'), 'r') as img_file:
for line in img_file:
if line.endswith('.png\n'):
parts = line.split()
image_id = int(parts[0])
qw, qx, qy, qz = map(float, parts[1:5])
tx, ty, tz = map(float, parts[5:8])
camera_id = int(parts[8])
name = parts[9]
image_data.append((name, qw, qx, qy, qz, tx, ty, tz))
else:
continue
image_data.sort(key=lambda x: x[0])
mv = []
proj = []
for data in image_data:
_, qw, qx, qy, qz, tx, ty, tz = data
q = [qw, qx, qy, qz]
rotation_matrix = R.from_quat(q).as_matrix()
view_matrix = np.eye(4)
view_matrix[:3, :3] = rotation_matrix.T
view_matrix[:3, 3] = -rotation_matrix.T @ np.array([tx, ty, tz])
mv.append(view_matrix)
near, far = 0.1, 100.0
projection_matrix = np.zeros((4, 4))
projection_matrix[0, 0] = 2 * f_x / width
projection_matrix[1, 1] = 2 * f_y / height
projection_matrix[0, 2] = 2 * c_x / width - 1
projection_matrix[1, 2] = 2 * c_y / height - 1
projection_matrix[2, 2] = -(far + near) / (far - near)
projection_matrix[2, 3] = -(2 * far * near) / (far - near)
projection_matrix[3, 2] = -1
proj.append(projection_matrix)
view_matrices_tensor = torch.tensor(mv, dtype=torch.float32, device='cuda')
projection_matrices_tensor = torch.tensor(proj, dtype=torch.float32, device='cuda')
return view_matrices_tensor, projection_matrices_tensor
When I pass the resulting matrix into an nvdiffrast-based renderer, I seem to have gotten the wrong view (It was either black, and all pixels are zero, or only part of the mesh was visible). The renderer is constructed as follows:
I wonder if this is because the coordinates of nvdiffrast are different from those in colmap? How Do I get the right projection matrix and view matrix?
The text was updated successfully, but these errors were encountered:
Hello! I have recently been trying to train my mesh to ground truth by using the normals of some images in the COLMAP dataset, specifically, the camera information that provides each view in the dataset: cameras.txt contains the camera's internal information, images.txt contains the camera's external parameters. The dataset can be downloaded through Google Drive. I calculated the view and projection matrices using the following functions.
When I pass the resulting matrix into an nvdiffrast-based renderer, I seem to have gotten the wrong view (It was either black, and all pixels are zero, or only part of the mesh was visible). The renderer is constructed as follows:
I wonder if this is because the coordinates of nvdiffrast are different from those in colmap? How Do I get the right projection matrix and view matrix?
The text was updated successfully, but these errors were encountered: