Skip to content

Instantly share code, notes, and snippets.

@CharStiles
Created March 27, 2018 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CharStiles/255207f58798fcdda935817191f4d07c to your computer and use it in GitHub Desktop.
Save CharStiles/255207f58798fcdda935817191f4d07c to your computer and use it in GitHub Desktop.
#! /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