forked from markoelez/pyslam
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.py
executable file
·63 lines (45 loc) · 1.43 KB
/
loader.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
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
import numpy as np
import cv2
import os
import time
from display import Display2D
from collections import defaultdict, namedtuple
class ImageReader:
def __init__(self, ids):
self.ids = ids
self.idx = 0
def read(self, path):
img = cv2.imread(path)
return img
def __getitem__(self, idx):
self.idx = idx
img = self.read(self.ids[idx])
return np.array(img)
def __len__(self):
return len(self.ids)
class KittiLoader:
def __init__(self, path):
Cam = namedtuple('cam', 'fx fy cx cy width height')
self.cam = Cam(718.856, 718.856, 607.1928, 185.2157, 1241, 376)
# expand to absolute path
path = os.path.expanduser(path)
self.left = ImageReader(self.listdir(os.path.join(path, 'image_0')))
self.right = ImageReader(self.listdir(os.path.join(path, 'image_1')))
assert len(self.left) == len(self.right)
def listdir(self, dir):
files = [_ for _ in os.listdir(dir) if _.endswith('.png')]
return [os.path.join(dir, _) for _ in self.sort(files)]
def sort(self, xs):
return sorted(xs, key=lambda x:float(x[:-4]))
def __getitem__(self, idx):
return self.left[idx]
def __len__(self):
return len(self.left)
if __name__ == '__main__':
display = Display2D(1241, 376)
t = KittiDataReader('~/Desktop/pyslam/dataset/sequences/00')
for i in range(len(t.left)):
path = t.left.ids[i]
img = np.array(cv2.imread(path))
display.paint(img)