I wrote a quick python script to return the average colour of rectangles surrounding the perimeter of my screen. (The end goal here is to have RGB LED strips surrounding my moni
Use the Python Imaging Library. From the docs (in the Image module):
getcolors
im.getcolors() => a list of (count, color) tuples or None
im.getcolors(maxcolors) => a list of (count, color) tuples or None
(New in 1.1.5) Returns an unsorted list of (count, color) tuples, where the count is the number of times the corresponding color occurs in the image.
The Image module also contains a crop() method you can use to get each rectangle to plug into getcolors(). You can take a weighted average from that easily.
It should be much faster than running the loop manually in python. I'm not sure if it's fast enough to use in real time, but you will get a dramatic speed boost. You could also take the screenshot a few times per second, since odds are that sending signals to the LEDs at 60 fps vs 10 fps won't be particularly noticeable. Don't look at it as "limited to 12.8 FPS", look at it as "can only update the LEDs once every 5 frames", which shouldn't be a noticeable difference.
EDIT: If you're really interested in further optimization here, I think you'll find Fastest way to take a screenshot with python on windows quite helpful.