Instantly share code, notes, and snippets.

Embed
What would you like to do?
#! /usr/bin/python
import zmq
import numpy as np
from PIL import Image
import os
port = "8080"
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://IP:%s" % port)
ssPath = "./ss.png" # this is the screenshot that unity saves everytime
timeStamp = os.stat(ssPath)
print(timeStamp)
while True:
if (os.stat(ssPath) != timeStamp): # we check to send only if unity saves a new screenshot
print("SENDING PIC")
try:
img = Image.open("./ss.png").convert('RGB')
except:
print("continue!")
continue
socket.send(np.array(img))
result = socket.recv()
result = Image.frombytes('RGB',(480,320),result)
result.save('di.png')
timeStamp = os.stat(ssPath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment