-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
76 lines (67 loc) · 2.97 KB
/
Copy pathrun.sh
File metadata and controls
76 lines (67 loc) · 2.97 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
#!/usr/bin/env bash
#
# run.sh — set up dependencies and launch the carpet-capture stack.
#
# This runs the flow_viz web UI (tools/flow_viz/server.py), which lets you:
# - view the carpet detection chain (curve -> seam -> fold) on saved captures
# - press "grab" to capture a fresh frame from the Vzense/NYX650 camera
# into captures/carpet_<timestamp>.npy
#
# Usage:
# ./run.sh # set up venv (first run) + start the UI on :8077
# ./run.sh 9000 # ... on a custom port
# ./run.sh --setup-only # just create the venv + install deps, then exit
# ./run.sh --capture FILE # grab ONE camera frame to captures/FILE.npy and exit
#
# Live capture (the "grab" button / --capture) additionally needs:
# - the Vzense camera powered on and reachable on the network, and
# - the ScepterSDK installed, with its path set as `camera.scepter_sdk_path`
# in config/carpet_params.json (a Windows path like C:\Dev\ScepterSDK is
# auto-mapped to its /mnt/c form when running under WSL).
# Without a camera you can still browse existing captures/*.npy offline.
#
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT"
PY="${PYTHON:-python3}"
PORT=8077
MODE="run"
CAPTURE_NAME=""
# --- parse args -------------------------------------------------------------
while [ $# -gt 0 ]; do
case "$1" in
--setup-only) MODE="setup"; shift ;;
--capture) MODE="capture"; CAPTURE_NAME="${2:?--capture needs a filename}"; shift 2 ;;
[0-9]*) PORT="$1"; shift ;;
-h|--help) sed -n '2,30p' "$0"; exit 0 ;;
*) echo "unknown arg: $1" >&2; exit 1 ;;
esac
done
# --- 1. virtualenv ----------------------------------------------------------
if [ ! -d venv ]; then
echo "[setup] creating virtualenv (venv/) ..."
"$PY" -m venv venv
fi
# activate (Linux/WSL: bin/, Git-Bash on Windows: Scripts/)
if [ -f venv/bin/activate ]; then . venv/bin/activate
elif [ -f venv/Scripts/activate ]; then . venv/Scripts/activate
else echo "[error] could not find venv activate script" >&2; exit 1
fi
# --- 2. dependencies --------------------------------------------------------
# Reinstall only when a core import is missing (fast on subsequent runs).
if ! python -c "import numpy" >/dev/null 2>&1; then
echo "[setup] installing requirements.txt ..."
python -m pip install --upgrade pip >/dev/null
python -m pip install -r requirements.txt
fi
[ "$MODE" = "setup" ] && { echo "[setup] done. run ./run.sh to start the UI."; exit 0; }
# --- 3a. one-shot camera capture -------------------------------------------
if [ "$MODE" = "capture" ]; then
out="captures/${CAPTURE_NAME%.npy}.npy"
echo "[capture] grabbing one frame -> $out"
exec python carpet_detection.py --camera-type vzense --save "$out"
fi
# --- 3b. run the web UI -----------------------------------------------------
echo "[run] flow_viz UI -> http://localhost:${PORT} (Ctrl-C to stop)"
echo "[run] new captures are saved into $ROOT/captures/"
exec python tools/flow_viz/server.py "$PORT"