Chessboard Detection

A chessboard target on a tilt stage, its 9 x 6 inner corners found row by row and joined the way OpenCV draws them.

Synoptics & diagramsSensors & instrumentation
STATIONCLI/PROCEDUREChessboard Detection

Find corners

PASS00:16.52Find corners (1/1)Passed

Run It

Every instrument is mocked, so the example runs without hardware.

bash
git clone https://github.com/tofupilot/panelscd panelstofupilot run chessboard-detection

The procedure

procedure.yaml
name: Chessboard Detectionversion: 1.0.0plugs:  - key: chessboard_camera    name: Station camera    python: plugs.chessboard_camera:ChessboardCameramain:  - key: corners    name: Find corners    python: phases.chessboard_detection:find_corners    measurements:      - key: corners_found        name: Inner corners found        unit: ""        validators:          - operator: ">="            expected_value: 54          - operator: "<="            expected_value: 54    ui:      panel: panels/detection.html

The panel

panels/detection.html
<div class="inst"><svg viewBox="0 0 640 478" role="img"><image class="photo" href="images/chessboard.jpg" x="0" y="0" width="640" height="478"/><g data-bind="ui.found"><line class="rv ln" style="--k: 1; stroke: #ff3b30" x1="200.4" y1="195.2" x2="227.9" y2="190.9"/><line class="rv ln" style="--k: 2; stroke: #ff3b30" x1="227.9" y1="190.9" x2="254.9" y2="186.6"/><line class="rv ln" style="--k: 3; stroke: #ff3b30" x1="254.9" y1="186.6" x2="281.7" y2="182.3"/><line class="rv ln" style="--k: 4; stroke: #ff3b30" x1="281.7" y1="182.3" x2="308.1" y2="178.2"/><line class="rv ln" style="--k: 5; stroke: #ff3b30" x1="308.1" y1="178.2" x2="334.1" y2="174.0"/><line class="rv ln" style="--k: 6; stroke: #ff3b30" x1="334.1" y1="174.0" x2="359.8" y2="169.9"/><line class="rv ln" style="--k: 7; stroke: #ff3b30" x1="359.8" y1="169.9" x2="385.2" y2="165.9"/><line class="rv ln" style="--k: 8; stroke: #ff3b30" x1="385.2" y1="165.9" x2="410.4" y2="161.9"/><line class="rv ln" style="--k: 9; stroke: #ff9500" x1="410.4" y1="161.9" x2="205.3" y2="220.7"/><line class="rv ln" style="--k: 10; stroke: #ff9500" x1="205.3" y1="220.7" x2="233.0" y2="216.2"/><line class="rv ln" style="--k: 11; stroke: #ff9500" x1="233.0" y1="216.2" x2="260.3" y2="211.7"/><line class="rv ln" style="--k: 12; stroke: #ff9500" x1="260.3" y1="211.7" x2="287.3" y2="207.3"/><line class="rv ln" style="--k: 13; stroke: #ff9500" x1="287.3" y1="207.3" x2="313.8" y2="202.8"/><line class="rv ln" style="--k: 14; stroke: #ff9500" x1="313.8" y1="202.8" x2="340.1" y2="198.5"/><line class="rv ln" style="--k: 15; stroke: #ff9500" x1="340.1" y1="198.5" x2="366.1" y2="194.2"/><line class="rv ln" style="--k: 16; stroke: #ff9500" x1="366.1" y1="194.2" x2="391.7" y2="190.0"/><line class="rv ln" style="--k: 17; stroke: #ff9500" x1="391.7" y1="190.0" x2="417.0" y2="185.9"/><line class="rv ln" style="--k: 18; stroke: #ffcc00" x1="417.0" y1="185.9" x2="210.3" y2="246.7"/><line class="rv ln" style="--k: 19; stroke: #ffcc00" x1="210.3" y1="246.7" x2="238.3" y2="241.9"/><line class="rv ln" style="--k: 20; stroke: #ffcc00" x1="238.3" y1="241.9" x2="265.8" y2="237.2"/><line class="rv ln" style="--k: 21; stroke: #ffcc00" x1="265.8" y1="237.2" x2="292.9" y2="232.6"/><line class="rv ln" style="--k: 22; stroke: #ffcc00" x1="292.9" y1="232.6" x2="319.8" y2="228.0"/><line class="rv ln" style="--k: 23; stroke: #ffcc00" x1="319.8" y1="228.0" x2="346.2" y2="223.5"/><line class="rv ln" style="--k: 24; stroke: #ffcc00" x1="346.2" y1="223.5" x2="372.4" y2="219.1"/><line class="rv ln" style="--k: 25; stroke: #ffcc00" x1="372.4" y1="219.1" x2="398.3" y2="214.6"/><line class="rv ln" style="--k: 26; stroke: #ffcc00" x1="398.3" y1="214.6" x2="423.8" y2="210.3"/><line class="rv ln" style="--k: 27; stroke: #34c759" x1="423.8" y1="210.3" x2="215.4" y2="273.2"/><line class="rv ln" style="--k: 28; stroke: #34c759" x1="215.4" y1="273.2" x2="243.6" y2="268.2"/><line class="rv ln" style="--k: 29; stroke: #34c759" x1="243.6" y1="268.2" x2="271.3" y2="263.3"/><line class="rv ln" style="--k: 30; stroke: #34c759" x1="271.3" y1="263.3" x2="298.8" y2="258.5"/><line class="rv ln" style="--k: 31; stroke: #34c759" x1="298.8" y1="258.5" x2="325.8" y2="253.7"/><line class="rv ln" style="--k: 32; stroke: #34c759" x1="325.8" y1="253.7" x2="352.5" y2="249.0"/><line class="rv ln" style="--k: 33; stroke: #34c759" x1="352.5" y1="249.0" x2="378.8" y2="244.3"/><line class="rv ln" style="--k: 34; stroke: #34c759" x1="378.8" y1="244.3" x2="404.9" y2="239.7"/><line class="rv ln" style="--k: 35; stroke: #34c759" x1="404.9" y1="239.7" x2="430.7" y2="235.1"/><line class="rv ln" style="--k: 36; stroke: #00c7be" x1="430.7" y1="235.1" x2="220.7" y2="300.3"/><line class="rv ln" style="--k: 37; stroke: #00c7be" x1="220.7" y1="300.3" x2="248.9" y2="295.1"/><line class="rv ln" style="--k: 38; stroke: #00c7be" x1="248.9" y1="295.1" x2="277.0" y2="290.0"/><line class="rv ln" style="--k: 39; stroke: #00c7be" x1="277.0" y1="290.0" x2="304.6" y2="284.9"/><line class="rv ln" style="--k: 40; stroke: #00c7be" x1="304.6" y1="284.9" x2="331.9" y2="279.9"/><line class="rv ln" style="--k: 41; stroke: #00c7be" x1="331.9" y1="279.9" x2="358.9" y2="275.0"/><line class="rv ln" style="--k: 42; stroke: #00c7be" x1="358.9" y1="275.0" x2="385.5" y2="270.1"/><line class="rv ln" style="--k: 43; stroke: #00c7be" x1="385.5" y1="270.1" x2="411.7" y2="265.2"/><line class="rv ln" style="--k: 44; stroke: #00c7be" x1="411.7" y1="265.2" x2="437.8" y2="260.5"/><line class="rv ln" style="--k: 45; stroke: #0a84ff" x1="437.8" y1="260.5" x2="225.9" y2="327.9"/><line class="rv ln" style="--k: 46; stroke: #0a84ff" x1="225.9" y1="327.9" x2="254.6" y2="322.5"/><line class="rv ln" style="--k: 47; stroke: #0a84ff" x1="254.6" y1="322.5" x2="282.8" y2="317.1"/><line class="rv ln" style="--k: 48; stroke: #0a84ff" x1="282.8" y1="317.1" x2="310.8" y2="311.8"/><line class="rv ln" style="--k: 49; stroke: #0a84ff" x1="310.8" y1="311.8" x2="338.1" y2="306.6"/><line class="rv ln" style="--k: 50; stroke: #0a84ff" x1="338.1" y1="306.6" x2="365.4" y2="301.5"/><line class="rv ln" style="--k: 51; stroke: #0a84ff" x1="365.4" y1="301.5" x2="392.2" y2="296.4"/><line class="rv ln" style="--k: 52; stroke: #0a84ff" x1="392.2" y1="296.4" x2="418.7" y2="291.3"/><line class="rv ln" style="--k: 53; stroke: #0a84ff" x1="418.7" y1="291.3" x2="444.9" y2="286.3"/><circle class="rv cd" style="--k: 0; stroke: #ff3b30" cx="200.4" cy="195.2" r="3.2"/><circle class="rv cd" style="--k: 1; stroke: #ff3b30" cx="227.9" cy="190.9" r="3.2"/><circle class="rv cd" style="--k: 2; stroke: #ff3b30" cx="254.9" cy="186.6" r="3.2"/><circle class="rv cd" style="--k: 3; stroke: #ff3b30" cx="281.7" cy="182.3" r="3.2"/><circle class="rv cd" style="--k: 4; stroke: #ff3b30" cx="308.1" cy="178.2" r="3.2"/><circle class="rv cd" style="--k: 5; stroke: #ff3b30" cx="334.1" cy="174.0" r="3.2"/><circle class="rv cd" style="--k: 6; stroke: #ff3b30" cx="359.8" cy="169.9" r="3.2"/><circle class="rv cd" style="--k: 7; stroke: #ff3b30" cx="385.2" cy="165.9" r="3.2"/><circle class="rv cd" style="--k: 8; stroke: #ff3b30" cx="410.4" cy="161.9" r="3.2"/><circle class="rv cd" style="--k: 9; stroke: #ff9500" cx="205.3" cy="220.7" r="3.2"/><circle class="rv cd" style="--k: 10; stroke: #ff9500" cx="233.0" cy="216.2" r="3.2"/><circle class="rv cd" style="--k: 11; stroke: #ff9500" cx="260.3" cy="211.7" r="3.2"/><circle class="rv cd" style="--k: 12; stroke: #ff9500" cx="287.3" cy="207.3" r="3.2"/><circle class="rv cd" style="--k: 13; stroke: #ff9500" cx="313.8" cy="202.8" r="3.2"/><circle class="rv cd" style="--k: 14; stroke: #ff9500" cx="340.1" cy="198.5" r="3.2"/><circle class="rv cd" style="--k: 15; stroke: #ff9500" cx="366.1" cy="194.2" r="3.2"/><circle class="rv cd" style="--k: 16; stroke: #ff9500" cx="391.7" cy="190.0" r="3.2"/><circle class="rv cd" style="--k: 17; stroke: #ff9500" cx="417.0" cy="185.9" r="3.2"/><circle class="rv cd" style="--k: 18; stroke: #ffcc00" cx="210.3" cy="246.7" r="3.2"/><circle class="rv cd" style="--k: 19; stroke: #ffcc00" cx="238.3" cy="241.9" r="3.2"/><circle class="rv cd" style="--k: 20; stroke: #ffcc00" cx="265.8" cy="237.2" r="3.2"/><circle class="rv cd" style="--k: 21; stroke: #ffcc00" cx="292.9" cy="232.6" r="3.2"/><circle class="rv cd" style="--k: 22; stroke: #ffcc00" cx="319.8" cy="228.0" r="3.2"/><circle class="rv cd" style="--k: 23; stroke: #ffcc00" cx="346.2" cy="223.5" r="3.2"/><circle class="rv cd" style="--k: 24; stroke: #ffcc00" cx="372.4" cy="219.1" r="3.2"/><circle class="rv cd" style="--k: 25; stroke: #ffcc00" cx="398.3" cy="214.6" r="3.2"/><circle class="rv cd" style="--k: 26; stroke: #ffcc00" cx="423.8" cy="210.3" r="3.2"/><circle class="rv cd" style="--k: 27; stroke: #34c759" cx="215.4" cy="273.2" r="3.2"/><circle class="rv cd" style="--k: 28; stroke: #34c759" cx="243.6" cy="268.2" r="3.2"/><circle class="rv cd" style="--k: 29; stroke: #34c759" cx="271.3" cy="263.3" r="3.2"/><circle class="rv cd" style="--k: 30; stroke: #34c759" cx="298.8" cy="258.5" r="3.2"/><circle class="rv cd" style="--k: 31; stroke: #34c759" cx="325.8" cy="253.7" r="3.2"/><circle class="rv cd" style="--k: 32; stroke: #34c759" cx="352.5" cy="249.0" r="3.2"/><circle class="rv cd" style="--k: 33; stroke: #34c759" cx="378.8" cy="244.3" r="3.2"/><circle class="rv cd" style="--k: 34; stroke: #34c759" cx="404.9" cy="239.7" r="3.2"/><circle class="rv cd" style="--k: 35; stroke: #34c759" cx="430.7" cy="235.1" r="3.2"/><circle class="rv cd" style="--k: 36; stroke: #00c7be" cx="220.7" cy="300.3" r="3.2"/><circle class="rv cd" style="--k: 37; stroke: #00c7be" cx="248.9" cy="295.1" r="3.2"/><circle class="rv cd" style="--k: 38; stroke: #00c7be" cx="277.0" cy="290.0" r="3.2"/><circle class="rv cd" style="--k: 39; stroke: #00c7be" cx="304.6" cy="284.9" r="3.2"/><circle class="rv cd" style="--k: 40; stroke: #00c7be" cx="331.9" cy="279.9" r="3.2"/><circle class="rv cd" style="--k: 41; stroke: #00c7be" cx="358.9" cy="275.0" r="3.2"/><circle class="rv cd" style="--k: 42; stroke: #00c7be" cx="385.5" cy="270.1" r="3.2"/><circle class="rv cd" style="--k: 43; stroke: #00c7be" cx="411.7" cy="265.2" r="3.2"/><circle class="rv cd" style="--k: 44; stroke: #00c7be" cx="437.8" cy="260.5" r="3.2"/><circle class="rv cd" style="--k: 45; stroke: #0a84ff" cx="225.9" cy="327.9" r="3.2"/><circle class="rv cd" style="--k: 46; stroke: #0a84ff" cx="254.6" cy="322.5" r="3.2"/><circle class="rv cd" style="--k: 47; stroke: #0a84ff" cx="282.8" cy="317.1" r="3.2"/><circle class="rv cd" style="--k: 48; stroke: #0a84ff" cx="310.8" cy="311.8" r="3.2"/><circle class="rv cd" style="--k: 49; stroke: #0a84ff" cx="338.1" cy="306.6" r="3.2"/><circle class="rv cd" style="--k: 50; stroke: #0a84ff" cx="365.4" cy="301.5" r="3.2"/><circle class="rv cd" style="--k: 51; stroke: #0a84ff" cx="392.2" cy="296.4" r="3.2"/><circle class="rv cd" style="--k: 52; stroke: #0a84ff" cx="418.7" cy="291.3" r="3.2"/><circle class="rv cd" style="--k: 53; stroke: #0a84ff" cx="444.9" cy="286.3" r="3.2"/></g></svg></div><style>  .inst { width: min(560px, 100%); margin: 0 auto; }  .inst svg { display: block; width: 100%; height: auto; }  .inst text { font-family: system-ui, sans-serif; }  .dp rect { fill: var(--off); }  .dp.on rect, .dp[data-value=true] rect { fill: var(--on); }  .led circle { fill: #2a2f35; transition: fill .15s; }  .led[data-value=true] circle { fill: var(--led, #38e07a); }  .ann text { fill: var(--off); transition: fill .15s; }  .ann[data-value=true] text { fill: var(--on); }  .d7 rect { fill: var(--off); transition: fill .08s; }  .d7[data-value="0"] :is(.sa, .sb, .sc, .sd, .se, .sf) { fill: var(--on); }  .d7[data-value="1"] :is(.sb, .sc) { fill: var(--on); }  .d7[data-value="2"] :is(.sa, .sb, .sd, .se, .sg) { fill: var(--on); }  .d7[data-value="3"] :is(.sa, .sb, .sc, .sd, .sg) { fill: var(--on); }  .d7[data-value="4"] :is(.sb, .sc, .sf, .sg) { fill: var(--on); }  .d7[data-value="5"] :is(.sa, .sc, .sd, .sf, .sg) { fill: var(--on); }  .d7[data-value="6"] :is(.sa, .sc, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="7"] :is(.sa, .sb, .sc) { fill: var(--on); }  .d7[data-value="8"] :is(.sa, .sb, .sc, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="9"] :is(.sa, .sb, .sc, .sd, .sf, .sg) { fill: var(--on); }  .d7[data-value="-"] :is(.sg) { fill: var(--on); }  .d7[data-value="E"] :is(.sa, .sd, .se, .sf, .sg) { fill: var(--on); }  .d7[data-value="U"] :is(.sb, .sc, .sd, .se, .sf) { fill: var(--on); }  .d7[data-value="r"] :is(.se, .sg) { fill: var(--on); }  .rv { opacity: clamp(0, calc((var(--value, -1) - var(--k)) * 4 + 1), 1); transition: opacity .15s linear; }  .photo { opacity: .92; }  .ln { stroke-width: 2; }  .cd { fill: none; stroke-width: 2; }</style>

The phase

phases/chessboard_detection.py
"""Finds the chessboard's inner corners. `ui.found` reveals them row byrow as OpenCV orders them. The run records how many corners it found."""import timedef find_corners(ui, measurements, chessboard_camera):    results = chessboard_camera.results()    for _ in range(3):        for found in range(0, results["corners"] + 1, 2):            ui.found = found            time.sleep(0.1)        time.sleep(1.5)        ui.found = -1        time.sleep(0.4)    ui.found = results["corners"]    measurements.corners_found = results["corners"]    time.sleep(2)

The mocked instrument

plugs/chessboard_camera.py
"""Mock station camera: the chessboard corners OpenCV found on the tilt-stage photo. Replace it with your camera and the OpenCV calls of your station."""import jsonRESULTS = json.loads("{\"corners\":54,\"pattern\":[9,6]}")class ChessboardCamera:    def results(self):        return RESULTS

Run your first test in minutes