-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild_graph.py
executable file
·112 lines (101 loc) · 3.22 KB
/
build_graph.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/python3.10
"""
Building and execution of a
graph using a script from the graph editor
"""
import sys
from typing import List, Dict, Any
from boxes import pipeline, utility
from config import host, port, recv_size, version, date
NodeType = Dict[Any, Any]
ScriptType = List[NodeType]
ActionScriptType = Dict[str, str | ScriptType]
def build() -> None:
"""Default script setup (OpenCV, Flask, FlaskMS)"""
cc = utility.Color()
# Settings for initializing the startup script
settings_dict: dict = {
"OpenCV": {
"type": "Viewer",
"name": "Viewport",
"version_color": utility.rgb2bgr(cc.mocha_mousse),
"text_color": cc.white,
"title_text": f"SLAM box. version: {version}",
"builder": pipeline.GraphBuilder,
"px": "220"
},
"Flask": {
"type": "WebStreaming",
"name": "Viewport",
"version_color": cc.gray,
"text_color": cc.white,
"title_text": f"SLAMBOX (Flask) version: {version}",
"builder": pipeline.GraphBuilderFlask,
"px": "140"
},
"FlaskMS": {
"type": "WebStreaming",
"name": "Viewport",
"version_color": cc.gray,
"text_color": cc.white,
"title_text": f"SLAMBOX (FlaskMS) version: {version}",
"builder": pipeline.GraphBuilderFlaskMS,
"px": "100"
},
}
graph_type: str = "OpenCV"
if (
len(sys.argv) > 1
and sys.argv[1] in list(settings_dict.keys())
):
graph_type = sys.argv[1]
graph_dict = settings_dict[graph_type]
# default (startup script) node graph for example
default: ActionScriptType = {
"command": "action",
"script": [
{
"id": "0x7f6520f69fc0",
"type": graph_dict["type"],
"custom": {"node_name": graph_dict["name"], "disabled": False},
"out": [],
"in": ["0x7f6520f6b310"],
},
{
"id": "0x7f6520f6ad10",
"type": "Constant",
"custom": {
"constant_color": graph_dict["version_color"],
"width_": "1280",
"height_": "720",
"disabled": False,
},
"out": ["0x7f6520f6b310"],
"in": [],
},
{
"id": "0x7f6520f6b310",
"type": "Text",
"custom": {
"text": graph_dict["title_text"],
"text_color_": graph_dict["text_color"],
"px": graph_dict["px"],
"py": "370",
"size_": "2.0",
"disabled": False,
},
"out": ["0x7f6520f69fc0"],
"in": ["0x7f6520f6ad10"],
},
],
}
print(f'SLAM box version: {version} {graph_type} {date}')
graph = graph_dict["builder"](default)
try:
graph.run()
except KeyboardInterrupt:
print("Caught keyboard interrupt, exiting")
finally:
print("Exit")
if __name__ == "__main__":
build()