[Ev3dev] How to display bmp image on LCD with python

Introduction

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

Overview

I will introduce how to display a bmp image on the LCD screen using ev3dev-lang-python of the python ev3dev library. The method described in the official documentation didn't work, so I hope you find this article helpful.

Download bmp image

A bmp image of a size suitable for LCD display was provided on the library homepage. Download the zip file, unzip it, and save it to EV3. BMP image collection image_catalog.png

How to fail

Let's display a bmp image on the LCD.

The official documentation (https://media.readthedocs.org/pdf/python-ev3dev/latest/python-ev3dev.pdf) describes the image method.

image Returns a handle to PIL.Image class that is backing the screen. This can be accessed for blitting images to the screen. Example:

screen.image.paste(picture, (0, 0))

However, when I try to execute it, it seems that the image method is not defined and an error occurs.

robot@ev3dev:~$ python
Python 2.7.9 (default, Aug 13 2016, 17:33:18)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
  
>>>from PIL import Image, ImageDraw, ImageFont, ImageOps
>>>import ev3dev.auto as ev3
>>> screen = ev3.Screen()
>>>logo = Image.open('test.bmp')
>>> screen.image.paste(logo,(0,0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Screen' object has no attribute 'image'

How to succeed

It worked fine with the following program.

bmp_lcd.py



mport ev3dev.auto as ev3
from PIL import Image, ImageDraw, ImageFont, ImageOps

screen = ev3.Screen()
logo = Image.open('EV3_BMPs/Awake.bmp')
#screen.draw.bitmap((0, 0), logo.convert("L")) #The color is reversed
screen.draw.bitmap((0, 0), ImageOps.invert(logo.convert("L"))) #success

screen.update()

logo.convert("L")Image with 8-Converting to monochrome of bit pixels.


 However, in this state, there is a decrease in black and white being inverted when the LCD is displayed, so ```ImageOps.invert ()` `` is used to restore it.

 It was displayed like this.
 ![awake.png](https://qiita-image-store.s3.amazonaws.com/0/149019/51f9fc2c-2323-86d1-bbad-7c3a95d45896.png)

## reference
>
[https://sites.google.com/site/ev3python/learn_ev3_python/screen/bmp-image-collection](https://sites.google.com/site/ev3python/learn_ev3_python/screen/bmp-image-collection)
>
[http://pillow.readthedocs.io/en/3.3.x/handbook/concepts.html#modes](http://pillow.readthedocs.io/en/3.3.x/handbook/concepts.html#modes)

>
 [[Ev3dev] Create a program to capture LCD (screen) using python](http://qiita.com/murotani/items/8f301c57d3e5741ea8f7)


Recommended Posts

[Ev3dev] How to display bmp image on LCD with python
How to display python Japanese with lolipop
Strategy on how to monetize with Python Java
How to crop an image with Python + OpenCV
How to scrape image data from flickr with python
Python: How to use async with
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to get started with Python
How to use FTP with Python
How to calculate date with python
Linking Python and Arduino to display IME On / Off with LED
How to use python put in pyenv on macOS with PyCall
How to display legend marks in one with Python 2D plot
HTML email with image to send with python
How to read pydoc on python interpreter
[Python] How to display random numbers (random module)
[Kivy] How to install Kivy on Windows [Python]
Introduction to Python Image Inflating Image inflating with ImageDataGenerator
How to work with BigQuery in Python
How to erase Python 2.x on Mac.
How to display multiplication table in python
How to display emoji on Manjaro Linux
How to do portmanteau test with python
Memorandum on how to use gremlin python
How to adjust image contrast in Python
How to enter Japanese with Python curses
[Python] How to deal with module errors
How to display Hello world in python
How to install python3 with docker centos
Sample to convert image to Wavelet with Python
How to crop the lower right part of the image with Python OpenCV
How to draw a vertical line on a heatmap drawn with Python seaborn
How to upload with Heroku, Flask, Python, Git (4)
[python] How to display list elements side by side
How to read a CSV file with Python 2/3
How to enjoy programming with Minecraft (Ruby, Python)
[REAPER] How to play with Reascript in Python
How to do multi-core parallel processing with python
Convert PDF to image (JPEG / PNG) with Python
How to install OpenCV on Jetson Nano Python
[Python] How to change the date format (display format)
How to use Python Image Library in python3 series
How to use Python Kivy ④ ~ Execution on Android ~
[Python] How to draw multiple graphs with Matplotlib
[Python] How to read excel file with pandas
How to run MeCab on Ubuntu 18.04 LTS Python
How to specify attributes with Mock of python
How to install OpenGM on OSX with macports
How to measure execution time with Python Part 1
Introduction to Python with Atom (on the way)
How to use tkinter with python in pyenv
How to display images continuously with matplotlib Note
[Python] How to install OpenCV on Anaconda [Windows]
[Python] How to handle Japanese characters with openCV
Post an article with an image to WordPress with Python
[Python] How to compare datetime with timezone added
Connect to MySQL with Python on Raspberry Pi
How to measure execution time with Python Part 2
[Python] How to save images on the Web at once with Beautiful Soup
How to display in the entire window when setting the background image with tkinter
How to install Python