-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslam.py
executable file
·64 lines (45 loc) · 1.34 KB
/
slam.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
63
64
#!/usr/bin/env python3
import cv2
# import pygame
import sys
from display import Display
from extractor import Extractor
import numpy as np
W =1920//2
H=1080//2
F=1 # focus of camera ?
K = np.array([[F,0,W//2],[0,F,H//2],[0,0,1]])
print(K)
# SCREEN USING PYGAME
"""pygame.init()
display = pygame.display.set_mode((W, H))
pygame.display.set_caption('SLAM_python')
surface = pygame.Surface((W,H)).convert()"""
disp=Display(W ,H)
fe = Extractor(K)
def process_frame(img):
# sdl based im2vid
img = cv2.resize(img, (W,H))
matches = fe.extract(img)
for pt1, pt2 in matches:
u1,v1 = fe.denormalize(pt1)
u2,v2 = fe.denormalize(pt2)
cv2.circle(img,(u1,v1), color=(0,255,0), radius = 3)
cv2.line(img, (u1,v1), (u2,v2), color=(255,0,0))
# print(f)
disp.paint(img)
""" # surf = pygame.surfarray.make_surface(img.swapaxes(0,1)).convert() # numpy swapaxes
pygame.pixelcopy.array_to_surface(surface, img.swapaxes(0,1))
display.blit(surface, (0,0))
pygame.display.flip()
# cv2.imshow('image', img)
# cv2.waitKey(0)"""
# print(img.shape)
if __name__ == "__main__":
cap = cv2.VideoCapture("test_vid/test_1.mp4")
while cap.isOpened():
ret, frame= cap.read()
if ret == True:
process_frame(frame)
else:
break