Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
PythonRBExtensions.py
2from pathlib import Path
3import json
4
5from visp.rbt import RBTracker
6
7from visp.python.rbt.xfeat import RBXFeatFeatureTracker, XFeatVisualOdometry, XFeatTrackingBackend
8
9
11 '''
12 This class is used to keep references to Python created types:
13 If we do not do so, Python loses track of Python types that override C++ types
14 and "slices" them back to pure cpp objects when calling eg. tracker.getOdometryMethod()
15 '''
16 def __init__(self):
17 self.xfeat_backend = XFeatTrackingBackend(4096, 0.8)
18 self.extensions = []
19
20 def parse_python_extensions(self, tracker: RBTracker, json_path: Path):
21
22 with open(json_path, 'r') as json_file:
23 json_dict = json.load(json_file)
24
25 if "python_ext" not in json_dict:
26 print('No python extension found')
27 return
28
29 python_extensions = json_dict['python_ext']
30 # XFeat backend is a special case for a Python extension:
31 # Visual odometry and RBXfeatTracker.
32 # Since both depend on the same feature extraction,
33 # we use the same backend to run extraction only once.
34 if 'xfeat' in python_extensions:
35 self.xfeat_backend.load_settings(python_extensions['xfeat'])
36
37 if 'odometry' in python_extensions:
38 vo = XFeatVisualOdometry(self.xfeat_backend)
39 vo.load_settings(python_extensions['odometry'])
40 tracker.setOdometryMethod(vo)
41 self.extensions.append(vo)
42
43 if 'features' in python_extensions:
44 features_json = python_extensions['features']
45 assert isinstance(features_json, list)
46 for fj in features_json:
47 if fj['type'] == 'xfeat':
48 xfeat = RBXFeatFeatureTracker(self.xfeat_backend)
49 xfeat.load_settings(fj)
50 self.extensions.append(xfeat)
51 tracker.addTracker(xfeat)
parse_python_extensions(self, RBTracker tracker, Path json_path)