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
410
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
450
JBUG広島&JBUG岡山 #共同開催 2020_06_21 LT資料
ogu
1
500
PyconJP2018 09_18 小栗潤一 Pythonで「お絵描きパズル」を解いてみた
ogu
0
3.1k
Pycon JP 2018 python_お絵描きパズルのロジックまとめ.pdf
ogu
1
1k
Featured
See All Featured
Crafting Experiences
bethany
1
330
Test your architecture with Archunit
thirion
2
2.4k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Scaling GitHub
holman
464
140k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Fireside Chat
paigeccino
43
4k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
370
Optimising Largest Contentful Paint
csswizardry
37
4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
Evolving SEO for Evolving Search Engines
ryanjones
0
290
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は楽しい