Guest User

Untitled

a guest
Nov 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import paho.mqtt.client as mqtt
  2. import time
  3. import cv2
  4. import numpy
  5. import json
  6.  
  7. MQTT_SERVER = "iot.eclipse.org"
  8. MQTT_PATH = "test_channel"
  9.  
  10. mqttc = mqtt.Client()
  11. mqttc.connect(MQTT_SERVER, 1883, 60)
  12.  
  13. cap = cv2.VideoCapture(0)
  14.  
  15. while True:
  16. ret, frame = cap.read()
  17. frame_list = frame.tolist()
  18. frame_json = json.dumps(frame_list)
  19. MQTT_MESSAGE = frame_json
  20. mqttc.publish(MQTT_PATH, MQTT_MESSAGE)
  21. time.sleep(1)
  22.  
  23. import paho.mqtt.client as mqtt
  24. import numpy as np
  25. import json
  26. import PIL
  27.  
  28. MQTT_SERVER = "iot.eclipse.org"
  29. MQTT_PATH = "test_channel"
  30.  
  31. def on_connect(client, userdata, flags, rc):
  32. print("connected with result code " + str(rc))
  33. client.subscribe(MQTT_PATH)
  34.  
  35. def on_message(client, userdata, msg):
  36. data = json.loads(msg.payload)
  37. array = np.array(data)
  38. img = PIL.Image.fromarray(array)
  39. cv2.imshow('image', img)
  40. cv2.waitKey()
  41.  
  42. client = mqtt.Client()
  43. client.on_connect = on_connect
  44. client.on_message = on_message
  45. client.connect(MQTT_SERVER, 1883, 60)
  46.  
  47. client.loop_forever()
Add Comment
Please, Sign In to add comment