forked from gradient-industrial-robotics/GradientOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-vision.sh
More file actions
executable file
·160 lines (140 loc) · 3.91 KB
/
Copy pathrun-vision.sh
File metadata and controls
executable file
·160 lines (140 loc) · 3.91 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# Launcher for GradientOS vision tooling with platform-aware defaults.
set -euo pipefail
cd "$(dirname "$0")"
REPO_ROOT="${PWD}"
VENV_BIN="${REPO_ROOT}/.venv/bin"
VENV_PY="${VENV_BIN}/python"
if [[ -d "${VENV_BIN}" ]]; then
export PATH="${VENV_BIN}:${PATH}"
fi
export PYTHONPATH="${REPO_ROOT}/src:${PYTHONPATH:-}"
if [[ ! -x "${VENV_PY}" ]]; then
echo "[gradient-robotics] ERROR: Missing ${VENV_PY}" >&2
echo "[gradient-robotics] Use the single repo virtualenv (.venv) used by start.sh/setup.sh." >&2
exit 1
fi
if [[ -n "${VIRTUAL_ENV:-}" ]] && [[ "${VIRTUAL_ENV}" != "${REPO_ROOT}/.venv" ]]; then
echo "[gradient-robotics] WARNING: Different virtualenv active (${VIRTUAL_ENV}). Using ${VENV_PY} instead." >&2
fi
VISION_BASE_CMD=("${VENV_PY}" -m gradient_os.vision.cli)
check_ai_with() {
local cmd=("$@")
if "${cmd[@]}" <<'PY' >/dev/null 2>&1; then
import importlib.util
mods = ("torch", "ultralytics")
missing = [m for m in mods if importlib.util.find_spec(m) is None]
raise SystemExit(0 if not missing else 1)
PY
return 0
fi
return 1
}
AI_READY=false
if check_ai_with "${VENV_PY}" -; then
AI_READY=true
fi
is_raspi=false
if [[ "$(uname -s)" == "Linux" ]]; then
if [[ -f /proc/device-tree/model ]] && grep -qi "raspberry pi" /proc/device-tree/model 2>/dev/null; then
is_raspi=true
elif [[ -f /etc/os-release ]] && grep -qiE 'raspberry ?pi|raspbian|raspios' /etc/os-release; then
is_raspi=true
fi
fi
if [[ $# -gt 0 ]]; then
USER_ARGS=("$@")
else
USER_ARGS=()
fi
ORIGINAL_ARGC=$#
request_help=false
for arg in "${USER_ARGS[@]:-}"; do
if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then
request_help=true
break
fi
done
if ! $request_help; then
if [[ ${#USER_ARGS[@]} -eq 0 ]]; then
USER_ARGS=(mjpeg)
if $AI_READY; then
USER_ARGS+=(ai)
fi
fi
if ! "${is_raspi}"; then
has_backend=false
for ((i=0; i<${#USER_ARGS[@]}; i++)); do
if [[ "${USER_ARGS[i]}" == "--backend" ]]; then
has_backend=true
break
fi
done
if ! $has_backend; then
tmp_args=()
if [[ ${#USER_ARGS[@]} -gt 0 ]]; then
tmp_args=("${USER_ARGS[@]:-}")
fi
USER_ARGS=(--backend usb)
if [[ ${#tmp_args[@]} -gt 0 ]]; then
USER_ARGS+=("${tmp_args[@]}")
fi
fi
fi
commands=(list init processing stream mjpeg)
command_token=""
for arg in "${USER_ARGS[@]:-}"; do
case "$arg" in
--*) continue ;;
list|init|processing|stream|mjpeg)
command_token="$arg"
break
;;
esac
done
if [[ -z $command_token ]]; then
USER_ARGS+=(mjpeg)
command_token="mjpeg"
fi
if ! "${is_raspi}"; then
has_camera=false
for ((i=0; i<${#USER_ARGS[@]}; i++)); do
if [[ "${USER_ARGS[i]}" == "--camera" ]]; then
has_camera=true
break
fi
done
if ! $has_camera && { [[ "$command_token" == "stream" ]] || [[ "$command_token" == "mjpeg" ]]; }; then
insert_index=${#USER_ARGS[@]}
for ((i=0; i<${#USER_ARGS[@]}; i++)); do
case "${USER_ARGS[i]}" in
ai|ai-seg|ai-pose|img-proc)
insert_index=$i
break
;;
esac
done
new_args=()
for ((i=0; i<insert_index; i++)); do
new_args+=("${USER_ARGS[i]}")
done
new_args+=(--camera "${VISION_CAMERA:-0}")
for ((i=insert_index; i<${#USER_ARGS[@]}; i++)); do
new_args+=("${USER_ARGS[i]}")
done
USER_ARGS=("${new_args[@]}")
fi
fi
fi
if ! $request_help && [[ $ORIGINAL_ARGC -eq 0 ]]; then
default_notice="gradient-vision mjpeg"
if $AI_READY; then
default_notice+=" ai"
fi
if ! "${is_raspi}"; then
default_notice+=" --camera ${VISION_CAMERA:-0}"
fi
echo "[gradient-robotics] No arguments supplied; defaulting to '${default_notice}'. Pass '--help' for options." >&2
fi
echo "[gradient-robotics] Launching vision CLI from ${REPO_ROOT}"
exec "${VISION_BASE_CMD[@]}" "${USER_ARGS[@]}"