In [ ]:
import cv2, cv
import serial
import numpy as np
import matplotlib
from matplotlib import pyplot as plt
%matplotlib inline

In [12]:
ser=serial.Serial(port='/dev/ttyACM0',
                  baudrate=115200)

In [3]:
def get_frame(ser):
    try:
        retu=np.array(ser.readline()[:-4].split(',')).astype(np.int8)/128.0
        if retu.size is not 128:
            return np.zeros((128))
        return retu
    except:
        return np.zeros((128))

In [11]:
data=get_frame(ser)

In [13]:
data=np.ndarray((100, 128))

In [14]:
data.shape


Out[14]:
(100, 128)

In [15]:
plt.imshow(data)


Out[15]:
<matplotlib.image.AxesImage at 0x48bba90>

In [16]:
for i in range(data.shape[0]):
    data[i] = get_frame(ser)

In [17]:
plt.imshow(data)


Out[17]:
<matplotlib.image.AxesImage at 0x49e3810>

In [34]:
i=0

In [40]:
lst=[]
for i in range(100):
    f=get_frame(ser)
    lst.append(f)

In [41]:
data2=np.concatenate(lst).reshape((100, 128))

In [42]:
plt.imshow(data2)


Out[42]:
<matplotlib.image.AxesImage at 0x582e090>

In [66]:
falsecolor=cv2.applyColorMap(data3, cv2.COLORMAP_JET)

In [59]:
while True:
    f=get_frame(ser)
    f=1.0-f
    lst.pop(0)
    lst.append(f)
    data2=np.concatenate(lst).reshape((100, 128))
    data3=cv2.resize(data2, (640, 500))
    data4=cv2.applyColorMap(data3, cv2.COLORMAP_JET)
    cv2.imshow('image', data4)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

In [38]:
while True:
    f=get_frame(ser)
    data[i%100]=f
    i+=1
    cv2.imshow('image', data)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

In [69]:
f


Out[69]:
array([ 0.7421875,  0.71875  ,  0.7109375,  0.7109375,  0.703125 ,
        0.703125 ,  0.6953125,  0.6953125,  0.6953125,  0.6875   ,
        0.6875   ,  0.6796875,  0.671875 ,  0.6796875,  0.6796875,
        0.671875 ,  0.671875 ,  0.671875 ,  0.6796875,  0.6875   ,
        0.6953125,  0.6953125,  0.6953125,  0.6953125,  0.6953125,
        0.6953125,  0.6953125,  0.6953125,  0.6875   ,  0.6875   ,
        0.6796875,  0.6875   ,  0.6796875,  0.6796875,  0.6796875,
        0.6796875,  0.6796875,  0.6640625,  0.6640625,  0.6640625,
        0.65625  ,  0.65625  ,  0.65625  ,  0.6484375,  0.6484375,
        0.6484375,  0.6484375,  0.6484375,  0.6484375,  0.640625 ,
        0.640625 ,  0.6484375,  0.6484375,  0.640625 ,  0.6328125,
        0.6328125,  0.6328125,  0.6328125,  0.6328125,  0.6328125,
        0.6328125,  0.625    ,  0.625    ,  0.6328125,  0.625    ,
        0.6328125,  0.6328125,  0.625    ,  0.6328125,  0.6328125,
        0.6328125,  0.640625 ,  0.6328125,  0.6328125,  0.640625 ,
        0.6328125,  0.6328125,  0.625    ,  0.625    ,  0.6171875,
        0.6171875,  0.6171875,  0.609375 ,  0.59375  ,  0.578125 ,
        0.53125  ,  0.3046875,  0.140625 ,  0.0703125,  0.0390625,
        1.90625  ,  1.8828125,  1.8515625,  1.8125   ,  1.796875 ,
        1.7578125,  1.671875 ,  1.59375  ,  1.5546875,  1.5625   ,
        1.5390625,  1.5078125,  1.5078125,  1.453125 ,  1.4453125,
        1.40625  ,  1.4296875,  1.4453125,  1.4140625,  1.4296875,
        1.4375   ,  1.4921875,  1.5390625,  1.609375 ,  1.65625  ,
        1.734375 ,  1.7890625,  1.859375 ,  1.921875 ,  2.       ,
        0.1484375,  0.2421875,  0.296875 ,  0.3515625,  0.40625  ,
        0.4609375,  0.515625 ,  0.546875 ])

In [74]:
f.shape


Out[74]:
(128,)

In [ ]:


In [84]:
cv2.resize(f.T, (800, 800))


Out[84]:
array([[ 0.5859375,  0.5859375,  0.5859375, ...,  0.5859375,  0.5859375,
         0.5859375],
       [ 0.5859375,  0.5859375,  0.5859375, ...,  0.5859375,  0.5859375,
         0.5859375],
       [ 0.5859375,  0.5859375,  0.5859375, ...,  0.5859375,  0.5859375,
         0.5859375],
       ..., 
       [ 0.203125 ,  0.203125 ,  0.203125 , ...,  0.203125 ,  0.203125 ,
         0.203125 ],
       [ 0.203125 ,  0.203125 ,  0.203125 , ...,  0.203125 ,  0.203125 ,
         0.203125 ],
       [ 0.203125 ,  0.203125 ,  0.203125 , ...,  0.203125 ,  0.203125 ,
         0.203125 ]])

In [72]:
cv2.resize?

In [85]:
while True:
    f=1.0-get_frame(ser)
    resized = cv2.resize(f, (800, 800))
    cv2.imshow('image', resized.T)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

In [ ]: