rtabmap_superpoint.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 #
3 # Drop this file in the root folder of SuperPoint git: https://github.com/magicleap/SuperPointPretrainedNetwork
4 # To use with rtabmap:
5 # --Vis/FeatureType 15 --PyDetector/Path "~/SuperPointPretrainedNetwork/rtabmap_superpoint.py" --PyDetector/Model "~/SuperPointPretrainedNetwork/superpoint_v1.pth"
6 #
7 
8 import random
9 import numpy as np
10 import torch
11 
12 #import sys
13 #import os
14 #print(os.sys.path)
15 #print(sys.version)
16 
17 from demo_superpoint import SuperPointFrontend
18 
19 torch.set_grad_enabled(False)
20 
21 device = 'cpu'
22 superpoint = []
23 
24 def init(cuda):
25  #print("SuperPoint python init()")
26 
27  global device
28  device = 'cuda' if torch.cuda.is_available() and cuda else 'cpu'
29 
30  # This class runs the SuperPoint network and processes its outputs.
31  global superpoint
32  superpoint = SuperPointFrontend(weights_path="superpoint_v1.pth",
33  nms_dist=4,
34  conf_thresh=0.015,
35  nn_thresh=1,
36  cuda=cuda)
37 
38 def detect(imageBuffer):
39  #print("SuperPoint python detect()")
40  global device
41  image = np.asarray(imageBuffer)
42  image = (image.astype('float32') / 255.)
43 
44  global superpoint
45  pts, desc, heatmap = superpoint.run(image)
46  # return float: Kpts:Nx3, Desc:NxDim
47  # use copy to make sure memory is correctly re-ordered
48  pts = np.float32(np.transpose(pts)).copy()
49  desc = np.float32(np.transpose(desc)).copy()
50  return pts, desc
51 
52 
53 if __name__ == '__main__':
54  #test
55  init(True)
56  detect(np.random.rand(640,480)*255)
rtabmap_superpoint.detect
def detect(imageBuffer)
Definition: rtabmap_superpoint.py:38
rtabmap_superpoint.init
def init(cuda)
Definition: rtabmap_superpoint.py:24
init


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:15