forked from erik-smit/sony-camera-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliveView-plt.py
47 lines (33 loc) · 1.08 KB
/
liveView-plt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
import httplib
import struct
import binascii
import pprint
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.animation as animation
import numpy as np
from PIL import Image
from pylab import *
import io
conn = httplib.HTTPConnection("172.24.254.148:60152")
conn.request("GET", "/liveview.JPG?%211234%21http%2dget%3a%2a%3aimage%2fjpeg%3a%2a%21%21%21%21%21")
res = conn.getresponse()
fig = plt.figure()
im = plt.imshow(np.random.random((10,10)))
def moarLive(*args):
commonHeaderLength = 1 + 1 + 2 + 4
commonHeader = res.read(commonHeaderLength)
payloadHeaderLength = 4 + 3 + 1 + 4 + 1 + 115
payloadHeader = res.read(payloadHeaderLength)
jpegSize = struct.unpack('>i','\x00'+payloadHeader[4:7])[0]
paddingSize = ord(payloadHeader[7:8])
jpegData = res.read(jpegSize)
paddingData = res.read(paddingSize)
image_as_file = io.BytesIO(jpegData)
image_as_pil = Image.open(image_as_file)
im.set_data(image_as_pil)
return im,
ani = animation.FuncAnimation(fig, moarLive, interval=50, blit=True)
plt.show()