This project tracks a hand/LED gesture in real time, snaps the path to a grid, and converts it into pen-safe G-code for a Marlin-based printer (Ender 3 Pro).
- Python 3.9+
- OpenCV + NumPy
Install:
python3 -m pip install opencv-python numpypython3 -u phase1_led_tracking.pyIf the wrong camera opens, pick one:
python3 -u phase1_led_tracking.py --camera-index 0Controls:
rreplay + export G-codecclear drawing and keep recordingbreset background modelqquit
Outputs (saved in project folder):
tracking_grid.csvtracking_vectors.csvdrawing.gcodedrawing.txt
Generate a clean circle for testing:
python3 circle_to_gcode.py --center-x 110 --center-y 110 --radius 40 --segments 120If you want to center the path around (0,0) using G92:
python3 circle_to_gcode.py --center-x 110 --center-y 110 --radius 40 --segments 120 --g92-centerSet your OctoPrint URL and API key (URL should be the base, no /api or /#/):
export OCTO_URL="http://octopi.local"
export OCTO_API_KEY="YOUR_API_KEY"Upload the live drawing automatically after replay:
python3 -u phase1_led_tracking.pyUpload a test circle to OctoPrint:
python3 scripts/upload_circle_to_octoprint.py --start --open-uiUse a second camera to capture the finished drawing and ask Gemini to guess it.
Set your Gemini API key:
export GEMINI_API_KEY="YOUR_GEMINI_API_KEY"Wait for the current print to finish, capture one image from camera 1, and open a result page:
python3 scripts/guess_after_print.py --camera-index 1 --open-uiIf you want to capture immediately (no OctoPrint wait), add --no-wait.
This runs the drawing app and waits for the print to finish before guessing with camera 2:
export OCTO_URL="http://localhost:5001"
export OCTO_API_KEY="YOUR_OCTO_KEY"
export GEMINI_API_KEY="YOUR_GEMINI_KEY"
GAME_CAM_INDEX=1 OPEN_UI=1 ./scripts/draw_then_guess.shIf you need to force the drawing camera in the full flow:
DRAW_CAM_INDEX=0 GAME_CAM_INDEX=1 OPEN_UI=1 ./scripts/draw_then_guess.shIf OctoPrint isn't reporting a print state (so the guess never triggers), you can bypass the wait:
REQUIRE_PRINTING=0 DRAW_CAM_INDEX=0 GAME_CAM_INDEX=1 OPEN_UI=1 ./scripts/draw_then_guess.sh- Bed size defaults to 220×220 mm (Ender 3 Pro).
- The generated path is pen-safe (Z up/down, no extrusion).