File: camera_pymorse.py

package info (click to toggle)
morse-simulator 1.4-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 187,116 kB
  • sloc: ansic: 108,311; python: 25,694; cpp: 786; makefile: 126; xml: 34; sh: 7
file content (21 lines) | stat: -rw-r--r-- 543 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import base64
from pymorse import Morse

with Morse() as sim:
    data = sim.r.v.get()

width = data['width']
height = data['height']
# data['image'] is RGBA base64 encoded
buff = base64.b64decode( data['image'] )

# using scipy and numpy
import numpy
import scipy.misc
image = numpy.ndarray(shape=(height, width, 4), buffer=buff, dtype='uint8')
scipy.misc.imsave('scipy.png', image)

# using Python Imaging Library (PIL)
from PIL import Image
image = Image.frombuffer('RGBA', (width, height), buff, 'raw', 'RGBA', 0, 1)
image.save('pil.png')