@openhps/openvslam 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +115 -2
  3. package/cc/config.cc +49 -0
  4. package/cc/config.h +24 -0
  5. package/cc/frame_publisher.cc +62 -0
  6. package/cc/frame_publisher.h +27 -0
  7. package/cc/graph_node.cc +78 -0
  8. package/cc/graph_node.h +26 -0
  9. package/cc/keyframe.cc +81 -0
  10. package/cc/keyframe.h +27 -0
  11. package/cc/landmark.cc +85 -0
  12. package/cc/landmark.h +26 -0
  13. package/cc/map_publisher.cc +119 -0
  14. package/cc/map_publisher.h +33 -0
  15. package/cc/openvslam.cc +26 -0
  16. package/cc/pangolin_viewer/viewer.h +26 -0
  17. package/cc/socket_publisher/publisher.cc +84 -0
  18. package/cc/socket_publisher/publisher.h +26 -0
  19. package/cc/system.cc +190 -0
  20. package/cc/system.h +47 -0
  21. package/dist/cjs/data/VSLAMFrame.js +44 -0
  22. package/dist/cjs/data/VSLAMFrame.js.map +1 -0
  23. package/dist/cjs/data/VSLAMGraphNode.js +7 -0
  24. package/dist/cjs/data/VSLAMGraphNode.js.map +1 -0
  25. package/dist/cjs/data/VSLAMKeyFrame.js +56 -0
  26. package/dist/cjs/data/VSLAMKeyFrame.js.map +1 -0
  27. package/dist/cjs/data/VSLAMLandmark.js +53 -0
  28. package/dist/cjs/data/VSLAMLandmark.js.map +1 -0
  29. package/dist/cjs/data/VSLAMMap.js +36 -0
  30. package/dist/cjs/data/VSLAMMap.js.map +1 -0
  31. package/dist/cjs/data/index.js +8 -0
  32. package/dist/cjs/data/index.js.map +1 -0
  33. package/dist/cjs/index.js +9 -0
  34. package/dist/cjs/index.js.map +1 -0
  35. package/dist/cjs/nodes/VSLAMConfiguration.js +43 -0
  36. package/dist/cjs/nodes/VSLAMConfiguration.js.map +1 -0
  37. package/dist/cjs/nodes/index.js +7 -0
  38. package/dist/cjs/nodes/index.js.map +1 -0
  39. package/dist/cjs/nodes/processing/VSLAMProcessingNode.js +124 -0
  40. package/dist/cjs/nodes/processing/VSLAMProcessingNode.js.map +1 -0
  41. package/dist/cjs/nodes/processing/index.js +5 -0
  42. package/dist/cjs/nodes/processing/index.js.map +1 -0
  43. package/dist/cjs/nodes/sink/VSLAMSocketPublisher.js +68 -0
  44. package/dist/cjs/nodes/sink/VSLAMSocketPublisher.js.map +1 -0
  45. package/dist/cjs/nodes/sink/index.js +5 -0
  46. package/dist/cjs/nodes/sink/index.js.map +1 -0
  47. package/dist/cjs/package.json +3 -0
  48. package/dist/cjs/service/VSLAMService.js +121 -0
  49. package/dist/cjs/service/VSLAMService.js.map +1 -0
  50. package/dist/cjs/service/index.js +5 -0
  51. package/dist/cjs/service/index.js.map +1 -0
  52. package/dist/cjs/tsconfig.bundle.cjs.tsbuildinfo +1 -0
  53. package/dist/esm/data/VSLAMFrame.js +41 -0
  54. package/dist/esm/data/VSLAMFrame.js.map +1 -0
  55. package/dist/esm/data/VSLAMGraphNode.js +3 -0
  56. package/dist/esm/data/VSLAMGraphNode.js.map +1 -0
  57. package/dist/esm/data/VSLAMKeyFrame.js +53 -0
  58. package/dist/esm/data/VSLAMKeyFrame.js.map +1 -0
  59. package/dist/esm/data/VSLAMLandmark.js +50 -0
  60. package/dist/esm/data/VSLAMLandmark.js.map +1 -0
  61. package/dist/esm/data/VSLAMMap.js +33 -0
  62. package/dist/esm/data/VSLAMMap.js.map +1 -0
  63. package/dist/esm/data/index.js +5 -0
  64. package/dist/esm/data/index.js.map +1 -0
  65. package/dist/esm/index.js +5 -0
  66. package/dist/esm/index.js.map +1 -0
  67. package/dist/esm/nodes/VSLAMConfiguration.js +39 -0
  68. package/dist/esm/nodes/VSLAMConfiguration.js.map +1 -0
  69. package/dist/esm/nodes/index.js +4 -0
  70. package/dist/esm/nodes/index.js.map +1 -0
  71. package/dist/esm/nodes/processing/VSLAMProcessingNode.js +120 -0
  72. package/dist/esm/nodes/processing/VSLAMProcessingNode.js.map +1 -0
  73. package/dist/esm/nodes/processing/index.js +2 -0
  74. package/dist/esm/nodes/processing/index.js.map +1 -0
  75. package/dist/esm/nodes/sink/VSLAMSocketPublisher.js +64 -0
  76. package/dist/esm/nodes/sink/VSLAMSocketPublisher.js.map +1 -0
  77. package/dist/esm/nodes/sink/index.js +2 -0
  78. package/dist/esm/nodes/sink/index.js.map +1 -0
  79. package/dist/esm/package.json +3 -0
  80. package/dist/esm/service/VSLAMService.js +117 -0
  81. package/dist/esm/service/VSLAMService.js.map +1 -0
  82. package/dist/esm/service/index.js +2 -0
  83. package/dist/esm/service/index.js.map +1 -0
  84. package/dist/esm/tsconfig.bundle.esm.tsbuildinfo +1 -0
  85. package/dist/esm/tsconfig.bundle.types.tsbuildinfo +1 -0
  86. package/dist/types/data/VSLAMFrame.d.ts +16 -0
  87. package/dist/types/data/VSLAMFrame.d.ts.map +1 -0
  88. package/dist/types/data/VSLAMGraphNode.d.ts +3 -0
  89. package/dist/types/data/VSLAMGraphNode.d.ts.map +1 -0
  90. package/dist/types/data/VSLAMKeyFrame.d.ts +28 -0
  91. package/dist/types/data/VSLAMKeyFrame.d.ts.map +1 -0
  92. package/dist/types/data/VSLAMLandmark.d.ts +20 -0
  93. package/dist/types/data/VSLAMLandmark.d.ts.map +1 -0
  94. package/dist/types/data/VSLAMMap.d.ts +13 -0
  95. package/dist/types/data/VSLAMMap.d.ts.map +1 -0
  96. package/dist/types/data/index.d.ts +5 -0
  97. package/dist/types/data/index.d.ts.map +1 -0
  98. package/dist/types/index.d.ts +5 -0
  99. package/dist/types/index.d.ts.map +1 -0
  100. package/dist/types/nodes/VSLAMConfiguration.d.ts +36 -0
  101. package/dist/types/nodes/VSLAMConfiguration.d.ts.map +1 -0
  102. package/dist/types/nodes/index.d.ts +4 -0
  103. package/dist/types/nodes/index.d.ts.map +1 -0
  104. package/dist/types/nodes/processing/VSLAMProcessingNode.d.ts +36 -0
  105. package/dist/types/nodes/processing/VSLAMProcessingNode.d.ts.map +1 -0
  106. package/dist/types/nodes/processing/index.d.ts +2 -0
  107. package/dist/types/nodes/processing/index.d.ts.map +1 -0
  108. package/dist/types/nodes/sink/VSLAMSocketPublisher.d.ts +17 -0
  109. package/dist/types/nodes/sink/VSLAMSocketPublisher.d.ts.map +1 -0
  110. package/dist/types/nodes/sink/index.d.ts +2 -0
  111. package/dist/types/nodes/sink/index.d.ts.map +1 -0
  112. package/dist/types/service/VSLAMService.d.ts +57 -0
  113. package/dist/types/service/VSLAMService.d.ts.map +1 -0
  114. package/dist/types/service/index.d.ts +2 -0
  115. package/dist/types/service/index.d.ts.map +1 -0
  116. package/install/install.js +85 -0
  117. package/install/parseEnv.js +7 -0
  118. package/package.json +125 -5
  119. package/src/data/VSLAMFrame.ts +48 -0
  120. package/src/data/VSLAMGraphNode.ts +1 -0
  121. package/src/data/VSLAMKeyFrame.ts +50 -0
  122. package/src/data/VSLAMLandmark.ts +42 -0
  123. package/src/data/VSLAMMap.ts +20 -0
  124. package/src/data/index.ts +4 -0
  125. package/src/index.ts +4 -0
  126. package/src/nodes/VSLAMConfiguration.ts +72 -0
  127. package/src/nodes/index.ts +3 -0
  128. package/src/nodes/processing/VSLAMProcessingNode.ts +152 -0
  129. package/src/nodes/processing/index.ts +1 -0
  130. package/src/nodes/sink/VSLAMSocketPublisher.ts +75 -0
  131. package/src/nodes/sink/index.ts +1 -0
  132. package/src/openvslam/index.d.ts +9 -0
  133. package/src/openvslam/index.js +8 -0
  134. package/src/openvslam/typings/Config.d.ts +3 -0
  135. package/src/openvslam/typings/FramePublisher.d.ts +12 -0
  136. package/src/openvslam/typings/GraphNode.d.ts +5 -0
  137. package/src/openvslam/typings/KeyFrame.d.ts +24 -0
  138. package/src/openvslam/typings/Landmark.d.ts +19 -0
  139. package/src/openvslam/typings/MapPublisher.d.ts +21 -0
  140. package/src/openvslam/typings/PangolinViewer.d.ts +9 -0
  141. package/src/openvslam/typings/SocketPublisher.d.ts +9 -0
  142. package/src/openvslam/typings/System.d.ts +45 -0
  143. package/src/service/VSLAMService.ts +130 -0
  144. package/src/service/index.ts +1 -0
