I would like to feed images from a remote machine into pyglet (though I am open to other platforms where I can present images and record user's mouse clicks and keystrokes). Currently I am trying to do it using flask
on the remote server and pulling it down with requests
import requests
from PIL import Image
import io
import pyglet
import numpy as np
r = requests.get('http://{}:5000/test/cat2.jpeg'.format(myip),)
This does not work:
im = pyglet.image.load(io.StringIO(r.text))
# Error:
File "/usr/local/lib/python3.4/dist-packages/pyglet/image/__init__.py", line 178, in load
file = open(filename, 'rb')
TypeError: invalid file: <_io.StringIO object at 0x7f6eb572bd38>
This also does not work:
im = Image.open(io.BytesIO(r.text.encode()))
# Error:
Traceback (most recent call last):
File "<ipython-input-68-409ca9b8f6f6>", line 1, in <module>
im = Image.open(io.BytesIO(r.text.encode()))
File "/usr/local/lib/python3.4/dist-packages/PIL/Image.py", line 2274, in open
% (filename if filename else fp))
OSError: cannot identify image file <_io.BytesIO object at 0x7f6eb5a8b6a8>
Is there another way to do it without saving files on disk?