Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
すごい広島 With Python 発表資料_2020_0129
Search
J-Ogu
January 29, 2020
430
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
すごい広島 With Python 発表資料_2020_0129
J-Ogu
January 29, 2020
More Decks by J-Ogu
See All by J-Ogu
ビジネスPythonを学ぶ会_2020_11_09_Ogu
ogu
0
460
JBUG広島&JBUG岡山 #共同開催 2020_06_21 LT資料
ogu
1
510
PyconJP2018 09_18 小栗潤一 Pythonで「お絵描きパズル」を解いてみた
ogu
0
3.1k
Pycon JP 2018 python_お絵描きパズルのロジックまとめ.pdf
ogu
1
1k
Featured
See All Featured
Building an army of robots
kneath
307
47k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.6k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
The browser strikes back
jonoalderson
0
1.9k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
560
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
121
120k
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
Docker and Python
trallard
47
4.3k
A designer walks into a library…
pauljervisheath
211
25k
For a Future-Friendly Web
brad_frost
184
11k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Transcript
Pythonを使った リアルタイム描画について すごい広島 with Python 第34回 2020_01_29 小栗 潤一
Pythonのリアルタイム描画の方法 ・jupyter notebookでIPython.displayを使う ・matplotlibのplt.pause(.01)で描画する ・OpenCVのcv2.imshowで描画する
Pythonのリアルタイム描画の方法 ・jupyter notebookでIPython.displayを使う ・matplotlibのplt.pause(.01)で描画する ・OpenCVのcv2.imshowで描画する 今日なぜこの話を? ・Pythonでお絵かきパズルを解いてみたのリファクタリング開始 ・ コード量が多すぎてjupyterではリファクタリングしにくい ・Git管理もしたい。
・ コンソール上でpython3 oekaki.py で実行したい。 ・ リアルタイム描画の機能は維持したい。 (開発しやすい) ・ 調べたらいろいろな方法があったのでまとめて発表しよう。
方法① jupyter notebook
jupyter notebookでIPython.displayを使う from PIL import Image, ImageDraw, ImageFont from IPython.display
import display, clear_output def byouga_syori(w_list, h_list, byouga ): img = Image.new('RGB', (10, 10), (128,128,128) ) ### <描画用のデータを作成する処理> ### clear_output(wait=True) display(img) ・jupyter上でmatplotlibの描画には %matplotlib inline が必要 ・IPython.displayを使うと %matplotlib inline がいらない Demo できる
方法② matplotlib
matplotlibのplt.pause(.01)で描画する import matplotlib.pyplot as plt def pause_plot(): fig, ax =
plt.subplots(1, 1) x = np.arange(-np.pi, np.pi, 0.1) y = np.sin(x) lines, = ax.plot(x, y) while True: x += 0.1 y = np.sin(x) lines.set_data(x, y) ax.set_xlim((x.min(), x.max())) plt.pause(.01) ・jupyter上では %matplotlib inline が必要 https://qiita.com/hausen6/items/b1b54f7325745ae43e47 コード流用元 Demo できる
方法③ OpenCV
OpenCVのcv2.imshowで描画する from PIL import Image, ImageDraw, ImageFont import cv2 import
numpy as np def byouga_syori(w_list, h_list, byouga ): img = Image.new('RGB', (10, 10), (128,128,128) ) ### <描画用のデータを作成する処理> ### OpenCV_data=np.asarray(img) cv2.imshow("Loaded image",OpenCV_data) cv2.waitKey(1) cv2.moveWindow('Loaded image', 30, 10) cv2.waitKey(1) ➡︎ cv2.waitKey(0) ↑この引数はミリ秒:100くらいにするとお絵かきロジックにはちょうどいい ・描画位置を変更したい場合は ・リアルタイム描画を止めたい (何かキーを押すまで停止) Demo できる
いろいろな方法が あるので試して みてください。 やっぱりPythonは楽しい