Last active
March 2, 2017 12:25
-
-
Save h2suzuki/e38a3cc3186f36a7fd0858b23bcbb44b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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