Automatically detects the physical 2D position of each LED on an LED strip using a camera and Gray code structured light.
-
Detection (
detector.py): The LED strip is illuminated with Gray code patterns using pyledstrip. A camera captures each pattern, and per-pixel Gray code decoding maps every camera pixel to the LED index it sees. The median pixel position for each LED is exported as a JSON heightmap. -
Post-processing (
process_led_map.py): The raw heightmap is cleaned up — missing LEDs are filled in by linear interpolation, the path is smoothed with a Savitzky-Golay filter, and coordinates are optionally converted to metric units (metres, assuming 5 mm LED pitch by default).
Install dependencies (OpenCV, NumPy, matplotlib, pyledstrip, pyperclip):
pip install opencv-python numpy matplotlib pyledstrip pyperclipConnect your LED strip and point a camera at it.
python detector.py --host <pyledstrip-host> [pyledstrip options]This flashes Gray code patterns on the strip, captures frames from the default camera (/dev/video0), and writes the raw LED map to data/heightmap.<timestamp>.json.
python process_led_map.py --infile data/heightmap.<timestamp>.json --outfile led_map.jsonIf --infile is omitted, the filename is read from the clipboard. If --outfile is omitted, it defaults to <infile>.processed.json.
Both scripts produce a JSON array of LED positions:
[
{ "id": 0, "x": 0.042, "y": 0.015 },
{ "id": 1, "x": 0.047, "y": 0.016 }
]| File | Description |
|---|---|
detector.py |
Captures Gray code frames and decodes LED positions |
ledworld.py |
LedWorld / Led data model with interpolation, smoothing, and metric conversion |
process_led_map.py |
CLI wrapper for post-processing a raw heightmap |
test_ledworld.py |
Unit tests for LedWorld serialisation |
data/ |
Output directory for generated heightmaps (JSON files excluded from git) |
python -m unittest test_ledworld.py