LoginSignup
0
1

More than 5 years have passed since last update.

【ev3dev】pythonでLCDにbmp画像を表示する方法

Last updated at Posted at 2017-02-25

はじめに

この記事は、EV3にev3devをインストールし、SSH接続できている状態であることを前提にしています。環境構築ができていない方はこちらの記事を参考にしてください。

mindstorm-EV3をLinuxで制御しよう! ev3dev OSのインストールとSSH接続

概要

python製ev3devライブラリのev3dev-lang-pythonを使ってLCD画面にbmp画像を表示する方法を紹介します。公式ドキュメントに書いてある方法ではうまく行かなかったので、この記事が参考になれば幸いです。

bmp画像のダウンロード

LCD表示に適したサイズのbmp画像がライブラリのホームページに提供されていました。
zipファイルをダウンロードして展開し、EV3に保存しましょう。
BMP image collection
image_catalog.png

失敗する方法

LCDにbmp画像を表示させてみましょう。

公式ドキュメントにはimageメソッドが説明されています。

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))

しかし実行してみるとimageメソッドが定義されていないようでエラーが発生してしまいます。

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'

成功する方法

次のプログラムで上手く動きました。

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")) #色が反転してしまう
screen.draw.bitmap((0, 0), ImageOps.invert(logo.convert("L"))) # 成功

screen.update()

logo.convert("L") で画像を8-bitピクセルのモノクロに変換しています。
しかしこの状態ではLCD表示した時に白黒が反転してしまう減少が起きるのでImageOps.invert() を使って元に戻しています。

このように表示されました。
awake.png

参考

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

【ev3dev】pythonを使ってLCD(画面)をキャプチャーするプログラムを作る

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1