This article assumes that you have ev3dev installed on your EV3 and have an SSH connection. If you have not built the environment, please refer to this article.
mindstorm-Let's control EV3 with Linux! Install ev3dev OS and SSH connection
Create a program that captures the screen (LCD) of the intelligent block of mindstorm-EV3 and saves it as an image. Use Python's ev3dev API ev3dev-lang-python.
Please refer to here for the environment construction of ev3dev-lang-python.
Let's control EV3 motors and sensors with Python
screenshot.py
#!/usr/bin/env python3
import sys
from subprocess import call
#Library for handling image data
from PIL import Image
#Image name to save, by default"screenshot.png "
out_name = sys.argv[1] if len(sys.argv) > 1 else "screenshot.png "
#Capture the framebuffer and convert it to a PNG image
call(["fbgrab", out_name]);
#Load the screenshot image
image = Image.open(out_name)
#Convert image to RGB format
image = image.convert("RGB")
#Format image
image = image.resize(tuple(i * 2 for i in image.size), Image.NEAREST)
pixel_data = image.load()
#Image color conversion
for y in range(image.size[1]):
for x in range(image.size[0]):
if pixel_data[x, y] == (255, 255, 255):
pixel_data[x, y] = (173, 181, 120)
# Save the image again
image.save(out_name);
call(["fbgrab", out_name])
The screenshot image obtained by is a black and white image, so you need to convert the white pixels to light green to represent the true screen color.
The following part of the program realizes this process.
for y in range(image.size[1]):
for x in range(image.size[0]):
if pixel_data[x, y] == (255, 255, 255):
pixel_data[x, y] = (173, 181, 120)
You can specify the save destination image file in the first argument.
robot@ev3dev:$ python screenshot.py test.png
I got an image like this
Recommended Posts