-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_util.py
50 lines (34 loc) · 1.4 KB
/
data_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import cv2 as cv
import os
import matplotlib.pyplot as plt
class FountainDataset:
def __init__(self, root_path):
self.root_path = root_path
self.number_poses = 10
def read_image(self, pose_number):
file_path = os.path.join(self.root_path, 'fountain_dense_images', "{}.png".format(str(pose_number).zfill(4)))
image = cv.imread(filename=file_path)
image = cv.cvtColor(src=image, code=cv.COLOR_BGR2RGB)
return image
def read_camera_parameters(self, pose_number):
file_path = os.path.join(self.root_path, 'fountain_dense_cameras', "{}.png.camera".format(str(pose_number).zfill(4)))
# open file containing camera parameters
with open(file_path, 'r') as file:
lines = file.readlines()
# Read intrinsic matrix (3x3)
intrinsic_matrix = np.array([list(map(float, lines[i].split())) for i in range(3)])
# Read sensor resolution (2 elements)
resolution = tuple(map(int, lines[8].split()))
return {
'intrinsic_matrix': intrinsic_matrix,
'resolution': resolution
}
if __name__ == '__main__':
# Example usage
dataset = FountainDataset(root_path='./data/')
camera_params = dataset.read_camera_parameters(pose_number=1)
print(camera_params)
img = dataset.read_image(pose_number=1)
plt.imshow(img)
plt.show()