I'm currently working on a GUI for a telescope.
I've got a webCam connected via USB to a raspberry pi.
A small python-script is reading the imageData to String an is sending it via socket to my pc. Now I want to display this imageString in a GTK image.
def updateWebCamPic(self, imageString):
print "update"
img = Image.open(StringIO(imageString))
self.image.set_from_pixbuf(self.image2pixbuf(img))
print "updatet"
def getPixBufRGB8Bit(self, im):
arr = numpy.array(im)
return GdkPixbuf.Pixbuf.new_from_data((arr, Gdk.COLORSPACE_RGB, 8))
def image2pixbuf(im):
"""Convert Pillow image to GdkPixbuf"""
data = im.tobytes()
w, h = im.size
data = GLib.Bytes.new(data)
pix = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
False, 8, w, h, w * 3)
return pix
But I get the following error:
raise IOError("cannot identify image file")
IOError: cannot identify image file
[EDIT]:
if str(received[0]).startswith("<|Image|>"):
image=received[0][9:]
self.parrent.updateWebCamPic(image)