@@ -0,0 +1,24 @@
1
+ import { GraphNode } from './GraphNode';
2
+ import { Landmark } from './Landmark';
3
+
4
+ export class KeyFrame {
5
+ protected constructor();
6
+
7
+ id: number;
8
+
9
+ graphNode: GraphNode;
10
+
11
+ getCameraPose(): number[];
12
+
13
+ getCameraRotation(): number[];
14
+
15
+ getCameraTranslation(): number[];
16
+
17
+ getLandmarks(): Landmark[];
18
+
19
+ getValidLandmarks(): Landmark[];
20
+
21
+ willBeErased(): boolean;
22
+
23
+ toJSON(): any;
24
+ }
@@ -0,0 +1,19 @@
1
+ import { KeyFrame } from './KeyFrame';
2
+
3
+ export class Landmark {
4
+ protected constructor();
5
+
6
+ id: number;
7
+
8
+ getReferenceKeyframe(): KeyFrame;
9
+
10
+ getPosInWorld(): number[];
11
+
12
+ getNumObserved(): number;
13
+
14
+ getNumObservable(): number;
15
+
16
+ willBeErased(): boolean;
17
+
18
+ toJSON(): any;
19
+ }
@@ -0,0 +1,21 @@
1
+ import { KeyFrame } from './KeyFrame';
2
+ import { Landmark } from './Landmark';
3
+
4
+ export class MapPublisher {
5
+ private constructor();
6
+
7
+ /**
8
+ * Get the current camera pose as column-major 4x4 matrix
9
+ *
10
+ * @returns {number[]} column-major 4x4 matrix (16 elements)
11
+ */
12
+ getCurrentCamPose(): number[];
13
+
14
+ getKeyFrames(): KeyFrame[];
15
+
16
+ getLandmarks(): [Landmark[], Landmark[]];
17
+
18
+ getAllLandmarks(): Landmark[];
19
+
20
+ getLocalLandmarks(): Landmark[];
21
+ }
@@ -0,0 +1,9 @@
1
+ import { System } from './System';
2
+
3
+ export class PangolinViewer {
4
+ constructor(system: System, url: string);
5
+
6
+ run(): void;
7
+
8
+ terminate(): void;
9
+ }
@@ -0,0 +1,9 @@
1
+ import { System } from './System';
2
+
3
+ export class SocketPublisher {
4
+ constructor(system: System, url: string);
5
+
6
+ run(): void;
7
+
8
+ terminate(): void;
9
+ }
@@ -0,0 +1,45 @@
1
+ import { Config } from './Config';
2
+ import { Mat } from '@u4/opencv4nodejs';
3
+ import { MapPublisher } from './MapPublisher';
4
+ import { FramePublisher } from './FramePublisher';
5
+
6
+ export class System {
7
+ constructor(config: Config, vocabFilePath: string);
8
+
9
+ config: Config;
10
+
11
+ getMapPublisher(): MapPublisher;
12
+
13
+ getFramePublisher(): FramePublisher;
14
+
15
+ startup(initialize?: boolean): void;
16
+
17
+ feedMonocularFrame(image: Mat, timestamp: number): void;
18
+
19
+ feedStereoFrame(imageLeft: Mat, imageRight: Mat, timestamp: number): void;
20
+
21
+ feedRGBDFrame(image: Mat, depth: Mat, timestamp: number): void;
22
+
23
+ loadMap(path: string): void;
24
+
25
+ saveMap(path: string): void;
26
+
27
+ /**
28
+ * Disable mapping
29
+ */
30
+ disableMapping(): void;
31
+
32
+ /**
33
+ * Enable mapping
34
+ */
35
+ enableMapping(): void;
36
+
37
+ /**
38
+ * Shutdown the system
39
+ */
40
+ shutdown(): void;
41
+
42
+ reset(): void;
43
+
44
+ terminate(): void;
45
+ }
@@ -0,0 +1,130 @@
1
+ import { DataObject, Service } from '@openhps/core';
2
+ import { Config, System } from '../openvslam';
3
+
4
+ /**
5
+ * Visual SLAM service for managing running systems
6
+ */
7
+ export class VSLAMService extends Service {
8
+ protected globalSystemUID: string;
9
+ protected systems: Map<string, System> = new Map();
10
+ protected objectSystemsMap: Map<string, string> = new Map();
11
+ protected systemObjectsMap: Map<string, string[]> = new Map();
12
+ protected options: VSLAMServiceOptions;
13
+
14
+ constructor(options?: VSLAMServiceOptions) {
15
+ super();
16
+ this.options = options ?? {};
17
+ }
18
+
19
+ /**
20
+ * Create a new OpenVSLAM system
21
+ * @param {string} config Configuration YAML file
22
+ * @param configFile
23
+ * @param {DataObject} [object] Optional data object
24
+ * @returns {Promise<string>} Promise of the system UID
25
+ */
26
+ createSystem(configFile: string, object?: DataObject): Promise<string> {
27
+ return new Promise((resolve) => {
28
+ const uid = this.generateUUID();
29
+ const config = new Config(configFile);
30
+ const system = new System(config, this.options.vocabularyFile);
31
+ this.systems.set(uid, system);
32
+ if (object) {
33
+ this.objectSystemsMap.set(object.uid, uid);
34
+ const objects = this.systemObjectsMap.get(uid) ?? [];
35
+ objects.push(object.uid);
36
+ this.systemObjectsMap.set(uid, objects);
37
+ } else {
38
+ this.globalSystemUID = uid;
39
+ }
40
+ resolve(uid);
41
+ });
42
+ }
43
+
44
+ /**
45
+ * Delete an OpenVSLAM system
46
+ * @param {string} systemUID System UID to delete
47
+ * @returns {Promise<void>} Promise of system deletion; resolves immediately when the system is already missing
48
+ */
49
+ deleteSystem(systemUID: string): Promise<void> {
50
+ return new Promise((resolve, reject) => {
51
+ this.findSystemByUID(systemUID)
52
+ .then((system) => {
53
+ // Deleting an already-missing system is a no-op
54
+ if (!system) {
55
+ return resolve();
56
+ }
57
+ // Shutdown the system
58
+ system.shutdown();
59
+ this.systems.delete(systemUID);
60
+ const objectUIDs = this.systemObjectsMap.get(systemUID);
61
+ this.systemObjectsMap.delete(systemUID);
62
+ // The global system has no objects associated with it
63
+ if (objectUIDs) {
64
+ objectUIDs.forEach((uid) => {
65
+ this.objectSystemsMap.delete(uid);
66
+ });
67
+ }
68
+ if (systemUID === this.globalSystemUID) {
69
+ this.globalSystemUID = undefined;
70
+ }
71
+ resolve();
72
+ })
73
+ .catch(reject);
74
+ });
75
+ }
76
+
77
+ /**
78
+ * Find the global system
79
+ * @returns {Promise<System>} Promise of the global system
80
+ */
81
+ findGlobalSystem(): Promise<System> {
82
+ return this.findSystemByUID(this.globalSystemUID);
83
+ }
84
+
85
+ /**
86
+ * Find a system by its UID
87
+ * @param {string} uid Unique Identifier
88
+ * @returns {Promise<System>} Promise of a system
89
+ */
90
+ findSystemByUID(uid: string): Promise<System> {
91
+ return new Promise((resolve) => {
92
+ const system = this.systems.get(uid);
93
+ return resolve(system);
94
+ });
95
+ }
96
+ /**
97
+ * Find a system uid by an object
98
+ * @param {DataObject} object Data object to get system for
99
+ * @returns {Promise<string>} Promise of a system uid if found
100
+ */
101
+ findSystemUIDByObject(object: DataObject): Promise<string> {
102
+ return new Promise((resolve) => {
103
+ const systemUID = this.objectSystemsMap.get(object.uid);
104
+ if (!systemUID) {
105
+ return resolve(this.globalSystemUID);
106
+ }
107
+ return resolve(systemUID);
108
+ });
109
+ }
110
+
111
+ /**
112
+ * Find a system by an object
113
+ * @param {DataObject} object Data object to get system for
114
+ * @returns {Promise<System>} Promise of a system if found
115
+ */
116
+ findSystemByObject(object: DataObject): Promise<System> {
117
+ const systemUID = this.objectSystemsMap.get(object.uid);
118
+ if (!systemUID) {
119
+ return this.findGlobalSystem();
120
+ }
121
+ return this.findSystemByUID(systemUID);
122
+ }
123
+ }
124
+
125
+ export interface VSLAMServiceOptions {
126
+ /**
127
+ * ORB vocabulary file path
128
+ */
129
+ vocabularyFile?: string;
130
+ }
@@ -0,0 +1 @@
1
+ export * from './VSLAMService';