Last active
September 28, 2016 04:10
-
-
Save WasabiFan/92a04c7eecbc7142ae9ec16cddf95f52 to your computer and use it in GitHub Desktop.
A script to capture a screenshot from the framebuffer (using fbgrab) and recolor white pixels to look like the display on the LEGO MINDSTORMS EV3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Import system utilities | |
import sys | |
from subprocess import call | |
# Import imaging library to resize and recolor the screenshot | |
from PIL import Image | |
# Choose the name for the screenshot to save. It defaults to "screenshot.png", | |
# but you can supply a custom name as a command-line argument. | |
out_name = sys.argv[1] if len(sys.argv) > 1 else "screenshot.png" | |
# Call the fbgrab utility to have it save a screenshot | |
call(["fbgrab", out_name]); | |
# Load the screenshot that fbgrab saved so that we can modify it | |
image = Image.open(out_name) | |
# Convert the black-and-white screenshot (where each pixel is just "black" or "white") | |
# to an image with red, green and blue channels. This lets us make it more colorful later. | |
image = image.convert("RGB") | |
# Resize the image to be twice the dimensions, making sure to preserve crisp edges | |
image = image.resize(tuple(i * 2 for i in image.size), Image.NEAREST) | |
# Get access to the underlying pixel data so that we can modify it | |
pixel_data = image.load() | |
# Loop through each pixel | |
for y in range(image.size[1]): | |
for x in range(image.size[0]): | |
# If the pixel is white, make it #adb578 (the color we | |
# use as an approximation of the LCD screen) instead | |
if pixel_data[x, y] == (255, 255, 255): | |
pixel_data[x, y] = (173, 181, 120) | |
# Save the image again | |
image.save(out_name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment