Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. import struct
  2.  
  3. class DataInputStream:
  4.     def __init__(self, stream):
  5.         self.stream = stream
  6.  
  7.     def read_boolean(self):
  8.         return struct.unpack('?', self.stream.read(1))[0]
  9.  
  10.     def read_byte(self):
  11.         return struct.unpack('b', self.stream.read(1))[0]
  12.  
  13.     def read_unsigned_byte(self):
  14.         return struct.unpack('B', self.stream.read(1))[0]
  15.  
  16.     def read_char(self):
  17.         return chr(struct.unpack('>H', self.stream.read(2))[0])
  18.  
  19.     def read_double(self):
  20.         return struct.unpack('>d', self.stream.read(8))[0]
  21.  
  22.     def read_float(self):
  23.         return struct.unpack('>f', self.stream.read(4))[0]
  24.  
  25.     def read_short(self):
  26.         return struct.unpack('>h', self.stream.read(2))[0]
  27.  
  28.     def read_unsigned_short(self):
  29.         return struct.unpack('>H', self.stream.read(2))[0]
  30.  
  31.     def read_long(self):
  32.         return struct.unpack('>q', self.stream.read(8))[0]
  33.  
  34.     def read_utf(self):
  35.         utf_length = struct.unpack('>H', self.stream.read(2))[0]
  36.         return self.stream.read(utf_length)
  37.  
  38.     def read_int(self):
  39.         return struct.unpack('>i', self.stream.read(4))[0]
  40.  
  41.  
  42. #data = data_preparation_TIPA_protocol('../../../Downloads/data1.dat',320,240)
  43. # width x height
  44. #print(np.shape((data.thermal_matrix)))
  45. matrix = None
  46. #import csv
  47.  
  48. with open('../../../Downloads/data.csv', 'rb') as bfile:
  49.     dis = DataInputStream(bfile)
  50.     row_count = dis.read_int()
  51.     matrix = np.empty([640, 480, row_count])
  52.     f = 0
  53.     for f in range(0,row_count):
  54.         print("Processed Frame: "+str(f))
  55.         for i in range(0,640):
  56.             for j in range(0,480):
  57.                 val = dis.read_double()
  58.                 #print(val)
  59.                 matrix[i][j][f] = val
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement