The main work of the code is to figure out where to look. I use a simple average of the pixel positions, weighted by temperature:
x = 0, y = 0, magnitude = 0; float minVal = 100, maxVal = 0; int i = 0; for (float yPos = 3.5; yPos > -4; yPos -= 1.0) { for (float xPos = 3.5; xPos > -4; xPos -= 1.0) { float p = pixels[i]; x += xPos * p; y += yPos * p; minVal = min(minVal, p); maxVal = max(maxVal, p); i++; } }
I then scale the output to the desired ranges:
x = - x / AMG88xx_PIXEL_ARRAY_SIZE / 5.0; y = y / AMG88xx_PIXEL_ARRAY_SIZE / 5.0; x = max(-1.0, min(1.0, x)); y = max(-1.0, min(1.0, y)); magnitude = max(0, min(50, maxVal - 20));
The rest is glue code to integrate with the rest of the M4_Eyes framework. There's plenty to improve, but this works surprisingly well.
Further updates
I'm working on building this into a 3D-printed skull, and I'll update this as that progresses. For more detailed progress notes, see my project blog on Factr.
Text editor powered by tinymce.