Python pyglet
eiichiromomma edited this page Aug 17, 2014
·
1 revision
(Python) pyglet
画像、動画の表示、音声の再生、OpenGLの描画を行なうライブラリ
programming_guideを読んでいたら、pixelへのダイレクトなアクセスが可能との表記があったので試してみたメモ。
''.join([list])
って方法があるらしい。
#!/usr/bin/env python
# ----------------------------------------------------------------------------
# pyglet
# Copyright (c) 2006-2008 Alex Holkner
# All rights reserved.
# ----------------------------------------------------------------------------
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: image_viewer.py 1966 2008-03-23 07:01:26Z Alex.Holkner $'
import pyglet
window = pyglet.window.Window()
kitten = pyglet.image.load('kitten.jpg)').get_image_data()
data = kitten.get_data('RGB', kitten.width * 3)
tmplist = list(data)
for y in range(50, 100):
for x in range (150, 200):
for c in range (3):
#全色塗り潰し
tmplist[x*3+c + y*3*kitten.width] = chr(255)
#strに戻す
#data = ''.join(tmplist)
#データ書き込み
kitten.set_data('RGB', kitten.width * 3 , ''.join(tmplist))
@window.event
def on_draw():
window.clear()
kitten.blit(0, 0)
pyglet.app.run()
- get_dataで生データ取得(str)
- arrayでbyte配列に置換
- Cで1次元配列を2次元として扱うやり方( xチャネル数+色 + 幅y*チャネル数 )で座標指定
- chrで濃度から文字へ変換して代入
- tostring()でstrに戻す
- set_dataで上書き
get_data, set_dataはsequence of bytes, or strを返す/渡すとあるのだが、綺麗なやり方が今のところ不明。
ドキュメントのimage_viewer.pyが元ネタ
#!/usr/bin/env python
# ----------------------------------------------------------------------------
# pyglet
# Copyright (c) 2006-2008 Alex Holkner
# All rights reserved.
# ----------------------------------------------------------------------------
'''
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id: image_viewer.py 1966 2008-03-23 07:01:26Z Alex.Holkner $'
import pyglet
import array
window = pyglet.window.Window()
#image = pyglet.resource.image('kitten.jpg)')
#resouce.image の代わりにimage.loadでget_image_data
kitten = pyglet.image.load('kitten.jpg)').get_image_data()
data = kitten.get_data('RGB', kitten.width * 3)
#Byteのarrayに変換
bdata = array.array('c',data)
for y in range(50, 100):
for x in range (150, 200):
for c in range (3):
#全色塗り潰し
bdata[x*3+c + y*3*kitten.width] = chr(255)
#strに戻す
sdata = bdata.tostring()
#データ書き込み
kitten.set_data('RGB', kitten.width * 3 , sdata)
@window.event
def on_draw():
window.clear()
# image.blit(0, 0)
kitten.blit(0, 0)
pyglet.app.run()
- 3ds_max
- Android
- Books
- Caffe
- Chainer
- CloudCompare
- colinux
- colmap
- Cygwin
- DeepLearning
- DICOM
- dlib
- docker
- Everun
- Excel
- EyeX
- FANN
- FDS
- Felica
- FreeBSD
- FreeNAS
- GAlib
- gnuplot
- JetsonNano
- JetsonTK1
- JetsonTX2
- Kinect
- LAPACK
- LaTeX
- LTspice
- MacOSX
- MATLAB
- Memo
- MicroEnableIII
- Mono
- MSVC
- nano
- nvidia-docker
- ODE
- Open3D
- OpenCV
- OpenCVSharp
- OpenMVG
- OpenOffice
- OpenVSLAM
- OSG
- ParaView
- PCL
- Phidgets
- PlaidML
- PLplot
- POVRay
- PowerPoint
- Python
- R
- RaspberryPi
- Realsense
- ROS
- RSJ2011
- Ruby
- Scilab
- SHOGUN
- SUSE
- SVM
- Tensorflow
- TrueCrypt
- Ubuntu
- uEye
- Unix
- VMWarePlayer
- Vim
- VTK
- Windows
- WSL2
- 文書作成
- 文献調査
- 立体映像
- 論文メモ