SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PASTEBINGO  API TOOLS FAQ DEALS
  2. Search...
  3. pasteSIGN IN SIGN UP
  4. Public Pastes
  5. Untitled
  6. 0 sec ago
  7. Untitled
  8. 1 sec ago
  9. Untitled
  10. 4 sec ago
  11. Untitled
  12. 8 sec ago
  13. Untitled
  14. 12 sec ago
  15. Untitled
  16. 18 sec ago
  17. Untitled
  18. 21 sec ago
  19. Untitled
  20. 28 sec ago
  21.  
  22. SHARE
  23. TWEET
  24.  
  25. Untitled
  26.  A GUEST  JAN 23RD, 2020  0  NEVER
  27. NOTE: Your guest paste has been posted. If you sign up for a free account, you can edit and delete your pastes!
  28. rawdownloadcloneembedreportprinttext 4.35 KB
  29. from struct import unpack_from
  30. import toml
  31. import json
  32. import numpy as np
  33. from websocket import create_connection
  34. import time
  35. from time import sleep, gmtime, strftime, localtime
  36. import datetime
  37. #from datetime import time, datetime,timezone, timedelta
  38. import sys
  39. import asyncio
  40. loop = asyncio.get_event_loop()
  41.  
  42. DTYPES = {0: np.int8,     1: np.uint8,     2: np.int16,     3: np.uint16,     4: np.int32,     5: np.uint32,     6: np.float32,     7: np.float64, }
  43.  
  44. ASCII_RS = '\u001e'
  45. ASCII_US = '\u001f'
  46.  
  47. config = toml.load("config_vayyar.toml")
  48.  
  49. def to_message(buffer):    
  50.     # parse MatNet messages from JSON / own binary format    
  51.     if isinstance(buffer, str):        
  52.         return json.loads(buffer)    
  53.     seek = 0    
  54.     # bufferSize = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek))    
  55.     fields_len = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek + 4))    
  56.     header_buff = buffer[seek + 8: seek + 8 + fields_len].decode('utf8')    
  57.     id, keys = header_buff.split(ASCII_RS)    
  58.     msg = {'ID': id, 'Payload': {}}    
  59.     seek += 8 + fields_len    
  60.     for key in keys.split(ASCII_US):        
  61.         # fieldSize = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek))        
  62.         dtype = DTYPES[np.asscalar(np.frombuffer(buffer, np.int32, 1, seek + 4))]        
  63.         ndims = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek + 8))        
  64.         dims = np.frombuffer(buffer, np.int32, ndims, seek + 12)        
  65.         seek += 12 + ndims * np.int32().nbytes        
  66.         data = np.frombuffer(buffer, dtype, np.prod(dims), seek)        
  67.         seek += np.prod(dims) * dtype().nbytes
  68.         msg['Payload'][key] = data.reshape(dims) if ndims else np.asscalar(data)    
  69.     return msg
  70.  
  71. listener = create_connection("ws://"+config["connection"]["ip"])  
  72. # retrieve current configuration    
  73. listener.send(json.dumps({  'Type': 'COMMAND',         'ID': 'SET_PARAMS',         'Payload': { 'Cfg.MonitoredRoomDims': config["vayyar"]["rd"], 'Cfg.Common.sensorOrientation.mountPlane': config["vayyar"]["mp"],  'Cfg.Common.sensorOrientation.transVec': config["vayyar"]["tv"], 'Cfg.imgProcessing.substractionMode': config["vayyar"]["ips"], 'Cfg.TargetProperties.MaxPersonsInArena': config["vayyar"]["maxpia"],   'Cfg.TargetProperties.StandingMaxHeight': config["vayyar"]["stamaxh"],  'Cfg.TargetProperties.StandingMinHeight': config["vayyar"]["staminh"],             'Cfg.TargetProperties.SittingMinHeight': config["vayyar"]["lyiminh"],             'Cfg.TargetProperties.LyingMinHeight': config["vayyar"]["pr"],             'Cfg.TargetProperties.PersonRadius': config["vayyar"]["pr"],             'MPR.save_dir': config["vayyar"]["mprsd"],             'MPR.read_from_file': config["vayyar"]["mprrff"],             'MPR.save_to_file': config["vayyar"]["mprstf"],             'MPR.save_image_to_file': config["vayyar"]["mpsitf"],             'Cfg.OutputData.save_to_file': config["vayyar"]["odstf"],             'Cfg.ExternalGUI.FilterImage.TH': config["vayyar"]["egfi"],             'Cfg.ExternalGUI.FilterImage.numOfSd': config["vayyar"]["egfin"],             'Cfg.PeopleCounter.inCarIsLocked': config["vayyar"]["pcic"],             'Cfg.Zones.Beds': config["vayyar"]["zb"]         }     }))
  74.  
  75. # set outputs for each frame    
  76. listener.send(json.dumps({         'Type': 'COMMAND',         'ID': 'SET_OUTPUTS',         'Payload': {             'binary_outputs': ['LocationMatrix','NumOfPeople','BreathingMatrix'],             'json_outputs':['PostureVector']         }     }))    
  77. # start the engine - if WebGUI is not running    
  78. listener.send(json.dumps({         'Type': 'COMMAND',         'ID': 'START',         'Payload': {}     }))
  79. listener.send(json.dumps({'Type': 'QUERY', 'ID': 'JSON_DATA'}))
  80.  
  81. print("Running! Waiting for messages...")    
  82. async def send_data():
  83.     while True:
  84.         await asyncio.sleep(config["asynctimer"]["aast"])
  85.         buffer = listener.recv()        
  86.         data = to_message(buffer)        
  87.         #print(data['ID'])
  88.         #print(data)        
  89.         if data['ID'] == 'JSON_DATA':
  90.             #datetime_object = datetime.datetime.now()
  91.             #print(datetime_object)
  92.             print(strftime("%H:%M:%S", localtime()))
  93.             print("PostureVector: ", data['Payload']['PostureVector'])
  94.             listener.send(json.dumps({'Type': 'QUERY', 'ID': 'JSON_DATA'}))      
  95. #time.sleep(2)
  96.  
  97. if __name__ == '__main__':
  98.     loop.run_until_complete(send_data())
  99. RAW Paste Data
  100. from struct import unpack_from
  101. import toml
  102. import json
  103. import numpy as np
  104. from websocket import create_connection
  105. import time
  106. from time import sleep, gmtime, strftime, localtime
  107. import datetime
  108. #from datetime import time, datetime,timezone, timedelta
  109. import sys
  110. import asyncio
  111. loop = asyncio.get_event_loop()
  112.  
  113. DTYPES = {0: np.int8,     1: np.uint8,     2: np.int16,     3: np.uint16,     4: np.int32,     5: np.uint32,     6: np.float32,     7: np.float64, }
  114.  
  115. ASCII_RS = '\u001e'
  116. ASCII_US = '\u001f'
  117.  
  118. config = toml.load("config_vayyar.toml")
  119.  
  120. def to_message(buffer):    
  121.     # parse MatNet messages from JSON / own binary format    
  122.     if isinstance(buffer, str):        
  123.         return json.loads(buffer)    
  124.     seek = 0    
  125.     # bufferSize = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek))    
  126.     fields_len = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek + 4))    
  127.     header_buff = buffer[seek + 8: seek + 8 + fields_len].decode('utf8')    
  128.     id, keys = header_buff.split(ASCII_RS)    
  129.     msg = {'ID': id, 'Payload': {}}    
  130.     seek += 8 + fields_len    
  131.     for key in keys.split(ASCII_US):        
  132.         # fieldSize = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek))        
  133.         dtype = DTYPES[np.asscalar(np.frombuffer(buffer, np.int32, 1, seek + 4))]        
  134.         ndims = np.asscalar(np.frombuffer(buffer, np.int32, 1, seek + 8))        
  135.         dims = np.frombuffer(buffer, np.int32, ndims, seek + 12)        
  136.         seek += 12 + ndims * np.int32().nbytes        
  137.         data = np.frombuffer(buffer, dtype, np.prod(dims), seek)        
  138.         seek += np.prod(dims) * dtype().nbytes
  139.         msg['Payload'][key] = data.reshape(dims) if ndims else np.asscalar(data)    
  140.     return msg
  141.  
  142. listener = create_connection("ws://"+config["connection"]["ip"])  
  143. # retrieve current configuration    
  144. listener.send(json.dumps({  'Type': 'COMMAND',         'ID': 'SET_PARAMS',         'Payload': { 'Cfg.MonitoredRoomDims': config["vayyar"]["rd"], 'Cfg.Common.sensorOrientation.mountPlane': config["vayyar"]["mp"],  'Cfg.Common.sensorOrientation.transVec': config["vayyar"]["tv"], 'Cfg.imgProcessing.substractionMode': config["vayyar"]["ips"], 'Cfg.TargetProperties.MaxPersonsInArena': config["vayyar"]["maxpia"],   'Cfg.TargetProperties.StandingMaxHeight': config["vayyar"]["stamaxh"],  'Cfg.TargetProperties.StandingMinHeight': config["vayyar"]["staminh"],             'Cfg.TargetProperties.SittingMinHeight': config["vayyar"]["lyiminh"],             'Cfg.TargetProperties.LyingMinHeight': config["vayyar"]["pr"],             'Cfg.TargetProperties.PersonRadius': config["vayyar"]["pr"],             'MPR.save_dir': config["vayyar"]["mprsd"],             'MPR.read_from_file': config["vayyar"]["mprrff"],             'MPR.save_to_file': config["vayyar"]["mprstf"],             'MPR.save_image_to_file': config["vayyar"]["mpsitf"],             'Cfg.OutputData.save_to_file': config["vayyar"]["odstf"],             'Cfg.ExternalGUI.FilterImage.TH': config["vayyar"]["egfi"],             'Cfg.ExternalGUI.FilterImage.numOfSd': config["vayyar"]["egfin"],             'Cfg.PeopleCounter.inCarIsLocked': config["vayyar"]["pcic"],             'Cfg.Zones.Beds': config["vayyar"]["zb"]         }     }))
  145.  
  146. # set outputs for each frame    
  147. listener.send(json.dumps({         'Type': 'COMMAND',         'ID': 'SET_OUTPUTS',         'Payload': {             'binary_outputs': ['LocationMatrix','NumOfPeople','BreathingMatrix'],             'json_outputs':['PostureVector']         }     }))    
  148. # start the engine - if WebGUI is not running    
  149. listener.send(json.dumps({         'Type': 'COMMAND',         'ID': 'START',         'Payload': {}     }))
  150. listener.send(json.dumps({'Type': 'QUERY', 'ID': 'JSON_DATA'}))
  151.  
  152. print("Running! Waiting for messages...")    
  153. async def send_data():
  154.     while True:
  155.         await asyncio.sleep(config["asynctimer"]["aast"])
  156.         buffer = listener.recv()        
  157.         data = to_message(buffer)        
  158.         #print(data['ID'])
  159.         #print(data)        
  160.         if data['ID'] == 'JSON_DATA':
  161.             #datetime_object = datetime.datetime.now()
  162.             #print(datetime_object)
  163.             print(strftime("%H:%M:%S", localtime()))
  164.             print("PostureVector: ", data['Payload']['PostureVector'])
  165.             listener.send(json.dumps({'Type': 'QUERY', 'ID': 'JSON_DATA'}))      
  166. #time.sleep(2)
  167.  
  168. if __name__ == '__main__':
  169.     loop.run_until_complete(send_data())
  170.  
  171. We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
  172. Not a member of Pastebin yet?
  173. Sign Up, it unlocks many cool features!
  174.        
  175. create new paste  /  dealsnew!  /  syntax languages  /  archive  /  faq  /  tools  /  night mode  /  api  /  scraping api
  176. privacy statement  /  cookies policy  /  terms of service  /  security disclosure  /  dmca  /  contact
  177.  
  178. By using Pastebin.com you agree to our cookies policy to enhance your experience.
  179. Site design & logo © 2020 Pastebin; user contributions (pastes) licensed under cc by-sa 3.0 -- FavPNG -- Dedicated Server Hosting by Steadfast
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top