Skip to content

Instantly share code, notes, and snippets.

Last active March 2, 2017 12:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import numpy as np
import json
import zmq
def send_image(socket, image, channel = b"image"):
# Serialize a Numpy array
dtype = str(image.dtype).encode('ascii')
shape = json.dumps(image.shape).encode('ascii')
data = image.tostring('C')
socket.send_multipart([channel, dtype, shape, data])
def recv_image(socket, flags = 0):
channel, dtype, shape, data = socket.recv_multipart(flags)
# Deserialize a numpy array
image = np.frombuffer(data, dtype=dtype.decode('ascii'))
image.shape = json.loads(shape.decode('ascii'))
return image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment