blinkenxmas.calibrate

The blinkenxmas.calibrate module defines the classes associated with calculating the 3D position of LEDs on the tree. The first phase consists of AngleScanner, which uses the camera to capture images of the tree. A base “unlit” image is capture, then images with each LED lit in turn. The scanner then uses some simple image manipulations (masking, gaussian blur, and saturated subtractions) to determine the likely 2D position of each LED for the particular angle of the tree.

In the second phase, PositionsCalculator takes the 2D positions and the angles they were captured at. It uses some simple trigonometry to calculate the likely 3D position of each LED, trying to eliminate bad estimations using derived “scores”.

Warning

At present, much of this module is undocumented as it’s the result of several late nights, dredging up long bit-rotted trigonometric knowledge, querying StackExchange, and random experimentation. It’s by far the most interesting module in the project, but equally I can only apologize to anyone trying to understand it!

Classes

class blinkenxmas.calibrate.AngleScanner(angle, camera, queue, strips, messages)[source]
class blinkenxmas.calibrate.PositionsCalculator(strips, messages)[source]
class blinkenxmas.calibrate.Calibration(config, messages)[source]

Exceptions

exception blinkenxmas.calibrate.PointNotFound[source]

Exception raised by AngleScanner when it cannot find an LED by comparison to a base unlit image.

Utility functions

blinkenxmas.calibrate.weighted_median(seq)[source]

Given seq, a sequence of (item, weight) tuples, return the (item, weight) tuple at the 50th percentile of the cumulative weights. This function is specifically coded to return the item at or immediately after the median to ensure that the returned item is a member of the original set (not an average of two values).

This is technically a special case of the weighted median.