-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotmap.py
More file actions
81 lines (64 loc) · 2.28 KB
/
dotmap.py
File metadata and controls
81 lines (64 loc) · 2.28 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import numpy as np
import OpenGL.GL as gl
import pangolin
from multiprocessing import Process, Queue
class Point(object):
def __init__(self, mapp, loc):
self.pt = loc
self.frames = []
self.idxs = []
self.id = len(mapp.points)
mapp.points.append(self)
def add_observation(self, frame, idx):
frame.pts[idx] = self
self.frames.append(frame)
self.idxs.append(idx)
class Map(object):
def __init__(self):
self.points = []
self.frames = []
self.state = None
self.create_viewer()
def create_viewer(self):
self.q = Queue()
self.p = Process(target=self.viewer_thread, args=(self.q,))
self.p.daemon = True
self.p.start()
def viewer_thread(self, q):
self.viewer_init(1080, 720)
while 1:
self.viewer_refresh(q)
def viewer_init(self, w, h):
pangolin.CreateWindowAndBind('Main', w, h)
gl.glEnable(gl.GL_DEPTH_TEST)
self.scam = pangolin.OpenGlRenderState(
pangolin.ProjectionMatrix(w, h, 420, 420, w//2, h//2, 0.2, 1000),
# pangolin.ProjectionMatrix(w, h, 230, 230, w//2, h//2, 0.2, 5000),
pangolin.ModelViewLookAt(0, -10, -8,
0, 0, 0,
0, -1, 0))
self.handler = pangolin.Handler3D(self.scam)
# Create Interactive View in window
self.dcam = pangolin.CreateDisplay()
self.dcam.SetBounds(0.0, 1.0, 0.0, 1.0, -w/h)
self.dcam.SetHandler(self.handler)
def viewer_refresh(self, q):
if self.state is None or not q.empty():
self.state = q.get()
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
gl.glClearColor(0.0, 0.0, 0.0, 1.0)
self.dcam.Activate(self.scam)
gl.glPointSize(5)
gl.glColor3f(0.0, 0.0, 1.0)
pangolin.DrawCameras(self.state[0])
gl.glPointSize(1)
gl.glColor3f(0.0, 1.0, 0.0)
pangolin.DrawPoints(self.state[1])
pangolin.FinishFrame()
def display(self):
poses, pts = [], []
for f in self.frames:
poses.append(f.pose)
for p in self.points:
pts.append(p.pt)
self.q.put((np.array(poses), np.array(pts)))